edu.rice.cs.plt.concurrent
Class ConditionMonitor

java.lang.Object
  extended by edu.rice.cs.plt.concurrent.ConditionMonitor
All Implemented Interfaces:
Condition

public class ConditionMonitor
extends java.lang.Object
implements Condition

Provides a convenient facility for blocking until an arbitrary condition is satisfied. Each time check() is invoked, the blocked threads check to see if the condition has become true. Note that there is no way for this to occur "automatically" — the only way the monitor can be made aware of a possible change is by an explicit call to check().


Constructor Summary
ConditionMonitor(Condition condition)
          Create an unsignaled completion monitor.
 
Method Summary
 boolean attemptEnsureTrue()
          Tries to ensure that the condition is true before continuing.
 boolean attemptEnsureTrue(long timeout)
          Tries to ensure that the monitor has been signaled before continuing.
 boolean attemptEnsureTrue(long timeout, java.util.concurrent.TimeUnit unit)
          Tries to ensure that the monitor has been signaled before continuing.
 void check()
          Check the condition and, if it is now true, notify all blocked threads.
 void ensureTrue()
          Ensures that the condition is true before continuing.
 void ensureTrue(long timeout)
          Ensures that the condition is true before continuing.
 void ensureTrue(long timeout, java.util.concurrent.TimeUnit unit)
          Ensures that the condition is true before continuing.
 boolean isTrue()
          Returns whether the flag is currently set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConditionMonitor

public ConditionMonitor(Condition condition)
Create an unsignaled completion monitor.

Method Detail

isTrue

public boolean isTrue()
Returns whether the flag is currently set

Specified by:
isTrue in interface Condition

check

public void check()
Check the condition and, if it is now true, notify all blocked threads.


ensureTrue

public void ensureTrue()
                throws java.lang.InterruptedException
Ensures that the condition is true before continuing. Blocks if necessary.

Throws:
java.lang.InterruptedException

ensureTrue

public void ensureTrue(long timeout)
                throws java.lang.InterruptedException,
                       java.util.concurrent.TimeoutException
Ensures that the condition is true before continuing. Blocks if necessary; fails if the the timeout is reached.

Parameters:
timeout - Maximum wait time, in milliseconds.
Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException

ensureTrue

public void ensureTrue(long timeout,
                       java.util.concurrent.TimeUnit unit)
                throws java.lang.InterruptedException,
                       java.util.concurrent.TimeoutException
Ensures that the condition is true before continuing. Blocks if necessary; fails if the the timeout is reached.

Parameters:
timeout - Maximum wait time, in unit units.
unit - Units for timeout.
Throws:
java.lang.InterruptedException
java.util.concurrent.TimeoutException

attemptEnsureTrue

public boolean attemptEnsureTrue()
Tries to ensure that the condition is true before continuing. Blocks if necessary. If the wait is interrupted, returns false.


attemptEnsureTrue

public boolean attemptEnsureTrue(long timeout)
Tries to ensure that the monitor has been signaled before continuing. Blocks if necessary. If the wait is interrupted or the timeout is reached, returns false.

Parameters:
timeout - Maximum wait time, in milliseconds.

attemptEnsureTrue

public boolean attemptEnsureTrue(long timeout,
                                 java.util.concurrent.TimeUnit unit)
Tries to ensure that the monitor has been signaled before continuing. Blocks if necessary. If the wait is interrupted or the timeout is reached, returns false.

Parameters:
timeout - Maximum wait time, in unit units.
unit - Units for timeout.