org.terracotta.counter
Class RateCounterImpl

java.lang.Object
  extended by org.terracotta.counter.RateCounterImpl
All Implemented Interfaces:
RateCounter, Statistic

public class RateCounterImpl
extends Object
implements RateCounter

A simple atomic rate counter implementation.


Constructor Summary
RateCounterImpl()
          Creates a new counter with both denominator and numerator at 0.
RateCounterImpl(long numerator, long denominator)
          Create a new counter with a defined denominator and numerator.
 
Method Summary
 void decrement(long numerator, long denominator)
          Decrement the numerator and denominator by the given amounts.
 long getAndReset()
          Get the current and then reset this statistic.
 long getValue()
          Get the current value.
 void increment(long numerator, long denominator)
          Increment the numerator and denominator by the given amounts.
 void setDenominatorValue(long newValue)
          Set the denominator to the given value.
 void setNumeratorValue(long newValue)
          Set the numerator to the given value.
 void setValue(long numerator, long denominator)
          Set the numerator and denominator to the given values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RateCounterImpl

public RateCounterImpl()
Creates a new counter with both denominator and numerator at 0.


RateCounterImpl

public RateCounterImpl(long numerator,
                       long denominator)
Create a new counter with a defined denominator and numerator.

Parameters:
numerator - the inital numerator value
denominator - the initial denominator value
Method Detail

setValue

public void setValue(long numerator,
                     long denominator)
Description copied from interface: RateCounter
Set the numerator and denominator to the given values.

Specified by:
setValue in interface RateCounter
Parameters:
numerator - new numerator value
denominator - new denominator value

increment

public void increment(long numerator,
                      long denominator)
Description copied from interface: RateCounter
Increment the numerator and denominator by the given amounts.

Specified by:
increment in interface RateCounter

decrement

public void decrement(long numerator,
                      long denominator)
Description copied from interface: RateCounter
Decrement the numerator and denominator by the given amounts.

Specified by:
decrement in interface RateCounter

setDenominatorValue

public void setDenominatorValue(long newValue)
Description copied from interface: RateCounter
Set the denominator to the given value.

Specified by:
setDenominatorValue in interface RateCounter
Parameters:
newValue - new denominator value

setNumeratorValue

public void setNumeratorValue(long newValue)
Description copied from interface: RateCounter
Set the numerator to the given value.

Specified by:
setNumeratorValue in interface RateCounter
Parameters:
newValue - new numerator value

getValue

public long getValue()
Get the current value. If the denominator is zero, then a zero rate value is returned.

Specified by:
getValue in interface Statistic

getAndReset

public long getAndReset()
Get the current and then reset this statistic. Reset for this implementation returns both the denominator and numerator to zero.

Specified by:
getAndReset in interface Statistic


Copyright © 2015 Terracotta, Inc.. All Rights Reserved.