scorej
Class SignalProcessor

java.lang.Object
  |
  +--scorej.SignalProcessor
All Implemented Interfaces:
java.lang.Runnable

public final class SignalProcessor
extends java.lang.Object
implements java.lang.Runnable

A signal broker class that matches incoming Signals with SignalWaits and notifies the appropriate SignalWait objects whenever there is a match. The operation of the SignalProcessor is partially controlled by the OmarClock. SignalProcessor is a singleton class, there can only be one instance in a JVM.

See Also:
OmarClock, SimulationClock, NonSimulationClock

Method Summary
 void flushSignalQueueUnsafe()
          Clear the signal queue.
 void flushSignalWaitQueueUnsafe()
          Clear the signal wait queue.
 boolean processFirstSignal(boolean flushSignal)
          Process the first signal in the queue.
 boolean processSignal(Signal signal)
          Process a signal.
 void reset()
          Resets the signal processor by flushing the signal queue and signal wait queue.
 void run()
          Starts the signal processor in an infinite loop in which it matches incoming signals with waits and notifies the waits upon a match.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

flushSignalQueueUnsafe

public void flushSignalQueueUnsafe()
Clear the signal queue. Note that it does not lock the signal queue. Locking (and unlocking of signal queue) needs to be done externally.


flushSignalWaitQueueUnsafe

public void flushSignalWaitQueueUnsafe()
Clear the signal wait queue. Note that it does not lock the signal queue. Locking (and unlocking of signal queue) needs to be done externally.


reset

public void reset()
           throws java.lang.InterruptedException
Resets the signal processor by flushing the signal queue and signal wait queue.

java.lang.InterruptedException

run

public void run()
Starts the signal processor in an infinite loop in which it matches incoming signals with waits and notifies the waits upon a match. This run method is executed in a new Thread by the SimulationClock (@link scorej.SimulationClock).

Specified by:
run in interface java.lang.Runnable

processFirstSignal

public boolean processFirstSignal(boolean flushSignal)
Process the first signal in the queue. See processSignal

Parameters:
flushSignal - boolean: true = remove the signal after processing it false = do not remove signal (signal must be cleaned out by a flush later)
Returns:
boolean: true = signal existed and was processed false = no signal exists

processSignal

public boolean processSignal(Signal signal)
Process a signal. Processing involves walking through the SignalWait list, and trying to match the Signal to the SignalWaits. If a SignalWait object gets matched, it is removed.

Returns:
boolean true if all the SignalWaits were tried as a match, false if we got interrupted waiting for the lock