Interface DistributedAtomicNumber<T>
-
- All Known Implementing Classes:
DistributedAtomicInteger,DistributedAtomicLong
public interface DistributedAtomicNumber<T>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AtomicValue<T>add(T delta)Add delta to the current value and return the new value information.AtomicValue<T>compareAndSet(T expectedValue, T newValue)Atomically sets the value to the given updated value if the current value==the expected value.AtomicValue<T>decrement()Subtract 1 from the current value and return the new value information.voidforceSet(T newValue)Forcibly sets the value of the counter without any guarantees of atomicity.AtomicValue<T>get()Returns the current value of the counter.AtomicValue<T>increment()Add 1 to the current value and return the new value information.booleaninitialize(T value)Atomic values are initially set to the equivalent ofNULLin a database.AtomicValue<T>subtract(T delta)Subtract delta from the current value and return the new value information.AtomicValue<T>trySet(T newValue)Attempt to atomically set the value to the given value.
-
-
-
Method Detail
-
get
AtomicValue<T> get() throws java.lang.Exception
Returns the current value of the counter. NOTE: if the value has never been set,0is returned.- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
compareAndSet
AtomicValue<T> compareAndSet(T expectedValue, T newValue) throws java.lang.Exception
Atomically sets the value to the given updated value if the current value==the expected value. Remember to always checkAtomicValue.succeeded().- Parameters:
expectedValue- the expected valuenewValue- the new value for the counter- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
trySet
AtomicValue<T> trySet(T newValue) throws java.lang.Exception
Attempt to atomically set the value to the given value. Remember to always checkAtomicValue.succeeded().- Parameters:
newValue- the value to set- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
initialize
boolean initialize(T value) throws java.lang.Exception
Atomic values are initially set to the equivalent ofNULLin a database. Use this method to initialize the value. The value will be set if and only iff the node does not exist.- Parameters:
value- the initial value to set- Returns:
- true if the value was set, false if the node already existed
- Throws:
java.lang.Exception- ZooKeeper errors
-
forceSet
void forceSet(T newValue) throws java.lang.Exception
Forcibly sets the value of the counter without any guarantees of atomicity.- Parameters:
newValue- the new value- Throws:
java.lang.Exception- ZooKeeper errors
-
increment
AtomicValue<T> increment() throws java.lang.Exception
Add 1 to the current value and return the new value information. Remember to always checkAtomicValue.succeeded().- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
decrement
AtomicValue<T> decrement() throws java.lang.Exception
Subtract 1 from the current value and return the new value information. Remember to always checkAtomicValue.succeeded().- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
add
AtomicValue<T> add(T delta) throws java.lang.Exception
Add delta to the current value and return the new value information. Remember to always checkAtomicValue.succeeded().- Parameters:
delta- amount to add- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
subtract
AtomicValue<T> subtract(T delta) throws java.lang.Exception
Subtract delta from the current value and return the new value information. Remember to always checkAtomicValue.succeeded().- Parameters:
delta- amount to subtract- Returns:
- value info
- Throws:
java.lang.Exception- ZooKeeper errors
-
-