org.compass.core.util.backport.java.util.concurrent.locks
Class FIFOCondVar

java.lang.Object
  extended by org.compass.core.util.backport.java.util.concurrent.locks.CondVar
      extended by org.compass.core.util.backport.java.util.concurrent.locks.FIFOCondVar
All Implemented Interfaces:
Serializable, Condition

 class FIFOCondVar
extends CondVar
implements Condition, Serializable


Nested Class Summary
 
Nested classes/interfaces inherited from class org.compass.core.util.backport.java.util.concurrent.locks.CondVar
CondVar.ExclusiveLock
 
Field Summary
 
Fields inherited from class org.compass.core.util.backport.java.util.concurrent.locks.CondVar
lock
 
Constructor Summary
FIFOCondVar(CondVar.ExclusiveLock lock)
          Create a new CondVar that relies on the given mutual exclusion lock.
 
Method Summary
 void await()
          Causes the current thread to wait until it is signalled or interrupted.
 boolean await(long timeout, TimeUnit unit)
          Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses.
 void awaitUninterruptibly()
          Causes the current thread to wait until it is signalled.
 boolean awaitUntil(Date deadline)
          Causes the current thread to wait until it is signalled or interrupted, or the specified deadline elapses.
protected  Collection getWaitingThreads()
           
protected  int getWaitQueueLength()
           
protected  boolean hasWaiters()
           
 void signal()
          Wakes up one waiting thread.
 void signalAll()
          Wakes up all waiting threads.
 
Methods inherited from class org.compass.core.util.backport.java.util.concurrent.locks.CondVar
getLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FIFOCondVar

FIFOCondVar(CondVar.ExclusiveLock lock)
Create a new CondVar that relies on the given mutual exclusion lock.

Parameters:
lock - A non-reentrant mutual exclusion lock.
Method Detail

awaitUninterruptibly

public void awaitUninterruptibly()
Description copied from interface: Condition
Causes the current thread to wait until it is signalled.

The lock associated with this condition is atomically released and the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:

In all cases, before this method can return the current thread must re-acquire the lock associated with this condition. When the thread returns it is guaranteed to hold this lock.

If the current thread's interrupted status is set when it enters this method, or it is interrupted while waiting, it will continue to wait until signalled. When it finally returns from this method its interrupted status will still be set.

Implementation Considerations

The current thread is assumed to hold the lock associated with this Condition when this method is called. It is up to the implementation to determine if this is the case and if not, how to respond. Typically, an exception will be thrown (such as IllegalMonitorStateException) and the implementation must document that fact.

Specified by:
awaitUninterruptibly in interface Condition
Overrides:
awaitUninterruptibly in class CondVar

await

public void await()
           throws InterruptedException
Description copied from interface: Condition
Causes the current thread to wait until it is signalled or interrupted.

The lock associated with this Condition is atomically released and the current thread becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:

In all cases, before this method can return the current thread must re-acquire the lock associated with this condition. When the thread returns it is guaranteed to hold this lock.

If the current thread:

then InterruptedException is thrown and the current thread's interrupted status is cleared. It is not specified, in the first case, whether or not the test for interruption occurs before the lock is released.

Implementation Considerations

The current thread is assumed to hold the lock associated with this Condition when this method is called. It is up to the implementation to determine if this is the case and if not, how to respond. Typically, an exception will be thrown (such as IllegalMonitorStateException) and the implementation must document that fact.

An implementation can favor responding to an interrupt over normal method return in response to a signal. In that case the implementation must ensure that the signal is redirected to another waiting thread, if there is one.

Specified by:
await in interface Condition
Overrides:
await in class CondVar
Throws:
InterruptedException - if the current thread is interrupted (and interruption of thread suspension is supported)

await

public boolean await(long timeout,
                     TimeUnit unit)
              throws InterruptedException
Description copied from interface: Condition
Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses. This method is behaviorally equivalent to:
   awaitNanos(unit.toNanos(time)) > 0
 

Specified by:
await in interface Condition
Overrides:
await in class CondVar
Parameters:
timeout - the maximum time to wait
unit - the time unit of the time argument
Returns:
false if the waiting time detectably elapsed before return from the method, else true
Throws:
InterruptedException - if the current thread is interrupted (and interruption of thread suspension is supported)

awaitUntil

public boolean awaitUntil(Date deadline)
                   throws InterruptedException
Description copied from interface: Condition
Causes the current thread to wait until it is signalled or interrupted, or the specified deadline elapses.

The lock associated with this condition is atomically released and the current thread becomes disabled for thread scheduling purposes and lies dormant until one of five things happens:

In all cases, before this method can return the current thread must re-acquire the lock associated with this condition. When the thread returns it is guaranteed to hold this lock.

If the current thread:

then InterruptedException is thrown and the current thread's interrupted status is cleared. It is not specified, in the first case, whether or not the test for interruption occurs before the lock is released.

The return value indicates whether the deadline has elapsed, which can be used as follows:

 synchronized boolean aMethod(Date deadline) {
   boolean stillWaiting = true;
   while (!conditionBeingWaitedFor) {
     if (stillWaiting)
         stillWaiting = theCondition.awaitUntil(deadline);
      else
        return false;
   }
   // ...
 }
 

Implementation Considerations

The current thread is assumed to hold the lock associated with this Condition when this method is called. It is up to the implementation to determine if this is the case and if not, how to respond. Typically, an exception will be thrown (such as IllegalMonitorStateException) and the implementation must document that fact.

An implementation can favor responding to an interrupt over normal method return in response to a signal, or over indicating the passing of the specified deadline. In either case the implementation must ensure that the signal is redirected to another waiting thread, if there is one.

Specified by:
awaitUntil in interface Condition
Overrides:
awaitUntil in class CondVar
Parameters:
deadline - the absolute time to wait until
Returns:
false if the deadline has elapsed upon return, else true
Throws:
InterruptedException - if the current thread is interrupted (and interruption of thread suspension is supported)

signal

public void signal()
Description copied from interface: Condition
Wakes up one waiting thread.

If any threads are waiting on this condition then one is selected for waking up. That thread must then re-acquire the lock before returning from await.

Specified by:
signal in interface Condition
Overrides:
signal in class CondVar

signalAll

public void signalAll()
Description copied from interface: Condition
Wakes up all waiting threads.

If any threads are waiting on this condition then they are all woken up. Each thread must re-acquire the lock before it can return from await.

Specified by:
signalAll in interface Condition
Overrides:
signalAll in class CondVar

hasWaiters

protected boolean hasWaiters()
Overrides:
hasWaiters in class CondVar

getWaitQueueLength

protected int getWaitQueueLength()
Overrides:
getWaitQueueLength in class CondVar

getWaitingThreads

protected Collection getWaitingThreads()
Overrides:
getWaitingThreads in class CondVar


Copyright (c) 2004-2006 The Compass Project.