|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.transaction.util.TurnBarrier
Simple turn based barrier to make a sequence of calls from different threads deterministic. This is very useful for testing where you want to have a contious flow throughout different threads. The idea is to have an ordered sequence of steps where step n can not be executed before n-1.
| Field Summary | |
protected int |
currentNumber
|
static long |
DEFAULT_TIMEOUT
|
protected LoggerFacade |
logger
|
protected String |
name
|
protected int |
startNumber
|
protected long |
timeout
|
| Constructor Summary | |
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. |
|
| Method Summary | |
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final long DEFAULT_TIMEOUT
protected final String name
protected int currentNumber
protected final int startNumber
protected final long timeout
protected LoggerFacade logger
| Constructor Detail |
public TurnBarrier(String name,
LoggerFacade logger)
name - the name of the barrierlogger - logger for debug output
public TurnBarrier(String name,
long timeout,
LoggerFacade logger)
name - the name of the barriertimeout - timeout for threads to wait for their turnlogger - logger for debug output
public 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 with| Method Detail |
public void waitForTurn(int turnNumber)
throws InterruptedException,
RuntimeException
turnNumber - the turn number to wait for
InterruptedException - thrown if the thread is interrupted while waiting
RuntimeException - thrown when timed outpublic void signalTurn(int turnNumber)
turnNumber - the next turn numberpublic void reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||