|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.curator.framework.recipes.atomic.DistributedAtomicInteger
public class DistributedAtomicInteger
A counter that attempts atomic increments. It first tries uses optimistic locking. If that fails,
an optional InterProcessMutex is taken. For both optimistic and mutex, a retry policy is used to
retry the increment.
The various increment methods return an AtomicValue object. You must always check
AtomicValue.succeeded(). None of the methods (other than get()) are guaranteed to succeed.
| Constructor Summary | |
|---|---|
DistributedAtomicInteger(org.apache.curator.framework.CuratorFramework client,
String counterPath,
org.apache.curator.RetryPolicy retryPolicy)
Creates in optimistic mode only - i.e. |
|
DistributedAtomicInteger(org.apache.curator.framework.CuratorFramework client,
String counterPath,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock)
Creates in mutex promotion mode. |
|
| Method Summary | |
|---|---|
AtomicValue<Integer> |
add(Integer delta)
Add delta to the current value and return the new value information. |
AtomicValue<Integer> |
compareAndSet(Integer expectedValue,
Integer newValue)
Atomically sets the value to the given updated value if the current value == the expected value. |
AtomicValue<Integer> |
decrement()
Subtract 1 from the current value and return the new value information. |
void |
forceSet(Integer newValue)
Forcibly sets the value of the counter without any guarantees of atomicity. |
AtomicValue<Integer> |
get()
Returns the current value of the counter. |
AtomicValue<Integer> |
increment()
Add 1 to the current value and return the new value information. |
boolean |
initialize(Integer initialize)
Atomic values are initially set to the equivalent of NULL in a database. |
AtomicValue<Integer> |
subtract(Integer delta)
Subtract delta from the current value and return the new value information. |
AtomicValue<Integer> |
trySet(Integer newValue)
Attempt to atomically set the value to the given value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DistributedAtomicInteger(org.apache.curator.framework.CuratorFramework client,
String counterPath,
org.apache.curator.RetryPolicy retryPolicy)
client - the clientcounterPath - path to hold the valueretryPolicy - the retry policy to use
public DistributedAtomicInteger(org.apache.curator.framework.CuratorFramework client,
String counterPath,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock)
InterProcessMutex will be tried
with its own retry policy
client - the clientcounterPath - path to hold the valueretryPolicy - the retry policy to usepromotedToLock - the arguments for the mutex promotion| Method Detail |
|---|
public AtomicValue<Integer> get()
throws Exception
DistributedAtomicNumber0 is returned.
get in interface DistributedAtomicNumber<Integer>Exception - ZooKeeper errors
public void forceSet(Integer newValue)
throws Exception
DistributedAtomicNumber
forceSet in interface DistributedAtomicNumber<Integer>newValue - the new value
Exception - ZooKeeper errors
public AtomicValue<Integer> compareAndSet(Integer expectedValue,
Integer newValue)
throws Exception
DistributedAtomicNumber== the expected value.
Remember to always check AtomicValue.succeeded().
compareAndSet in interface DistributedAtomicNumber<Integer>expectedValue - the expected valuenewValue - the new value for the counter
Exception - ZooKeeper errors
public AtomicValue<Integer> trySet(Integer newValue)
throws Exception
DistributedAtomicNumberAtomicValue.succeeded().
trySet in interface DistributedAtomicNumber<Integer>newValue - the value to set
Exception - ZooKeeper errors
public boolean initialize(Integer initialize)
throws Exception
DistributedAtomicNumberNULL in a database.
Use this method to initialize the value. The value will be set if and only iff the node does not exist.
initialize in interface DistributedAtomicNumber<Integer>initialize - the initial value to set
Exception - ZooKeeper errors
public AtomicValue<Integer> increment()
throws Exception
AtomicValue.succeeded().
increment in interface DistributedAtomicNumber<Integer>Exception - ZooKeeper errors
public AtomicValue<Integer> decrement()
throws Exception
AtomicValue.succeeded().
decrement in interface DistributedAtomicNumber<Integer>Exception - ZooKeeper errors
public AtomicValue<Integer> add(Integer delta)
throws Exception
AtomicValue.succeeded().
add in interface DistributedAtomicNumber<Integer>delta - amount to add
Exception - ZooKeeper errors
public AtomicValue<Integer> subtract(Integer delta)
throws Exception
AtomicValue.succeeded().
subtract in interface DistributedAtomicNumber<Integer>delta - amount to subtract
Exception - ZooKeeper errors
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||