public class SharedValue extends java.lang.Object implements java.io.Closeable, SharedValueReader
Constructor and Description |
---|
SharedValue(CuratorFramework client,
java.lang.String path,
byte[] seedValue) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
ListenerContainer<SharedValueListener> |
getListenable()
Returns the listenable
|
byte[] |
getValue()
Return the current value of the count
|
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)
Changes the shared value only if its value has not changed since this client last
read it.
|
public SharedValue(CuratorFramework client, java.lang.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 createdpublic byte[] getValue()
SharedValueReader
getValue
in interface SharedValueReader
public void setValue(byte[] newValue) throws java.lang.Exception
newValue
- new valuejava.lang.Exception
- ZK errors, interruptions, etc.public boolean trySetValue(byte[] newValue) throws java.lang.Exception
getValue()
.newValue
- the new value to attemptgetValue()
will return the updated valuejava.lang.Exception
- ZK errors, interruptions, etc.public ListenerContainer<SharedValueListener> getListenable()
getListenable
in interface SharedValueReader
public void start() throws java.lang.Exception
close()
when you are
finished with the shared valuejava.lang.Exception
- ZK errors, interruptions, etc.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException