org.javasimon
Interface Counter

All Superinterfaces:
HasAttributes, Simon
All Known Implementing Classes:
CounterImpl, NullCounter

public interface Counter
extends Simon

Counter tracks the single integer value and watches its max/min values. It can be used for values starting with 0 - in that case min might not be important if counter does not go bellow 0. Counter can also start from any other arbitrary number that is set after the first change (increment, decrement, set) - this is more typical case for tracking also the min value.

Initialization

When a counter is created, it is set to 0, but its maximum/minimum values are undefined:
 Counter counter = SimonManager.getCounter("com.my.counter");
 System.out.println("counter = " + counter);
Output is:
 counter = Simon Counter: [com.my.counter INHERIT] counter=0, max=undef, min=undef

This behavior allows the counter to be initialized before it is used and its exteremes are tracked - first initialization also sets max/min (extreme) values:

 Counter counter = SimonManager.getCounter("com.my.counter").set(47);
 System.out.println("counter = " + counter);
Output is:
 counter = Simon Counter: [com.my.counter INHERIT] counter=47, max=47, min=47

Usage

Typical Counter usage is based on increase() and decrease() methods when it is possible to track the monitored value - this can be used for example to count users logged in. If the value changes by more than 1 than it is possible to use methods with arguments - increase(long) and decrease(long). Finally method set(long) is always available to set the counter to the particular value when needed.

Author:
Richard "Virgo" Richter

Method Summary
 Counter decrease()
          Decrements the counter by one.
 Counter decrease(long dec)
          Increments the counter by the specified value.
 long getCounter()
          Returns the current value of the counter.
 long getDecrementSum()
          Returns the sum of all decremented values (as a positive number).
 long getIncrementSum()
          Returns the sum of all incremented values.
 long getMax()
          Returns maximal value of counter.
 long getMaxTimestamp()
          Returns ms timestamp when the max value was reached.
 long getMin()
          Returns minimal value of counter.
 long getMinTimestamp()
          Returns ms timestamp when the min value was reached.
 Counter increase()
          Increments the counter by one.
 Counter increase(long inc)
          Increments the counter by the specified value.
 Counter reset()
          Resets the Simon values related to the measuring, timestamps and so on - usage timestamps, state, attributes are not affected.
 CounterSample sample()
          Samples Simon values and returns them in a Java Bean derived from Sample interface.
 CounterSample sampleAndReset()
          Samples Simon values and returns them in a Java Bean derived from Sample interface and resets the Simon.
 Counter set(long val)
          Sets the value of the counter to specified value.
 
Methods inherited from interface org.javasimon.Simon
getFirstUsage, getChildren, getLastReset, getLastUsage, getName, getNote, getParent, getState, isEnabled, setNote, setState
 
Methods inherited from interface org.javasimon.HasAttributes
getAttribute, getAttribute, getAttributeNames, getCopyAsSortedMap, removeAttribute, setAttribute
 

Method Detail

increase

Counter increase()
Increments the counter by one.

Returns:
this

decrease

Counter decrease()
Decrements the counter by one.

Returns:
this

increase

Counter increase(long inc)
Increments the counter by the specified value.

Parameters:
inc - added value
Returns:
this

decrease

Counter decrease(long dec)
Increments the counter by the specified value.

Parameters:
dec - subtracted value
Returns:
this

getCounter

long getCounter()
Returns the current value of the counter.

Returns:
counter value

getMin

long getMin()
Returns minimal value of counter.

Returns:
maximal reached value

getMinTimestamp

long getMinTimestamp()
Returns ms timestamp when the min value was reached.

Returns:
ms timestamp of the min value decremented

getMax

long getMax()
Returns maximal value of counter.

Returns:
maximal reached value

getMaxTimestamp

long getMaxTimestamp()
Returns ms timestamp when the max value was reached.

Returns:
ms timestamp of the max value incremented

set

Counter set(long val)
Sets the value of the counter to specified value.

Parameters:
val - new counter value
Returns:
this

reset

Counter reset()
Description copied from interface: Simon
Resets the Simon values related to the measuring, timestamps and so on - usage timestamps, state, attributes are not affected. Timestamp of the last reset can be obtained by the method Simon.getLastReset(). Reset is perfomed even for disabled Simons.

Specified by:
reset in interface Simon
Returns:
returns this

getIncrementSum

long getIncrementSum()
Returns the sum of all incremented values. If incremented value was negative, sum is lowered by this value.

Returns:
sum of all incremented values

getDecrementSum

long getDecrementSum()
Returns the sum of all decremented values (as a positive number). If decremented value was negative, sum is lowered by this value.

Returns:
sum of all decremented values

sample

CounterSample sample()
Description copied from interface: Simon
Samples Simon values and returns them in a Java Bean derived from Sample interface.

Specified by:
sample in interface Simon
Returns:
sample containing all Simon values

sampleAndReset

CounterSample sampleAndReset()
Description copied from interface: Simon
Samples Simon values and returns them in a Java Bean derived from Sample interface and resets the Simon. Operation is synchronized to assure atomicity.

Specified by:
sampleAndReset in interface Simon
Returns:
sample containing all Simon values


Copyright © 2013. All Rights Reserved.