Interface DistributedAtomicNumber<T>
- All Known Implementing Classes:
DistributedAtomicInteger
,DistributedAtomicLong
public interface DistributedAtomicNumber<T>
-
Method Summary
Modifier and TypeMethodDescriptionAdd delta to the current value and return the new value information.compareAndSet
(T expectedValue, T newValue) Atomically sets the value to the given updated value if the current value==
the expected value.Subtract 1 from the current value and return the new value information.void
Forcibly sets the value of the counter without any guarantees of atomicity.get()
Returns the current value of the counter.Add 1 to the current value and return the new value information.boolean
initialize
(T value) Atomic values are initially set to the equivalent ofNULL
in a database.Subtract delta from the current value and return the new value information.Attempt to atomically set the value to the given value.
-
Method Details
-
get
Returns the current value of the counter. NOTE: if the value has never been set,0
is returned.- Returns:
- value info
- Throws:
Exception
- ZooKeeper errors
-
compareAndSet
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:
Exception
- ZooKeeper errors
-
trySet
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:
Exception
- ZooKeeper errors
-
initialize
Atomic values are initially set to the equivalent ofNULL
in 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:
Exception
- ZooKeeper errors
-
forceSet
Forcibly sets the value of the counter without any guarantees of atomicity.- Parameters:
newValue
- the new value- Throws:
Exception
- ZooKeeper errors
-
increment
Add 1 to the current value and return the new value information. Remember to always checkAtomicValue.succeeded()
.- Returns:
- value info
- Throws:
Exception
- ZooKeeper errors
-
decrement
Subtract 1 from the current value and return the new value information. Remember to always checkAtomicValue.succeeded()
.- Returns:
- value info
- Throws:
Exception
- ZooKeeper errors
-
add
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:
Exception
- ZooKeeper errors
-
subtract
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:
Exception
- ZooKeeper errors
-