org.terracotta.counter
Class SimpleCounterImpl

java.lang.Object
  extended by org.terracotta.counter.SimpleCounterImpl
All Implemented Interfaces:
Serializable, Counter, Statistic
Direct Known Subclasses:
BoundedCounter

public class SimpleCounterImpl
extends Object
implements Counter, Serializable

A simple non-clusterable atomic counter implementation.

See Also:
Serialized Form

Constructor Summary
SimpleCounterImpl()
          Creates a new counter with an initial value of 0.
SimpleCounterImpl(long initialValue)
          Creates a new counter with the given initial value.
 
Method Summary
 long decrement()
          Decrements the count by one.
 long decrement(long amount)
          Decrements the count by amount.
 long getAndReset()
          Performs an atomic getAndSet(0).
 long getAndSet(long newValue)
          Atomically sets the new value and returns the previous value.
 long getValue()
          Get the current value.
 long increment()
          Increments the count by one.
 long increment(long amount)
          Increments the count by amount.
 void setValue(long newValue)
          Set the count to the supplied value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCounterImpl

public SimpleCounterImpl()
Creates a new counter with an initial value of 0.


SimpleCounterImpl

public SimpleCounterImpl(long initialValue)
Creates a new counter with the given initial value.

Parameters:
initialValue - initial value for the counter
Method Detail

increment

public long increment()
Description copied from interface: Counter
Increments the count by one.

Specified by:
increment in interface Counter
Returns:
the new count value

decrement

public long decrement()
Description copied from interface: Counter
Decrements the count by one.

Specified by:
decrement in interface Counter
Returns:
the new count value

getAndSet

public long getAndSet(long newValue)
Atomically sets the new value and returns the previous value.

Specified by:
getAndSet in interface Counter
Parameters:
newValue - value to set to
Returns:
the old value

getAndReset

public long getAndReset()
Performs an atomic getAndSet(0).

Specified by:
getAndReset in interface Statistic

getValue

public long getValue()
Description copied from interface: Statistic
Get the current value.

Specified by:
getValue in interface Statistic

increment

public long increment(long amount)
Description copied from interface: Counter
Increments the count by amount.

Specified by:
increment in interface Counter
Parameters:
amount - amount to increment by
Returns:
the new value

decrement

public long decrement(long amount)
Description copied from interface: Counter
Decrements the count by amount.

Specified by:
decrement in interface Counter
Parameters:
amount - amount to increment by
Returns:
the new value

setValue

public void setValue(long newValue)
Description copied from interface: Counter
Set the count to the supplied value.

Specified by:
setValue in interface Counter
Parameters:
newValue - value to set to


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