T - the type of values aggregated by this counterpublic abstract class Counter<T> extends Object
Counters compare using value equality of their name, kind, and cumulative value. Equal counters should have equal toString()s.
| Modifier and Type | Class and Description |
|---|---|
static class |
Counter.AggregationKind
Possible kinds of counter aggregation.
|
static interface |
Counter.CounterMean<T>
The mean value of a
Counter, represented as an aggregate value and
a count. |
| Modifier and Type | Field and Description |
|---|---|
protected Counter.AggregationKind |
kind
The kind of aggregation function to apply to this counter.
|
protected String |
name
The name of this counter.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Counter(String name,
Counter.AggregationKind kind) |
| Modifier and Type | Method and Description |
|---|---|
abstract Counter<T> |
addValue(T value)
Adds a new value to the aggregation stream.
|
static Counter<Boolean> |
booleans(String name,
Counter.AggregationKind kind)
|
static Counter<Double> |
doubles(String name,
Counter.AggregationKind kind)
|
boolean |
equals(Object o) |
abstract T |
getAggregate()
Returns the aggregated value, or the sum for MEAN aggregation, either
total or, if delta, since the last update extraction or resetDelta.
|
abstract T |
getAndResetDelta()
Resets the counter's delta value to have no values accumulated and returns
the value of the delta prior to the reset.
|
abstract Counter.CounterMean<T> |
getAndResetMeanDelta()
Resets the counter's delta value to have no values accumulated and returns
the value of the delta prior to the reset, for a MEAN counter.
|
Counter.AggregationKind |
getKind()
Returns the counter's aggregation kind.
|
abstract Counter.CounterMean<T> |
getMean()
Returns the mean in the form of a CounterMean, or null if this is not a
MEAN counter.
|
String |
getName()
Returns the counter's name.
|
Class<?> |
getType()
Returns the counter's type.
|
int |
hashCode() |
protected IllegalArgumentException |
illegalArgumentException()
Constructs an
IllegalArgumentException explaining that this
Counter's aggregation kind is not supported by its value type. |
static Counter<Integer> |
ints(String name,
Counter.AggregationKind kind)
|
boolean |
isCompatibleWith(Counter<?> that)
Returns whether this Counter is compatible with that Counter.
|
static Counter<Long> |
longs(String name,
Counter.AggregationKind kind)
|
abstract Counter<T> |
resetMeanToValue(long elementCount,
T value)
Resets the aggregation stream to this new value.
|
abstract Counter<T> |
resetToValue(T value)
Resets the aggregation stream to this new value.
|
String |
toString()
Returns a string representation of the Counter.
|
protected final String name
protected final Counter.AggregationKind kind
protected Counter(String name, Counter.AggregationKind kind)
public static Counter<Integer> ints(String name, Counter.AggregationKind kind)
Counter that aggregates Integer, values
according to the desired aggregation kind. The supported aggregation kinds
are Counter.AggregationKind.SUM, Counter.AggregationKind.MIN,
Counter.AggregationKind.MAX, and Counter.AggregationKind.MEAN.
This is a convenience wrapper over a
Counter implementation that aggregates Long values. This is
useful when the application handles (boxed) Integer values that
are not readily convertible to the (boxed) Long values otherwise
expected by the Counter implementation aggregating Long
values.name - the name of the new counterkind - the new counter's aggregation kindIllegalArgumentException - if the aggregation kind is not supportedpublic static Counter<Long> longs(String name, Counter.AggregationKind kind)
Counter that aggregates Long values
according to the desired aggregation kind. The supported aggregation kinds
are Counter.AggregationKind.SUM, Counter.AggregationKind.MIN,
Counter.AggregationKind.MAX, and Counter.AggregationKind.MEAN.name - the name of the new counterkind - the new counter's aggregation kindIllegalArgumentException - if the aggregation kind is not supportedpublic static Counter<Double> doubles(String name, Counter.AggregationKind kind)
Counter that aggregates Double values
according to the desired aggregation kind. The supported aggregation kinds
are Counter.AggregationKind.SUM, Counter.AggregationKind.MIN,
Counter.AggregationKind.MAX, and Counter.AggregationKind.MEAN.name - the name of the new counterkind - the new counter's aggregation kindIllegalArgumentException - if the aggregation kind is not supportedpublic static Counter<Boolean> booleans(String name, Counter.AggregationKind kind)
Counter that aggregates Boolean values
according to the desired aggregation kind. The only supported aggregation
kinds are Counter.AggregationKind.AND and Counter.AggregationKind.OR.name - the name of the new counterkind - the new counter's aggregation kindIllegalArgumentException - if the aggregation kind is not supportedpublic abstract Counter<T> addValue(T value)
public abstract Counter<T> resetToValue(T value)
public abstract Counter<T> resetMeanToValue(long elementCount, T value)
public abstract T getAndResetDelta()
public abstract Counter.CounterMean<T> getAndResetMeanDelta()
public String getName()
public Counter.AggregationKind getKind()
public Class<?> getType()
public abstract T getAggregate()
@Nullable public abstract Counter.CounterMean<T> getMean()
public String toString()
public boolean isCompatibleWith(Counter<?> that)
protected IllegalArgumentException illegalArgumentException()
IllegalArgumentException explaining that this
Counter's aggregation kind is not supported by its value type.