java.io.Closeable, java.lang.AutoCloseable, org.apache.curator.framework.listen.Listenable<SharedCountListener>, SharedCountReaderpublic class SharedCount extends java.lang.Object implements java.io.Closeable, SharedCountReader, org.apache.curator.framework.listen.Listenable<SharedCountListener>
| Modifier | Constructor | Description |
|---|---|---|
|
SharedCount(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
int seedValue) |
|
protected |
SharedCount(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
SharedValue sv) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addListener(SharedCountListener listener) |
|
void |
addListener(SharedCountListener listener,
java.util.concurrent.Executor executor) |
|
void |
close() |
|
int |
getCount() |
Return the current value of the count
|
VersionedValue<java.lang.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<java.lang.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,
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 createdprotected SharedCount(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
SharedValue sv)
public int getCount()
SharedCountReadergetCount in interface SharedCountReaderpublic VersionedValue<java.lang.Integer> getVersionedValue()
SharedCountReadergetVersionedValue in interface SharedCountReaderpublic void setCount(int newCount)
throws java.lang.Exception
newCount - new valuejava.lang.Exception - ZK errors, interruptions, etc.@Deprecated
public boolean trySetCount(int newCount)
throws java.lang.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 valuejava.lang.Exception - ZK errors, interruptions, etc.public boolean trySetCount(VersionedValue<java.lang.Integer> previous, 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)
addListener in interface org.apache.curator.framework.listen.Listenable<SharedCountListener>public void addListener(SharedCountListener listener, java.util.concurrent.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 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.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.