org.javasimon
Class CounterImpl

java.lang.Object
  extended by org.javasimon.AbstractSimon
      extended by org.javasimon.CounterImpl
All Implemented Interfaces:
Counter, HasAttributes, Simon

final class CounterImpl
extends AbstractSimon
implements Counter

Class implements Counter interface - see there for how to use Counter.

Author:
Richard "Virgo" Richter
See Also:
Counter

Field Summary
private  long counter
          An internal counter.
private  long decrementSum
          Sum of all decrements.
private  long incrementSum
          Sum of all increments.
private  long max
          A maximum tracker.
private  long maxTimestamp
           
private  long min
          A minimum tracker - only negative values.
private  long minTimestamp
           
 
Fields inherited from class org.javasimon.AbstractSimon
enabled, firstUsage, lastUsage, manager
 
Constructor Summary
CounterImpl(String name, Manager manager)
          Construts Counter Simon with a specified name and for the specified manager.
 
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.
private  void privateSet(long val, long now)
           
 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.
 String toString()
          Returns Simon basic information, counter, max value and min value as a human readable string.
private  void updateUsages(long now)
          Updates usage statistics.
 
Methods inherited from class org.javasimon.AbstractSimon
addChild, getAttribute, getAttribute, getAttributeNames, getCopyAsSortedMap, getFirstUsage, getChildren, getLastReset, getLastUsage, getName, getNote, getParent, getState, isEnabled, removeAttribute, replaceChild, resetCommon, sampleCommon, setAttribute, setNote, setParent, setState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
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
 

Field Detail

counter

private long counter
An internal counter.


incrementSum

private long incrementSum
Sum of all increments.


decrementSum

private long decrementSum
Sum of all decrements.


max

private long max
A maximum tracker.


maxTimestamp

private long maxTimestamp

min

private long min
A minimum tracker - only negative values.


minTimestamp

private long minTimestamp
Constructor Detail

CounterImpl

CounterImpl(String name,
            Manager manager)
Construts Counter Simon with a specified name and for the specified manager.

Parameters:
name - Simon's name
manager - owning manager
Method Detail

set

public Counter set(long val)
Description copied from interface: Counter
Sets the value of the counter to specified value.

Specified by:
set in interface Counter
Parameters:
val - new counter value
Returns:
this

privateSet

private void privateSet(long val,
                        long now)

increase

public Counter increase()
Description copied from interface: Counter
Increments the counter by one.

Specified by:
increase in interface Counter
Returns:
this

decrease

public Counter decrease()
Description copied from interface: Counter
Decrements the counter by one.

Specified by:
decrease in interface Counter
Returns:
this

updateUsages

private void updateUsages(long now)
Updates usage statistics.

Parameters:
now - current millis timestamp

increase

public Counter increase(long inc)
Description copied from interface: Counter
Increments the counter by the specified value.

Specified by:
increase in interface Counter
Parameters:
inc - added value
Returns:
this

decrease

public Counter decrease(long dec)
Description copied from interface: Counter
Increments the counter by the specified value.

Specified by:
decrease in interface Counter
Parameters:
dec - subtracted value
Returns:
this

reset

public 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 Counter
Specified by:
reset in interface Simon
Returns:
returns this

sampleAndReset

public 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 Counter
Specified by:
sampleAndReset in interface Simon
Returns:
sample containing all Simon values

sample

public 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 Counter
Specified by:
sample in interface Simon
Returns:
sample containing all Simon values

getCounter

public long getCounter()
Description copied from interface: Counter
Returns the current value of the counter.

Specified by:
getCounter in interface Counter
Returns:
counter value

getMin

public long getMin()
Description copied from interface: Counter
Returns minimal value of counter.

Specified by:
getMin in interface Counter
Returns:
maximal reached value

getMinTimestamp

public long getMinTimestamp()
Description copied from interface: Counter
Returns ms timestamp when the min value was reached.

Specified by:
getMinTimestamp in interface Counter
Returns:
ms timestamp of the min value decremented

getMax

public long getMax()
Description copied from interface: Counter
Returns maximal value of counter.

Specified by:
getMax in interface Counter
Returns:
maximal reached value

getMaxTimestamp

public long getMaxTimestamp()
Description copied from interface: Counter
Returns ms timestamp when the max value was reached.

Specified by:
getMaxTimestamp in interface Counter
Returns:
ms timestamp of the max value incremented

getIncrementSum

public long getIncrementSum()
Description copied from interface: Counter
Returns the sum of all incremented values. If incremented value was negative, sum is lowered by this value.

Specified by:
getIncrementSum in interface Counter
Returns:
sum of all incremented values

getDecrementSum

public long getDecrementSum()
Description copied from interface: Counter
Returns the sum of all decremented values (as a positive number). If decremented value was negative, sum is lowered by this value.

Specified by:
getDecrementSum in interface Counter
Returns:
sum of all decremented values

toString

public String toString()
Returns Simon basic information, counter, max value and min value as a human readable string.

Overrides:
toString in class AbstractSimon
Returns:
basic information, counter, max and min values
See Also:
AbstractSimon.toString()


Copyright © 2013. All Rights Reserved.