Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.transaction.util
Class TurnBarrier

    java.lang.Object
      org.apache.commons.transaction.util.TurnBarrier

public class TurnBarrier
extends Object

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.

Version:
  $Revision$

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

### DEFAULT_TIMEOUT

    public static final long DEFAULT_TIMEOUT

See Also:
  Constant Field Values

### name

    protected final String name

### currentNumber

    protected int currentNumber

### startNumber

    protected final int startNumber

### timeout

    protected final long timeout

### logger

    protected LoggerFacade logger

Constructor Detail

### TurnBarrier

    public TurnBarrier(String name,
                       LoggerFacade logger)

  Creates a new turn barrier starting with turn 0 with an unlimited timeout.

Parameters:
  `name` - the name of the barrier
  `logger` - logger for debug output

### TurnBarrier

    public TurnBarrier(String name,
                       long timeout,
                       LoggerFacade logger)

  Creates a new turn barrier starting with turn 0.

Parameters:
  `name` - the name of the barrier
  `timeout` - timeout for threads to wait for their turn
  `logger` - logger for debug output

### TurnBarrier

    public TurnBarrier(String name,
                       long timeout,
                       LoggerFacade logger,
                       int startTurn)

  Creates a new turn barrier.

Parameters:
  `name` - the name of the barrier
  `timeout` - timeout for threads to wait for their turn
  `logger` - logger for debug output
  `startTurn` - the turn to start with

Method Detail

### waitForTurn

    public void waitForTurn(int turnNumber)
                     throws InterruptedException,
                            RuntimeException

  Blockingly waits for the given turn. If a timeout occurs a runtime exception will be thrown.

  Parameters:
    `turnNumber` - the turn number to wait for
  Throws:
    `InterruptedException` - thrown if the thread is interrupted while waiting
    `RuntimeException` - thrown when timed out

### signalTurn

    public void signalTurn(int turnNumber)

  Signals the next turn. Any thread waiting for the turn will be allowed to continue.

  Parameters:
    `turnNumber` - the next turn number

### reset

    public void reset()

  Starts the barrier over again. The next turn will be the one the barrier was started with.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004 The Apache Software Foundation. All Rights Reserved.