- java.lang.Object
-
- com.pervasive.datarush.monitoring.BasicCounter
-
- All Implemented Interfaces:
CounterSupplier
,StatisticSupplier
public final class BasicCounter extends Object implements CounterSupplier
Basic mutable implementation ofCounterSupplier
. Counters must be started before they are first incremented. Once they have stopped they cannot be started again.
-
-
Constructor Summary
Constructors Constructor Description BasicCounter()
Creates a counter with an initial count of 0.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getCount()
This will return the value of the counter or an undefined value if never started.StatisticState
getState()
Returns the current state of the supplier.void
increment()
Increments the counter by1
void
increment(long stepSize)
Increments the counter by the specified step sizeCounterSupplier
snapshot()
Returns a snapshot of this statistic.void
start()
Places the counter in theStatisticState.ACTIVE
.void
stop()
Places the counter in the stopped state.
-
-
-
Constructor Detail
-
BasicCounter
public BasicCounter()
Creates a counter with an initial count of 0. Prior to callingincrement()
for the first time,start()
must be called.
-
-
Method Detail
-
start
public void start()
Places the counter in theStatisticState.ACTIVE
.- Throws:
IllegalStateException
- if the counter is already started or has finished
-
stop
public void stop()
Places the counter in the stopped state. This method can be called while in any state and thus is safe to call within afinally
block.
-
getState
public StatisticState getState()
Description copied from interface:StatisticSupplier
Returns the current state of the supplier.- Specified by:
getState
in interfaceStatisticSupplier
- Returns:
- the state of the supplier
-
increment
public void increment()
Increments the counter by1
-
increment
public void increment(long stepSize)
Increments the counter by the specified step size- Parameters:
stepSize
- the amount by which to increment
-
snapshot
public CounterSupplier snapshot()
Description copied from interface:StatisticSupplier
Returns a snapshot of this statistic.- Specified by:
snapshot
in interfaceCounterSupplier
- Specified by:
snapshot
in interfaceStatisticSupplier
- Returns:
- a snapshot of this statistic.
-
getCount
public long getCount()
Description copied from interface:CounterSupplier
This will return the value of the counter or an undefined value if never started.- Specified by:
getCount
in interfaceCounterSupplier
- Returns:
- the value of the counter or an undefined value if never started.
-
-