public class SharedCount extends java.lang.Object implements java.io.Closeable, SharedCountReader, Listenable<SharedCountListener>
| Constructor and Description |
|---|
SharedCount(CuratorFramework client,
java.lang.String path,
int seedValue) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SharedCountListener listener)
Add the given listener.
|
void |
addListener(SharedCountListener listener,
java.util.concurrent.Executor executor)
Add the given listener.
|
void |
close() |
int |
getCount()
Return the current value of the count
|
void |
removeListener(SharedCountListener listener)
Remove the given listener
|
void |
setCount(int newCount)
Change the shared count value irrespective of its previous state
|
void |
start()
The shared count must be started before it can be used.
|
boolean |
trySetCount(int newCount)
Changes the shared count only if its value has not changed since this client last
read it.
|
public SharedCount(CuratorFramework client, java.lang.String path, int seedValue)
client - the clientpath - the shared path - i.e. where the shared count is storedseedValue - the initial value for the count if/f the path has not yet been createdpublic int getCount()
SharedCountReadergetCount in interface SharedCountReaderpublic void setCount(int newCount)
throws java.lang.Exception
newCount - new valuejava.lang.Exception - ZK errors, interruptions, etc.public boolean trySetCount(int newCount)
throws java.lang.Exception
getCount().newCount - the new value to attemptgetCount() will return the updated valuejava.lang.Exception - ZK errors, interruptions, etc.public void addListener(SharedCountListener listener)
ListenableaddListener in interface Listenable<SharedCountListener>listener - listener to addpublic void addListener(SharedCountListener listener, java.util.concurrent.Executor executor)
ListenableaddListener in interface Listenable<SharedCountListener>listener - listener to addexecutor - executor to run listener inpublic void removeListener(SharedCountListener listener)
ListenableremoveListener in interface Listenable<SharedCountListener>listener - listener to removepublic void start()
throws java.lang.Exception
close() when you are
finished with the shared countjava.lang.Exception - ZK errors, interruptions, etc.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException