public class Event extends CObject
0
and 1
),
in which a client may wait for one of this two states.
This class follows DbC(tm) methodology
(Wikipedia).
Where possible, contracts are implement with native's Java
assert.
Constructor and Description |
---|
Event(boolean initial)
Creates an event with initial state and registering waiting threads.
|
Event(boolean initial,
boolean registerAwaitingThreads)
Creates an event with initial state.
|
Modifier and Type | Method and Description |
---|---|
void |
await(boolean state)
Wait for a given state value.
|
void |
reset()
Reset the event state (false).
|
void |
set()
Set the event state (true).
|
boolean |
stateMatches(boolean state)
Does current state matches argument?
This method should be used with utmost care, because its result,
depending on the event's usage, might change immediately after
it has been called (race condition).
|
void |
toggle()
Toggle the event state.
|
await, await, await, broadcast, interruptWaitingThreads, lockIsMine, registerAwaitingThreads, signal, syncronizedLockIsMine
public Event(boolean initial)
initial
- state valuepublic Event(boolean initial, boolean registerAwaitingThreads)
initial
- the initial stateregisterAwaitingThreads
- if true, threads are registered when waitingpublic void set()
public void reset()
public void toggle()
public boolean stateMatches(boolean state)
state
- the state to testpublic void await(boolean state) throws ThreadInterruptedException
state
- value to wait forThreadInterruptedException