DistributedAtomicNumber<java.lang.Long>public class DistributedAtomicLong extends java.lang.Object implements DistributedAtomicNumber<java.lang.Long>
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 | Description |
|---|---|
DistributedAtomicLong(org.apache.curator.framework.CuratorFramework client,
java.lang.String counterPath,
org.apache.curator.RetryPolicy retryPolicy) |
Creates in optimistic mode only - i.e.
|
DistributedAtomicLong(org.apache.curator.framework.CuratorFramework client,
java.lang.String counterPath,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock) |
Creates in mutex promotion mode.
|
| Modifier and Type | Method | Description |
|---|---|---|
AtomicValue<java.lang.Long> |
add(java.lang.Long delta) |
Add delta to the current value and return the new value information.
|
AtomicValue<java.lang.Long> |
compareAndSet(java.lang.Long expectedValue,
java.lang.Long newValue) |
Atomically sets the value to the given updated value
if the current value
== the expected value. |
AtomicValue<java.lang.Long> |
decrement() |
Subtract 1 from the current value and return the new value information.
|
void |
forceSet(java.lang.Long newValue) |
Forcibly sets the value of the counter without any guarantees of atomicity.
|
AtomicValue<java.lang.Long> |
get() |
Returns the current value of the counter.
|
AtomicValue<java.lang.Long> |
increment() |
Add 1 to the current value and return the new value information.
|
boolean |
initialize(java.lang.Long initialize) |
Atomic values are initially set to the equivalent of
NULL in a database. |
AtomicValue<java.lang.Long> |
subtract(java.lang.Long delta) |
Subtract delta from the current value and return the new value information.
|
AtomicValue<java.lang.Long> |
trySet(java.lang.Long newValue) |
Attempt to atomically set the value to the given value.
|
public DistributedAtomicLong(org.apache.curator.framework.CuratorFramework client,
java.lang.String counterPath,
org.apache.curator.RetryPolicy retryPolicy)
client - the clientcounterPath - path to hold the valueretryPolicy - the retry policy to usepublic DistributedAtomicLong(org.apache.curator.framework.CuratorFramework client,
java.lang.String counterPath,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock)
InterProcessMutex will be tried
with its own retry policyclient - the clientcounterPath - path to hold the valueretryPolicy - the retry policy to usepromotedToLock - the arguments for the mutex promotionpublic AtomicValue<java.lang.Long> get() throws java.lang.Exception
DistributedAtomicNumber0 is returned.get in interface DistributedAtomicNumber<java.lang.Long>java.lang.Exception - ZooKeeper errorspublic void forceSet(java.lang.Long newValue)
throws java.lang.Exception
DistributedAtomicNumberforceSet in interface DistributedAtomicNumber<java.lang.Long>newValue - the new valuejava.lang.Exception - ZooKeeper errorspublic AtomicValue<java.lang.Long> compareAndSet(java.lang.Long expectedValue, java.lang.Long newValue) throws java.lang.Exception
DistributedAtomicNumber== the expected value.
Remember to always check AtomicValue.succeeded().compareAndSet in interface DistributedAtomicNumber<java.lang.Long>expectedValue - the expected valuenewValue - the new value for the counterjava.lang.Exception - ZooKeeper errorspublic AtomicValue<java.lang.Long> trySet(java.lang.Long newValue) throws java.lang.Exception
DistributedAtomicNumberAtomicValue.succeeded().trySet in interface DistributedAtomicNumber<java.lang.Long>newValue - the value to setjava.lang.Exception - ZooKeeper errorspublic boolean initialize(java.lang.Long initialize)
throws java.lang.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<java.lang.Long>initialize - the initial value to setjava.lang.Exception - ZooKeeper errorspublic AtomicValue<java.lang.Long> increment() throws java.lang.Exception
AtomicValue.succeeded().increment in interface DistributedAtomicNumber<java.lang.Long>java.lang.Exception - ZooKeeper errorspublic AtomicValue<java.lang.Long> decrement() throws java.lang.Exception
AtomicValue.succeeded().decrement in interface DistributedAtomicNumber<java.lang.Long>java.lang.Exception - ZooKeeper errorspublic AtomicValue<java.lang.Long> add(java.lang.Long delta) throws java.lang.Exception
AtomicValue.succeeded().add in interface DistributedAtomicNumber<java.lang.Long>delta - amount to addjava.lang.Exception - ZooKeeper errorspublic AtomicValue<java.lang.Long> subtract(java.lang.Long delta) throws java.lang.Exception
AtomicValue.succeeded().subtract in interface DistributedAtomicNumber<java.lang.Long>delta - amount to subtractjava.lang.Exception - ZooKeeper errorsCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.