org.terracotta.toolkit.concurrent
Interface ToolkitBarrier

All Superinterfaces:
Destroyable, ToolkitObject

public interface ToolkitBarrier
extends Destroyable, ToolkitObject

A toolkit barrier that can be used to coordinate between threads in the toolkit implementation platform. Similar to CyclicBarrier in nature.

Consult the Toolkit class level docs for more info on behavior regarding destroy.


Method Summary
 int await()
          Waits until all parties have invoked await on this barrier.
 int await(long timeout, TimeUnit unit)
          Waits until all parties have invoked await on this barrier, or the specified waiting time elapses.
 int getParties()
          Returns the number of parties required to trip this barrier.
 boolean isBroken()
          Queries if this barrier is in a broken state.
 void reset()
          Reset to initial state.
 
Methods inherited from interface org.terracotta.toolkit.object.Destroyable
destroy, isDestroyed
 
Methods inherited from interface org.terracotta.toolkit.object.ToolkitObject
getName
 

Method Detail

getParties

int getParties()
Returns the number of parties required to trip this barrier.

Returns:
the number of parties required to trip this barrier

isBroken

boolean isBroken()
Queries if this barrier is in a broken state.

Returns:
true if one or more parties broke out of this barrier due to interruption or timeout since construction or the last reset, or a barrier action failed due to an exception; false otherwise.

await

int await()
          throws InterruptedException,
                 BrokenBarrierException
Waits until all parties have invoked await on this barrier.

Returns:
the arrival index of the current thread, where index getParties() - 1 indicates the first to arrive and zero indicates the last to arrive
Throws:
InterruptedException - if the current thread was interrupted while waiting
BrokenBarrierException - if another thread was interrupted or timed out while the current thread was waiting, or the barrier was reset, or the barrier was broken when await was called, or the barrier action (if present) failed due an exception.

await

int await(long timeout,
          TimeUnit unit)
          throws InterruptedException,
                 TimeoutException,
                 BrokenBarrierException
Waits until all parties have invoked await on this barrier, or the specified waiting time elapses.

Parameters:
timeout - the time to wait for the barrier
unit - the time unit of the timeout parameter
Returns:
the arrival index of the current thread, where index getParties() - 1 indicates the first to arrive and zero indicates the last to arrive
Throws:
InterruptedException - if the current thread was interrupted while waiting
TimeoutException - if the specified timeout elapses
BrokenBarrierException - if another thread was interrupted or timed out while the current thread was waiting, or the barrier was reset, or the barrier was broken when await was called, or the barrier action (if present) failed due an exception

reset

void reset()
Reset to initial state. Clears both the broken status and any record of waiting threads, and releases all currently waiting threads with indeterminate return status. This method is intended only for use in recovery actions in which it is somehow known that no thread could possibly be relying on the the synchronization properties of this barrier.



Copyright © 2014 Terracotta, Inc.. All Rights Reserved.