Class AdaptingCircularBufferCounter
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.internal.aggregator.AdaptingCircularBufferCounter
-
final class AdaptingCircularBufferCounter extends java.lang.Object
A circle-buffer-backed exponential counter.The first recorded value becomes the 'baseIndex'. Going backwards leads to start/stop index
This expand start/End index as it sees values.
This class is NOT thread-safe. It is expected to be behind a synchronized incrementer.
-
-
Field Summary
Fields Modifier and Type Field Description private AdaptingIntegerArray
backing
private int
baseIndex
private int
endIndex
private static int
NULL_INDEX
private int
startIndex
-
Constructor Summary
Constructors Constructor Description AdaptingCircularBufferCounter(int maxSize)
Constructs a circular buffer that will hold at mostmaxSize
buckets.AdaptingCircularBufferCounter(AdaptingCircularBufferCounter toCopy)
(Deep)-Copies the values from another exponential counter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
clear()
Resets all bucket counts to zero and resets index start/end tracking.(package private) long
get(int index)
Get the number of recordings for the given index.(package private) int
getIndexEnd()
The last index with a recording.(package private) int
getIndexStart()
The first index with a recording.(package private) int
getMaxSize()
Returns the maximum number of buckets allowed in this counter.(package private) boolean
increment(int index, long delta)
Persist new data at index, incrementing by delta amount.(package private) boolean
isEmpty()
Boolean denoting if the backing structure has recordings or not.private int
toBufferIndex(int index)
java.lang.String
toString()
-
-
-
Field Detail
-
NULL_INDEX
private static final int NULL_INDEX
- See Also:
- Constant Field Values
-
endIndex
private int endIndex
-
startIndex
private int startIndex
-
baseIndex
private int baseIndex
-
backing
private final AdaptingIntegerArray backing
-
-
Constructor Detail
-
AdaptingCircularBufferCounter
AdaptingCircularBufferCounter(int maxSize)
Constructs a circular buffer that will hold at mostmaxSize
buckets.
-
AdaptingCircularBufferCounter
AdaptingCircularBufferCounter(AdaptingCircularBufferCounter toCopy)
(Deep)-Copies the values from another exponential counter.
-
-
Method Detail
-
getIndexStart
int getIndexStart()
The first index with a recording. May be negative.Note: the returned value is not meaningful when isEmpty returns true.
- Returns:
- the first index with a recording.
-
getIndexEnd
int getIndexEnd()
The last index with a recording. May be negative.Note: the returned value is not meaningful when isEmpty returns true.
- Returns:
- The last index with a recording.
-
increment
boolean increment(int index, long delta)
Persist new data at index, incrementing by delta amount.- Parameters:
index
- The index of where to perform the incrementation.delta
- How much to increment the index by.- Returns:
- success status.
-
get
long get(int index)
Get the number of recordings for the given index.- Returns:
- the number of recordings for the index, or 0 if the index is out of bounds.
-
isEmpty
boolean isEmpty()
Boolean denoting if the backing structure has recordings or not.- Returns:
- true if no recordings, false if at least one recording.
-
getMaxSize
int getMaxSize()
Returns the maximum number of buckets allowed in this counter.
-
clear
void clear()
Resets all bucket counts to zero and resets index start/end tracking.
-
toBufferIndex
private int toBufferIndex(int index)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-