public class SharedCount extends Object implements Closeable, SharedCountReader, org.apache.curator.framework.listen.Listenable<SharedCountListener>
| Constructor and Description |
|---|
SharedCount(org.apache.curator.framework.CuratorFramework client,
String path,
int seedValue) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(SharedCountListener listener) |
void |
addListener(SharedCountListener listener,
Executor executor) |
void |
close() |
int |
getCount()
Return the current value of the count
|
VersionedValue<Integer> |
getVersionedValue()
Return the current count and version
|
void |
removeListener(SharedCountListener 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)
Deprecated.
use
trySetCount(VersionedValue, int) 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 count. |
boolean |
trySetCount(VersionedValue<Integer> previous,
int newCount)
Changes the shared count only if its value has not changed since the version specified by
newCount.
|
public SharedCount(org.apache.curator.framework.CuratorFramework client,
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 VersionedValue<Integer> getVersionedValue()
SharedCountReadergetVersionedValue in interface SharedCountReaderpublic void setCount(int newCount)
throws Exception
newCount - new valueException - ZK errors, interruptions, etc.@Deprecated public boolean trySetCount(int newCount) throws Exception
trySetCount(VersionedValue, int) 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 count.getCount().newCount - the new value to attemptgetCount() will return the updated valueException - ZK errors, interruptions, etc.public boolean trySetCount(VersionedValue<Integer> previous, int newCount) throws Exception
getCount().newCount - the new value to attemptgetCount() will return the updated valueException - ZK errors, interruptions, etc.public void addListener(SharedCountListener listener)
addListener in interface org.apache.curator.framework.listen.Listenable<SharedCountListener>public void addListener(SharedCountListener listener, Executor executor)
addListener in interface org.apache.curator.framework.listen.Listenable<SharedCountListener>public void removeListener(SharedCountListener listener)
removeListener in interface org.apache.curator.framework.listen.Listenable<SharedCountListener>public void start()
throws Exception
close() when you are
finished with the shared countException - ZK errors, interruptions, etc.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.