org.apache.avalon.excalibur.concurrent
Class ConditionalEvent

java.lang.Object
  |
  +--org.apache.avalon.excalibur.concurrent.ConditionalEvent

public class ConditionalEvent
extends java.lang.Object

This class implements a POSIX style "Event" object. The difference between the ConditionalEvent and the java wait()/notify() technique is in handling of event state. If a ConditionalEvent is signalled, a thread that subsequently waits on it is immediately released. In case of auto reset EventObjects, the object resets (unsignalled) itself as soon as it is signalled and waiting thread(s) are released (based on whether signal() or signalAll() was called).

Since:
4.0
Version:
CVS $Revision: 1.3 $ $Date: 2001/12/11 09:53:27 $
Author:
Karthik Rangaraju

Constructor Summary
ConditionalEvent(boolean initialState)
          Creates a manual reset ConditionalEvent with a specified initial state
ConditionalEvent(boolean initialState, boolean autoReset)
          Creates a ConditionalEvent with the defined initial state
 
Method Summary
 boolean isSignalled()
          Checks if the event is signalled.
 void reset()
          Resets the event to an unsignalled state
 void signal()
          Signals the event.
 void signalAll()
          Current implementation only works with manual reset events.
 void waitForSignal()
          If the event is signalled, this method returns immediately resetting the signal, otherwise it blocks until the event is signalled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConditionalEvent

public ConditionalEvent(boolean initialState)
Creates a manual reset ConditionalEvent with a specified initial state
Parameters:
pInitialState - Sets the initial state of the ConditionalEvent. Signalled if pInitialState is true, unsignalled otherwise.

ConditionalEvent

public ConditionalEvent(boolean initialState,
                        boolean autoReset)
Creates a ConditionalEvent with the defined initial state
Parameters:
pInitialState - if true, the ConditionalEvent is signalled when created.
pAutoReset - if true creates an auto-reset ConditionalEvent
Method Detail

isSignalled

public boolean isSignalled()
Checks if the event is signalled. Does not block on the operation
Returns:
true is event is signalled, false otherwise. Does not reset an autoreset event

signal

public void signal()
Signals the event. A single thread blocked on waitForSignal() is released
See Also:
signalAll(), waitForSignal()

signalAll

public void signalAll()
Current implementation only works with manual reset events. Releases all threads blocked on waitForSignal()
See Also:
waitForSignal()

reset

public void reset()
Resets the event to an unsignalled state

waitForSignal

public void waitForSignal()
                   throws java.lang.InterruptedException
If the event is signalled, this method returns immediately resetting the signal, otherwise it blocks until the event is signalled.
Throws:
java.lang.InterruptedException - if the thread is interrupted when blocked


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.