public interface DistributedAtomicNumber<T>
Modifier and Type | Method and 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.
|
void |
forceSet(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.
|
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.
|
AtomicValue<T> get() throws java.lang.Exception
0
is returned.java.lang.Exception
- ZooKeeper errorsAtomicValue<T> compareAndSet(T expectedValue, T newValue) throws java.lang.Exception
==
the expected value.
Remember to always check AtomicValue.succeeded()
.expectedValue
- the expected valuenewValue
- the new value for the counterjava.lang.Exception
- ZooKeeper errorsAtomicValue<T> trySet(T newValue) throws java.lang.Exception
AtomicValue.succeeded()
.newValue
- the value to setjava.lang.Exception
- ZooKeeper errorsvoid forceSet(T newValue) throws java.lang.Exception
newValue
- the new valuejava.lang.Exception
- ZooKeeper errorsAtomicValue<T> increment() throws java.lang.Exception
AtomicValue.succeeded()
.java.lang.Exception
- ZooKeeper errorsAtomicValue<T> decrement() throws java.lang.Exception
AtomicValue.succeeded()
.java.lang.Exception
- ZooKeeper errorsAtomicValue<T> add(T delta) throws java.lang.Exception
AtomicValue.succeeded()
.delta
- amount to addjava.lang.Exception
- ZooKeeper errorsAtomicValue<T> subtract(T delta) throws java.lang.Exception
AtomicValue.succeeded()
.delta
- amount to subtractjava.lang.Exception
- ZooKeeper errors