public class MonitoredCounter extends AbstractMonitorable<java.lang.Long> implements Counter
Monitorable
specifically for
implementing long-valued counters.
This class should be used to measure incrementing counter values only. For any other values, use
MonitoredValue
or another subclass of SettableValue
.
In Parfait terms, a counter is a value that increments over time due to an event. An example of a counter might the number of JMS messages sent or Garbage collections completed. Note that this class explicitly provides an atomic increment operation only. Values must not decrement or be set to an arbitrary value.
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicLong |
value |
LOG
NULL_COUNTER
Constructor and Description |
---|
MonitoredCounter(java.lang.String name,
java.lang.String description)
Creates a new MonitoredCounter against
the default registry with no
unit semantics. |
MonitoredCounter(java.lang.String name,
java.lang.String description,
MonitorableRegistry registry)
Creates a new MonitoredCounter against the given registry with no unit
semantics.
|
MonitoredCounter(java.lang.String name,
java.lang.String description,
MonitorableRegistry registry,
javax.measure.Unit<?> unit)
Creates a new MonitoredCounter against the provided
MonitorableRegistry with the given unit semantics. |
MonitoredCounter(java.lang.String name,
java.lang.String description,
javax.measure.Unit<?> unit)
Creates a new MonitoredCounter against
the default registry |
Modifier and Type | Method and Description |
---|---|
java.lang.Long |
get()
This method should never block and must return as quickly as possible.
|
void |
inc()
Increments the counter by one.
|
void |
inc(long value)
Increments the counter by a given value.
|
void |
set(long newValue)
Reset the counter to a specific value.
|
attachMonitor, getDescription, getName, getSemantics, getType, getUnit, isAttached, logValue, notifyMonitors, registerSelf, removeMonitor
public MonitoredCounter(java.lang.String name, java.lang.String description)
the default registry
with no
unit semantics.public MonitoredCounter(java.lang.String name, java.lang.String description, MonitorableRegistry registry)
public MonitoredCounter(java.lang.String name, java.lang.String description, javax.measure.Unit<?> unit)
the default registry
public MonitoredCounter(java.lang.String name, java.lang.String description, MonitorableRegistry registry, javax.measure.Unit<?> unit)
MonitorableRegistry
with the given unit semantics.public java.lang.Long get()
Monitorable
get
in interface Monitorable<java.lang.Long>
public void set(long newValue)
Reset the counter to a specific value. This is not the typical use of this class;
this class' value is typically monotonically increasing, and should not roam freely, making
inc(long)
the more common usage
Use this method in the case of a 'reset' or similar functionality, or in the case where values are being extracted from a monotonically-increasing source and we need to use that source's value verbatim.
public void inc(long value)