public class TurnBarrier
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
currentNumber |
static long |
DEFAULT_TIMEOUT |
protected LoggerFacade |
logger |
protected java.lang.String |
name |
protected int |
startNumber |
protected long |
timeout |
| Constructor and Description |
|---|
TurnBarrier(java.lang.String name,
LoggerFacade logger)
Creates a new turn barrier starting with turn 0 with an unlimited timeout.
|
TurnBarrier(java.lang.String name,
long timeout,
LoggerFacade logger)
Creates a new turn barrier starting with turn 0.
|
TurnBarrier(java.lang.String name,
long timeout,
LoggerFacade logger,
int startTurn)
Creates a new turn barrier.
|
| Modifier and Type | Method and Description |
|---|---|
void |
reset()
Starts the barrier over again.
|
void |
signalTurn(int turnNumber)
Signals the next turn.
|
void |
waitForTurn(int turnNumber)
Blockingly waits for the given turn.
|
public static final long DEFAULT_TIMEOUT
protected final java.lang.String name
protected int currentNumber
protected final int startNumber
protected final long timeout
protected LoggerFacade logger
public TurnBarrier(java.lang.String name,
LoggerFacade logger)
name - the name of the barrierlogger - logger for debug outputpublic TurnBarrier(java.lang.String name,
long timeout,
LoggerFacade logger)
name - the name of the barriertimeout - timeout for threads to wait for their turnlogger - logger for debug outputpublic TurnBarrier(java.lang.String name,
long timeout,
LoggerFacade logger,
int startTurn)
name - the name of the barriertimeout - timeout for threads to wait for their turnlogger - logger for debug outputstartTurn - the turn to start withpublic void waitForTurn(int turnNumber)
throws java.lang.InterruptedException,
java.lang.RuntimeException
turnNumber - the turn number to wait forjava.lang.InterruptedException - thrown if the thread is interrupted while waitingjava.lang.RuntimeException - thrown when timed outpublic void signalTurn(int turnNumber)
turnNumber - the next turn numberpublic void reset()
Copyright ? 2004 The Apache Software Foundation. All Rights Reserved.