|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.concurrent.StateMonitor<T>
public class StateMonitor<T>
Provides a convenient facility for blocking until a state change explicitly occurs. Each time the wrapped state value changes, the blocked threads check to see if the new state meets a provided criteria.
Ideally, this class would extend ConcurrentBox. Unfortunately, the methods of
AtomicReference are final, and so they can't be overridden here.
Also, since locking is necessary when performing thread notification, these implementations simply use
locking, rather than relying on built-in non-blocking atomic primitives.
| Constructor Summary | |
|---|---|
StateMonitor(T state)
|
|
| Method Summary | |
|---|---|
T |
attemptEnsureNotState(T wrong)
Tries to ensure that the state does not equal wrong before continuing. |
T |
attemptEnsureNotState(T expected,
long timeout)
Tries to ensure that the state does not equal wrong before continuing. |
T |
attemptEnsureNotState(T expected,
long timeout,
TimeUnit unit)
Tries to ensure that the state does not equal wrong before continuing. |
T |
attemptEnsurePredicate(Predicate<? super T> predicate)
Tries to ensure that predicate accepts the current state before continuing. |
T |
attemptEnsurePredicate(Predicate<? super T> predicate,
long timeout)
Tries to ensure that predicate accepts the current state before continuing. |
T |
attemptEnsurePredicate(Predicate<? super T> predicate,
long timeout,
TimeUnit unit)
Tries to ensure that predicate accepts the current state before continuing. |
T |
attemptEnsureState(T expected)
Tries to ensure that the state equals expected before continuing. |
T |
attemptEnsureState(T expected,
long timeout)
Tries to ensure that the state equals expected before continuing. |
T |
attemptEnsureState(T expected,
long timeout,
TimeUnit unit)
Tries to ensure that the monitor has been signaled before continuing. |
boolean |
compareAndSet(T expect,
T update)
If the current state is expect, change it to update. |
T |
ensureNotState(T wrong)
Ensures that the state does not equal wrong before continuing. |
T |
ensureNotState(T wrong,
long timeout)
Ensures that the state does not equal wrong before continuing. |
T |
ensureNotState(T wrong,
long timeout,
TimeUnit unit)
Ensures that the state does not equal wrong before continuing. |
T |
ensurePredicate(Predicate<? super T> predicate)
Ensures that predicate accepts the current state before continuing. |
T |
ensurePredicate(Predicate<? super T> predicate,
long timeout)
Ensures that predicate accepts the current state before continuing. |
T |
ensurePredicate(Predicate<? super T> predicate,
long timeout,
TimeUnit unit)
Ensures that predicate accepts the current state before continuing. |
T |
ensureState(T expected)
Ensures that the state equals expected before continuing. |
T |
ensureState(T expected,
long timeout)
Ensures that the state equals expected before continuing. |
T |
ensureState(T expected,
long timeout,
TimeUnit unit)
Ensures that the state equals expected before continuing. |
T |
getAndSet(T newState)
Change the state to newState; return the previous state. |
void |
set(T newState)
Change the state to newState. |
T |
value()
Get the current state. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public StateMonitor(T state)
| Method Detail |
|---|
public T value()
value in interface Thunk<T>public void set(T newState)
newState.
set in interface Box<T>public T getAndSet(T newState)
newState; return the previous state.
AtomicReference.getAndSet(V)
public boolean compareAndSet(T expect,
T update)
expect, change it to update. In this case, true is
returned. Otherwise, give up and return false.
AtomicReference.compareAndSet(V, V)
public T ensureState(T expected)
throws InterruptedException
expected before continuing. Blocks if necessary.
expected).
InterruptedException
public T ensureState(T expected,
long timeout)
throws InterruptedException,
TimeoutException
expected before continuing. Blocks if necessary; fails if the
the timeout is reached.
timeout - Maximum wait time, in milliseconds.
expected).
InterruptedException
TimeoutException
public T ensureState(T expected,
long timeout,
TimeUnit unit)
throws InterruptedException,
TimeoutException
expected before continuing. Blocks if necessary; fails if the
the timeout is reached.
timeout - Maximum wait time, in unit units.unit - Units for timeout.
expected).
InterruptedException
TimeoutExceptionpublic T attemptEnsureState(T expected)
expected before continuing. Blocks if necessary. Stops waiting
if interrupted.
expected).
public T attemptEnsureState(T expected,
long timeout)
expected before continuing. Blocks if necessary. If interrupted
or if the timeout is reached, stops waiting.
timeout - Maximum wait time, in milliseconds.
expected).
public T attemptEnsureState(T expected,
long timeout,
TimeUnit unit)
timeout - Maximum wait time, in unit units.unit - Units for timeout.
expected).
public T ensureNotState(T wrong)
throws InterruptedException
wrong before continuing. Blocks if necessary.
wrong).
InterruptedException
public T ensureNotState(T wrong,
long timeout)
throws InterruptedException,
TimeoutException
wrong before continuing. Blocks if necessary; fails if the
the timeout is reached.
timeout - Maximum wait time, in milliseconds.
expected).
InterruptedException
TimeoutException
public T ensureNotState(T wrong,
long timeout,
TimeUnit unit)
throws InterruptedException,
TimeoutException
wrong before continuing. Blocks if necessary; fails if the
the timeout is reached.
timeout - Maximum wait time, in unit units.unit - Units for timeout.
expected).
InterruptedException
TimeoutExceptionpublic T attemptEnsureNotState(T wrong)
wrong before continuing. Blocks if necessary.
Stops waiting if interrupted.
wrong).
public T attemptEnsureNotState(T expected,
long timeout)
wrong before continuing. Blocks if necessary.
If the wait is interrupted or the timeout is reached, stops waiting.
timeout - Maximum wait time, in milliseconds.
wrong).
public T attemptEnsureNotState(T expected,
long timeout,
TimeUnit unit)
wrong before continuing. Blocks if necessary.
If the wait is interrupted or the timeout is reached, stops waiting.
timeout - Maximum wait time, in unit units.unit - Units for timeout.
wrong).
public T ensurePredicate(Predicate<? super T> predicate)
throws InterruptedException
predicate accepts the current state before continuing. Blocks if necessary.
predicate).
InterruptedException
public T ensurePredicate(Predicate<? super T> predicate,
long timeout)
throws InterruptedException,
TimeoutException
predicate accepts the current state before continuing. Blocks if necessary; fails if the
the timeout is reached.
timeout - Maximum wait time, in milliseconds.
predicate).
InterruptedException
TimeoutException
public T ensurePredicate(Predicate<? super T> predicate,
long timeout,
TimeUnit unit)
throws InterruptedException,
TimeoutException
predicate accepts the current state before continuing. Blocks if necessary; fails if the
the timeout is reached.
timeout - Maximum wait time, in unit units.unit - Units for timeout.
predicate).
InterruptedException
TimeoutExceptionpublic T attemptEnsurePredicate(Predicate<? super T> predicate)
predicate accepts the current state before continuing. Blocks if necessary.
Stops waiting if interrupted.
predicate).
public T attemptEnsurePredicate(Predicate<? super T> predicate,
long timeout)
predicate accepts the current state before continuing. Blocks if necessary.
If the wait is interrupted or the timeout is reached, stops waiting.
timeout - Maximum wait time, in milliseconds.
predicate).
public T attemptEnsurePredicate(Predicate<? super T> predicate,
long timeout,
TimeUnit unit)
predicate accepts the current state before continuing. Blocks if necessary.
If the wait is interrupted or the timeout is reached, stops waiting.
timeout - Maximum wait time, in unit units.unit - Units for timeout.
predicate).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||