org.apache.commons.monitoring.impl.values
Class ThreadSafeCounter

java.lang.Object
  extended by org.apache.commons.monitoring.impl.values.AbstractStatValue<Counter>
      extended by org.apache.commons.monitoring.impl.values.ThreadSafeCounter
All Implemented Interfaces:
Counter, StatValue
Direct Known Subclasses:
CompositeCounter

public class ThreadSafeCounter
extends AbstractStatValue<Counter>
implements Counter

Thread-safe implementation of Counter, based on synchronized methods.

Author:
Nicolas De Loof

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.commons.monitoring.StatValue
StatValue.Listener
 
Constructor Summary
ThreadSafeCounter(Role<Counter> role)
           
 
Method Summary
 void add(long delta, Unit unit)
          Add value to the counter.
protected  void computeStats(long l)
           
 long get()
          
 double getMean()
          
protected  long getSquares()
           
 long getSum()
           
 void reset()
          reset the statValue
 void set(long l, Unit unit)
          
 
Methods inherited from class org.apache.commons.monitoring.impl.values.AbstractStatValue
addListener, fireValueChanged, getHits, getMax, getMin, getMonitor, getRole, getStandardDeviation, getUnit, normalize, removeListener, setMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.monitoring.Counter
getHits
 
Methods inherited from interface org.apache.commons.monitoring.StatValue
addListener, getMax, getMin, getMonitor, getRole, getStandardDeviation, getUnit, removeListener, setMonitor
 

Constructor Detail

ThreadSafeCounter

public ThreadSafeCounter(Role<Counter> role)
Method Detail

get

public long get()

Specified by:
get in interface StatValue
Returns:
the value

reset

public void reset()
Description copied from interface: StatValue
reset the statValue

Specified by:
reset in interface StatValue

set

public void set(long l,
                Unit unit)

Specified by:
set in interface StatValue
Parameters:
l - the value to set

add

public void add(long delta,
                Unit unit)
Description copied from interface: Counter
Add value to the counter. Delta should not be negative (in such case a Gauge should be used).

Specified by:
add in interface Counter

computeStats

protected void computeStats(long l)
Overrides:
computeStats in class AbstractStatValue<Counter>

getMean

public double getMean()
Description copied from class: AbstractStatValue

Specified by:
getMean in interface StatValue
Specified by:
getMean in class AbstractStatValue<Counter>
Returns:
the arithmetic mean value

getSquares

protected long getSquares()
Specified by:
getSquares in class AbstractStatValue<Counter>

getSum

public long getSum()
Specified by:
getSum in interface Counter
Specified by:
getSum in class AbstractStatValue<Counter>
Returns:
the sum of all set operations


Copyright © 2008 The Apache Software Foundation. All Rights Reserved.