public class DistributedDoubleBarrier
extends java.lang.Object
A double barrier as described in the ZK recipes. Quoting the recipe:
Double barriers enable clients to synchronize the beginning and the end of a computation. When enough processes have joined the barrier, processes start their computation and leave the barrier once they have finished.
Constructor and Description |
---|
DistributedDoubleBarrier(CuratorFramework client,
java.lang.String barrierPath,
int memberQty)
Creates the barrier abstraction.
|
Modifier and Type | Method and Description |
---|---|
void |
enter()
Enter the barrier and block until all members have entered
|
boolean |
enter(long maxWait,
java.util.concurrent.TimeUnit unit)
Enter the barrier and block until all members have entered or the timeout has
elapsed
|
protected java.util.List<java.lang.String> |
getChildrenForEntering() |
void |
leave()
Leave the barrier and block until all members have left
|
boolean |
leave(long maxWait,
java.util.concurrent.TimeUnit unit)
Leave the barrier and block until all members have left or the timeout has
elapsed
|
public DistributedDoubleBarrier(CuratorFramework client, java.lang.String barrierPath, int memberQty)
memberQty
is the number of members in the
barrier. When enter()
is called, it blocks until all members have entered. When
leave()
is called, it blocks until all members have left.client
- the clientbarrierPath
- path to usememberQty
- the number of members in the barrier. NOTE: more than memberQty
can enter the barrier. memberQty
is a threshold, not a limitpublic void enter() throws java.lang.Exception
java.lang.Exception
- interruptions, errors, etc.public boolean enter(long maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
maxWait
- max time to blockunit
- time unitjava.lang.Exception
- interruptions, errors, etc.public void leave() throws java.lang.Exception
java.lang.Exception
- interruptions, errors, etc.public boolean leave(long maxWait, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
maxWait
- max time to blockunit
- time unitjava.lang.Exception
- interruptions, errors, etc.protected java.util.List<java.lang.String> getChildrenForEntering() throws java.lang.Exception
java.lang.Exception