|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.curator.framework.recipes.atomic.DistributedAtomicValue
public class DistributedAtomicValue
A distributed value that attempts atomic sets. 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 methods return an AtomicValue object. You must always check
AtomicValue.succeeded(). None of the methods (other than get()) are guaranteed to succeed.
| Constructor Summary | |
|---|---|
DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
String path,
org.apache.curator.RetryPolicy retryPolicy)
Creates in optimistic mode only - i.e. |
|
DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
String path,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock)
Creates in mutex promotion mode. |
|
| Method Summary | |
|---|---|
AtomicValue<byte[]> |
compareAndSet(byte[] expectedValue,
byte[] newValue)
Atomically sets the value to the given updated value if the current value == the expected value. |
void |
forceSet(byte[] newValue)
Forcibly sets the value any guarantees of atomicity. |
AtomicValue<byte[]> |
get()
Returns the current value of the counter. |
boolean |
initialize(byte[] value)
Atomic values are initially set to the equivalent of NULL in a database. |
AtomicValue<byte[]> |
trySet(byte[] 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 DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
String path,
org.apache.curator.RetryPolicy retryPolicy)
client - the clientpath - path to hold the valueretryPolicy - the retry policy to use
public DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
String path,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock)
InterProcessMutex will be tried
with its own retry policy
client - the clientpath - path to hold the valueretryPolicy - the retry policy to usepromotedToLock - the arguments for the mutex promotion| Method Detail |
|---|
public AtomicValue<byte[]> get()
throws Exception
0 is returned.
Exception - ZooKeeper errors
public void forceSet(byte[] newValue)
throws Exception
newValue - the new value
Exception - ZooKeeper errors
public AtomicValue<byte[]> compareAndSet(byte[] expectedValue,
byte[] newValue)
throws Exception
== the expected value.
Remember to always check AtomicValue.succeeded().
expectedValue - the expected valuenewValue - the new value
Exception - ZooKeeper errors
public AtomicValue<byte[]> trySet(byte[] newValue)
throws Exception
AtomicValue.succeeded().
newValue - the value to set
Exception - ZooKeeper errors
public boolean initialize(byte[] value)
throws Exception
NULL in a database.
Use this method to initialize the value. The value will be set if and only iff the node does not exist.
value - the initial value to set
Exception - ZooKeeper errors
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||