2222import io .opentelemetry .sdk .resources .Resource ;
2323import java .util .Collection ;
2424import java .util .List ;
25- import java .util .Objects ;
26- import java .util .concurrent .atomic .AtomicReference ;
2725import java .util .function .Supplier ;
2826import javax .annotation .Nullable ;
2927import javax .annotation .concurrent .ThreadSafe ;
@@ -114,8 +112,8 @@ public MetricData toMetricData(
114112 }
115113
116114 static final class Handle extends AggregatorHandle <DoublePointData , DoubleExemplarData > {
117- @ Nullable private static final Double DEFAULT_VALUE = null ;
118- private final AtomicReference < Double > current = new AtomicReference <>( DEFAULT_VALUE ) ;
115+ private volatile boolean set = false ;
116+ private volatile double current = 0 ;
119117
120118 // Only used when memoryMode is REUSABLE_DATA
121119 @ Nullable private final MutableDoublePointData reusablePoint ;
@@ -136,20 +134,31 @@ protected DoublePointData doAggregateThenMaybeReset(
136134 Attributes attributes ,
137135 List <DoubleExemplarData > exemplars ,
138136 boolean reset ) {
139- Double value = reset ? this .current .getAndSet (DEFAULT_VALUE ) : this .current .get ();
137+ double currentLocal = current ;
138+ if (!set ) {
139+ throw new NullPointerException ();
140+ }
141+ if (reset ) {
142+ set = false ;
143+ }
144+
145+ DoublePointData output ;
140146 if (reusablePoint != null ) {
141- reusablePoint .set (
142- startEpochNanos , epochNanos , attributes , Objects .requireNonNull (value ), exemplars );
143- return reusablePoint ;
147+ reusablePoint .set (startEpochNanos , epochNanos , attributes , currentLocal , exemplars );
148+ output = reusablePoint ;
144149 } else {
145- return ImmutableDoublePointData .create (
146- startEpochNanos , epochNanos , attributes , Objects .requireNonNull (value ), exemplars );
150+ output =
151+ ImmutableDoublePointData .create (
152+ startEpochNanos , epochNanos , attributes , currentLocal , exemplars );
147153 }
154+
155+ return output ;
148156 }
149157
150158 @ Override
151159 protected void doRecordDouble (double value ) {
152- current .set (value );
160+ current = value ;
161+ set = true ;
153162 }
154163 }
155164}
0 commit comments