public class TurnBarrier extends Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
currentNumber |
static long |
DEFAULT_TIMEOUT |
protected LoggerFacade |
logger |
protected String |
name |
protected int |
startNumber |
protected long |
timeout |
| Constructor and Description |
|---|
TurnBarrier(String name,
LoggerFacade logger)
Creates a new turn barrier starting with turn 0 with an unlimited timeout.
|
TurnBarrier(String name,
long timeout,
LoggerFacade logger)
Creates a new turn barrier starting with turn 0.
|
TurnBarrier(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 int currentNumber
protected final int startNumber
protected final long timeout
protected LoggerFacade logger
public TurnBarrier(String name, LoggerFacade logger)
name - the name of the barrierlogger - logger for debug outputpublic TurnBarrier(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(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 InterruptedException, RuntimeException
turnNumber - the turn number to wait forInterruptedException - thrown if the thread is interrupted while waitingRuntimeException - thrown when timed outpublic void signalTurn(int turnNumber)
turnNumber - the next turn numberpublic void reset()
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.