org.terracotta.counter
Class BoundedCounter

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

public class BoundedCounter
extends SimpleCounterImpl

A bounded counter implementation that prevents it's value from exceeded a pre-defined set of bounds.

Any setting operation which would cause an out-of-bounds condition is ignored.

See Also:
Serialized Form

Constructor Summary
BoundedCounter(long initialValue, long minValue, long maxValue)
          Creates a bounded counter with the given initial value and bounds.
 
Method Summary
 long decrement()
          Decrements the count by one.
 long decrement(long amount)
          Decrements the count by amount.
 long getAndSet(long newValue)
          Atomically sets the new value and returns the previous 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 org.terracotta.counter.SimpleCounterImpl
getAndReset, getValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BoundedCounter

public BoundedCounter(long initialValue,
                      long minValue,
                      long maxValue)
Creates a bounded counter with the given initial value and bounds.

Parameters:
initialValue - the initial counter value
minValue - the inclusive upper bound
maxValue - the inclusive lower bound
Method Detail

decrement

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

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

decrement

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

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

getAndSet

public long getAndSet(long newValue)
Description copied from class: SimpleCounterImpl
Atomically sets the new value and returns the previous value.

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

increment

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

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

increment

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

Specified by:
increment in interface Counter
Overrides:
increment in class SimpleCounterImpl
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
Overrides:
setValue in class SimpleCounterImpl
Parameters:
newValue - value to set to


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