app.util
Class OneShotTimeoutBarrier

java.lang.Object
  extended by app.util.OneShotTimeoutBarrier

public final class OneShotTimeoutBarrier
extends java.lang.Object

A OneShotTimeoutBarrier, like a Token, is a form of binary semaphore, but with two differences: (a) the passWhenOpen(long)/P() operation has a timeout, and (b) it is "one-shot" in that the passWhenOpen(long) method should be called by a single thread on a single occasion only.


Method Summary
static OneShotTimeoutBarrier newBarrier()
          Creates and returns a new one-shot barrier.
 void open()
          Opens this barrier provided it has not already timed out; if a thread is currently blocked on passWhenOpen(long), that thread will be unblocked as a result.
 boolean passWhenOpen(long timeout)
          Acquires the permission to proceed represented by this barrier, blocking if necessary until it is opened by another thread or until the specified timeout has elapsed (more or less), and returns true if and only if the barrier is open.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newBarrier

public static final OneShotTimeoutBarrier newBarrier()
Creates and returns a new one-shot barrier.


passWhenOpen

public final boolean passWhenOpen(long timeout)
                           throws java.lang.InterruptedException
Acquires the permission to proceed represented by this barrier, blocking if necessary until it is opened by another thread or until the specified timeout has elapsed (more or less), and returns true if and only if the barrier is open.

Throws:
java.lang.InterruptedException

open

public final void open()
Opens this barrier provided it has not already timed out; if a thread is currently blocked on passWhenOpen(long), that thread will be unblocked as a result.