public interface Counter
An asynchronous counter that can be used to across the cluster to maintain a consistent count.
- Author:
- Tim Fox
-
Method Summary
Modifier and TypeMethodDescriptionaddAndGet(long value) Add the value to the counter atomically and return the new countcompareAndSet(long expected, long value) Set the counter to the specified value only if the current value is the expectec value.Decrement the counter atomically and return the new countget()Get the current value of the countergetAndAdd(long value) Add the value to the counter atomically and return the value before the addIncrement the counter atomically and return the value before the increment.Increment the counter atomically and return the new count
-
Method Details
-
get
Get the current value of the counter- Returns:
- a future notified with the value
-
incrementAndGet
Increment the counter atomically and return the new count- Returns:
- a future notified with the value
-
getAndIncrement
Increment the counter atomically and return the value before the increment.- Returns:
- a future notified with the value
-
decrementAndGet
Decrement the counter atomically and return the new count- Returns:
- a future notified with the value
-
addAndGet
Add the value to the counter atomically and return the new count- Parameters:
value- the value to add- Returns:
- a future notified with the value
-
getAndAdd
Add the value to the counter atomically and return the value before the add- Parameters:
value- the value to add- Returns:
- a future notified with the value
-
compareAndSet
Set the counter to the specified value only if the current value is the expectec value. This happens atomically.- Parameters:
expected- the expected valuevalue- the new value- Returns:
- a future notified with
trueon success
-