public class SharedValue extends Object implements Closeable, SharedValueReader
Modifier | Constructor and Description |
---|---|
|
SharedValue(CuratorFramework client,
String path,
byte[] seedValue) |
protected |
SharedValue(WatcherRemoveCuratorFramework client,
String path,
byte[] seedValue,
CuratorWatcher watcher) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
Listenable<SharedValueListener> |
getListenable()
Returns the listenable
|
byte[] |
getValue()
Return the current value of the count
|
VersionedValue<byte[]> |
getVersionedValue()
Return the current version and value
|
void |
setValue(byte[] newValue)
Change the shared value value irrespective of its previous state
|
void |
start()
The shared value must be started before it can be used.
|
boolean |
trySetValue(byte[] newValue)
Deprecated.
use
trySetValue(VersionedValue, byte[]) for stronger atomicity
guarantees. Even if this object's internal state is up-to-date, the caller has no way to
ensure that they've read the most recently seen value. |
boolean |
trySetValue(VersionedValue<byte[]> previous,
byte[] newValue)
Changes the shared value only if its value has not changed since the version specified by
newValue.
|
public SharedValue(CuratorFramework client, String path, byte[] seedValue)
client
- the clientpath
- the shared path - i.e. where the shared value is storedseedValue
- the initial value for the value if/f the path has not yet been createdprotected SharedValue(WatcherRemoveCuratorFramework client, String path, byte[] seedValue, CuratorWatcher watcher)
public byte[] getValue()
SharedValueReader
getValue
in interface SharedValueReader
public VersionedValue<byte[]> getVersionedValue()
SharedValueReader
getVersionedValue
in interface SharedValueReader
public void setValue(byte[] newValue) throws Exception
newValue
- new valueException
- ZK errors, interruptions, etc.@Deprecated public boolean trySetValue(byte[] newValue) throws Exception
trySetValue(VersionedValue, byte[])
for stronger atomicity
guarantees. Even if this object's internal state is up-to-date, the caller has no way to
ensure that they've read the most recently seen value.getValue()
.newValue
- the new value to attemptgetValue()
will return the updated valueException
- ZK errors, interruptions, etc.public boolean trySetValue(VersionedValue<byte[]> previous, byte[] newValue) throws Exception
getValue()
.newValue
- the new value to attemptgetValue()
will return the updated valueException
- ZK errors, interruptions, etc.public Listenable<SharedValueListener> getListenable()
getListenable
in interface SharedValueReader
public void start() throws Exception
close()
when you are
finished with the shared valueException
- ZK errors, interruptions, etc.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.