Interface WaitQueue.Signal
- All Known Implementing Classes:
WaitQueue.Standard.AbstractSignal
- Enclosing interface:
- WaitQueue
A Signal is a one-time-use mechanism for a thread to wait for notification that some condition
state has transitioned that it may be interested in (and hence should check if it is).
It is potentially transient, i.e. the state can change in the meantime, it only indicates
that it should be checked, not necessarily anything about what the expected state should be.
Signal implementations should never wake up spuriously, they are always woken up by a
signal() or signalAll().
This abstract definition of Signal does not need to be tied to a WaitQueue.
Whilst RegisteredSignal is the main building block of Signals, this abstract
definition allows us to compose Signals in useful ways. The Signal is 'owned' by the
thread that registered itself with WaitQueue(s) to obtain the underlying RegisteredSignal(s);
only the owning thread should use a Signal.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Awaitable
Awaitable.AbstractAwaitable, Awaitable.AsyncAwaitable, Awaitable.Defaults, Awaitable.SyncAwaitableNested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Condition
Condition.Async, Condition.Sync -
Method Summary
Modifier and TypeMethodDescriptionawait()Await indefinitely, throwing any interrupt.booleanawaitUntil(long nanoTimeDeadline) Await until the deadline (in nanoTime), throwing any interrupt.voidcancel()Should only be called by the owning thread.booleanatomically: cancels the Signal if !isSet(), or returns true if isSet()booleanbooleanisSet()Methods inherited from interface org.apache.cassandra.utils.concurrent.Awaitable
await, awaitThrowUncheckedOnInterrupt, awaitThrowUncheckedOnInterrupt, awaitUninterruptibly, awaitUninterruptibly, awaitUntilThrowUncheckedOnInterrupt, awaitUntilUninterruptiblyMethods inherited from interface org.apache.cassandra.utils.concurrent.Condition
isSignalled, signal, signalAll
-
Method Details
-
isCancelled
boolean isCancelled()- Returns:
- true if cancelled; once cancelled, must be discarded by the owning thread.
-
isSet
boolean isSet()- Returns:
- isSignalled() || isCancelled(). Once true, the state is fixed and the Signal should be discarded by the owning thread.
-
checkAndClear
boolean checkAndClear()atomically: cancels the Signal if !isSet(), or returns true if isSet()- Returns:
- true if isSet()
-
cancel
void cancel()Should only be called by the owning thread. Indicates the signal can be retired, and if signalled propagates the signal to another waiting thread -
await
Await indefinitely, throwing any interrupt. No spurious wakeups. Important: the signal can be cancelled if the thread executing await() is interrupted- Specified by:
awaitin interfaceAwaitable- Throws:
InterruptedException- if interrupted
-
awaitUntil
Await until the deadline (in nanoTime), throwing any interrupt. No spurious wakeups.- Specified by:
awaitUntilin interfaceAwaitable- Returns:
- true if we were signalled, false if the deadline elapsed Important: the signal can be cancelled if the thread executing await() is interrupted
- Throws:
InterruptedException- if interrupted
-