pt.ua.concurrent
Class Event

java.lang.Object
  extended by pt.ua.concurrent.CObject
      extended by pt.ua.concurrent.Event
All Implemented Interfaces:
InterruptibleAwaitingThreads, SyncCV

public class Event
extends CObject

A simple module supporting two valued events. An event is a double-valued variable (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.

Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
Event(boolean initial)
          Creates an event with initial state and registering waiting threads.
Event(boolean initial, boolean registerAwaitingThreads)
          Creates an event with initial state.
 
Method Summary
 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.
 
Methods inherited from class pt.ua.concurrent.CObject
await, await, await, broadcast, interruptWaitingThreads, lockIsMine, registerAwaitingThreads, signal, syncronizedLockIsMine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Event

public Event(boolean initial)
Creates an event with initial state and registering waiting threads.

Parameters:
initial - state value

Event

public Event(boolean initial,
             boolean registerAwaitingThreads)
Creates an event with initial state.

Parameters:
registerAwaitingThreads - if true, threads are registered when waiting
Method Detail

set

public void set()
Set the event state (true).


reset

public void reset()
Reset the event state (false).


toggle

public void toggle()
Toggle the event state.


stateMatches

public 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).

Returns:
true, if state matches the argument, false otherwise

await

public void await(boolean state)
           throws ThreadInterruptedException
Wait for a given state value.

Parameters:
state - value to wait for
Throws:
ThreadInterruptedException