public class DistributedAtomicValue
extends java.lang.Object
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 | Description |
|---|---|
DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
org.apache.curator.RetryPolicy retryPolicy) |
Creates in optimistic mode only - i.e.
|
DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock) |
Creates in mutex promotion mode.
|
| Modifier and Type | Method | Description |
|---|---|---|
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.
|
public DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
org.apache.curator.RetryPolicy retryPolicy)
client - the clientpath - path to hold the valueretryPolicy - the retry policy to usepublic DistributedAtomicValue(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
org.apache.curator.RetryPolicy retryPolicy,
PromotedToLock promotedToLock)
InterProcessMutex will be tried
with its own retry policyclient - the clientpath - path to hold the valueretryPolicy - the retry policy to usepromotedToLock - the arguments for the mutex promotionpublic AtomicValue<byte[]> get() throws java.lang.Exception
0 is returned.java.lang.Exception - ZooKeeper errorspublic void forceSet(byte[] newValue)
throws java.lang.Exception
newValue - the new valuejava.lang.Exception - ZooKeeper errorspublic AtomicValue<byte[]> compareAndSet(byte[] expectedValue, byte[] newValue) throws java.lang.Exception
== the expected value.
Remember to always check AtomicValue.succeeded().expectedValue - the expected valuenewValue - the new valuejava.lang.Exception - ZooKeeper errorspublic AtomicValue<byte[]> trySet(byte[] newValue) throws java.lang.Exception
AtomicValue.succeeded().newValue - the value to setjava.lang.Exception - ZooKeeper errorspublic boolean initialize(byte[] value)
throws java.lang.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 setjava.lang.Exception - ZooKeeper errorsCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.