-
Notifications
You must be signed in to change notification settings - Fork 434
Shared counter
Randgalt edited this page Nov 17, 2011
·
5 revisions
Manages a shared integer. All clients watching the same path will have the up-to-date value of the shared integer (considering ZK's normal consistency guarantees).
- SharedCount
- SharedCountReader
- SharedCountListener
public SharedCount(CuratorFramework client,
String path,
int seedValue)
Parameters:
client - the client
path - the shared path - i.e. where the shared count is stored
seedValue - the initial value for the count if/f the path has not yet been created
SharedCounts must be started:
count.start();
When you are through with the instance, you should call close:
count.close();
int getCount()
Return the current value of the count
void addListener(SharedCountListener listener)
Add a listener for changes to the count
public void setCount(int newCount)
Change the shared count value irrespective of its previous state
public boolean trySetCount(int newCount)
Changes the shared count only if its value has not changed since this client last read it. If the count
has changed, the value is not set and this client's view of the value is updated. i.e. if the count is
not successful you can get the updated value by calling getCount().
Parameters:
newCount - the new value to attempt
Returns:
true if the change attempt was successful, false if not. If the change was not successful, getCount()
will return the updated value
The SharedCountListener
class extends ConnectionStateListener
. When the SharedCount is started, it adds the listener to the Curator instance. Users of the SharedCount
must pay attention to any connection state changes.
If the SUSPENDED state is reported, the instance must assume that, until it receives a RECONNECTED state, the count is no longer accurate and isn't being updated. If the LOST state is reported, the count is permanently down.
- Curator
- Javadoc
- Coverage Report
- Getting Started
- Examples
- FAQ
- Client
- Framework
-
Recipes
- Leader Latch
- Leader Election
- Shared Reentrant Lock
- Shared Lock
- Shared Reentrant Read Write Lock
- Shared Semaphore
- Multi Shared Lock
- Distributed Queue
- Distributed Id Queue
- Distributed Priority Queue
- Distributed Delay Queue
- Simple Distributed Queue
- Barrier
- Double Barrier
- Shared counter
- Distributed Atomic Long
- Path Cache
- Node Cache
- Utilities – Test Server, Test Cluster, ZKPaths, EnsurePath, QueueSharder, Reaper, ChildReaper
- Tech Notes
- Errors
- Exhibitor Integration
- Extensions
- Logging and Tracing