@@ -81,18 +81,7 @@ public final class AsynchronousMetricStorage<T extends PointData, U extends Exem
8181 private long epochNanos ;
8282
8383 // Delete the first empty handle to reclaim space, and return quickly for all subsequent entries
84- private final BiConsumer <Attributes , AggregatorHandle <T , U >> handlesDeleter =
85- new BiConsumer <Attributes , AggregatorHandle <T , U >>() {
86- private boolean active = true ;
87-
88- @ Override
89- public void accept (Attributes attributes , AggregatorHandle <T , U > handle ) {
90- if (active && !handle .hasRecordedValues ()) {
91- aggregatorHandles .remove (attributes );
92- active = false ;
93- }
94- }
95- };
84+ private HandlesDeleter handlesDeleter ;
9685
9786 private AsynchronousMetricStorage (
9887 RegisteredReader registeredReader ,
@@ -111,6 +100,7 @@ private AsynchronousMetricStorage(
111100 this .attributesProcessor = attributesProcessor ;
112101 this .maxCardinality = maxCardinality - 1 ;
113102 this .reusablePointsPool = new ObjectPool <>(aggregator ::createReusablePoint );
103+ this .handlesDeleter = new HandlesDeleter ();
114104
115105 if (memoryMode == REUSABLE_DATA ) {
116106 this .lastPoints = new PooledHashMap <>();
@@ -177,6 +167,12 @@ private Attributes validateAndProcessAttributes(Attributes attributes) {
177167
178168 if (aggregatorHandles .size () >= maxCardinality ) {
179169 aggregatorHandles .forEach (handlesDeleter );
170+ if (memoryMode == REUSABLE_DATA ) {
171+ handlesDeleter .reset ();
172+ } else {
173+ handlesDeleter = new HandlesDeleter ();
174+ }
175+
180176 if (aggregatorHandles .size () >= maxCardinality ) {
181177 throttlingLogger .log (
182178 Level .WARNING ,
@@ -333,4 +329,20 @@ private Collection<T> collectWithCumulativeAggregationTemporality() {
333329 public boolean isEmpty () {
334330 return aggregator == Aggregator .drop ();
335331 }
332+
333+ private class HandlesDeleter implements BiConsumer <Attributes , AggregatorHandle <T , U >> {
334+ private boolean active = true ;
335+
336+ @ Override
337+ public void accept (Attributes attributes , AggregatorHandle <T , U > handle ) {
338+ if (active && !handle .hasRecordedValues ()) {
339+ aggregatorHandles .remove (attributes );
340+ active = false ;
341+ }
342+ }
343+
344+ private void reset () {
345+ active = true ;
346+ }
347+ }
336348}
0 commit comments