com.isti.util.queue
Class NotifyEventQueue

java.lang.Object
  extended by com.isti.util.queue.NotifyThread
      extended by com.isti.util.queue.NotifyEventQueue
All Implemented Interfaces:
java.lang.Runnable

public abstract class NotifyEventQueue
extends NotifyThread

Class NotifyEventQueue is a FIFO event queue with notify-thread support. Subclasses need to define a 'run()' method with a processing loop that checks 'finishRunning()' and uses 'waitForEvent()' to retrieve events. See the 'com.isti.util.test.NotifyEvtQueueTest' class for an example usage.


Field Summary
protected  java.util.Vector m_queue
          Fifo event queue implemented with a vector.
 
Fields inherited from class com.isti.util.queue.NotifyThread
m_stateLock
 
Constructor Summary
NotifyEventQueue(java.lang.String idStr)
          Class NotifyEventQueue is a FIFO event queue with notify-thread support.
 
Method Summary
 boolean checkForEvent()
          Waits for the queue to have events.
 boolean checkForEvent(long waitTimeMs)
          Waits for the queue to have events.
 void clearEvents()
          Clears all events from the queue.
 boolean finishRunning()
          Indicates if processing thread should exit.
 void finishWorkAndStopThread()
          Finishes pending work and stops the thread.
 int getQueueSize()
          Indicates if the event queue is empty.
 boolean isEmpty()
          Indicates if the event queue is empty.
 void notifyThread()
          Notifies our event processing thread that the queue has events to process.
 java.lang.Object pullEvent()
          Pulls an event from the queue.
 void pushEvent(java.lang.Object event)
          Pushes an event object into the queue.
 void pushEventBackNoNotify(java.lang.Object event)
          Pushes an event object back into the queue at location 0
 void pushEventNoNotify(java.lang.Object event)
          Pushes an event object into the queue but don't issue any notifications
 void stopThread()
          Stops the thread.
 java.lang.Object waitForEvent()
          Waits for the queue to have events.
 java.lang.Object waitForEvent(long waitTimeMs)
          Waits for the queue to have events.
 int waitForNotify()
          Waits for a thread-notify on the queue.
 int waitForNotify(long waitTimeMs)
          Waits for a thread-notify on the queue, up to the given number of milliseconds.
 
Methods inherited from class com.isti.util.queue.NotifyThread
isRunning, resumeThread, setDaemonThread, setRunning, shouldFinishWork, startThread, suspendThread, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

m_queue

protected java.util.Vector m_queue
Fifo event queue implemented with a vector.

Constructor Detail

NotifyEventQueue

public NotifyEventQueue(java.lang.String idStr)
Class NotifyEventQueue is a FIFO event queue with notify-thread support.

Parameters:
idStr - Identification string for this queue and its processing thread.
Method Detail

pushEvent

public void pushEvent(java.lang.Object event)
Pushes an event object into the queue.

Parameters:
event - the event object to use.

pushEventBackNoNotify

public void pushEventBackNoNotify(java.lang.Object event)
Pushes an event object back into the queue at location 0

Parameters:
event - the event object to use.

pushEventNoNotify

public void pushEventNoNotify(java.lang.Object event)
Pushes an event object into the queue but don't issue any notifications

Parameters:
event - the event object to use.

pullEvent

public java.lang.Object pullEvent()
Pulls an event from the queue. If the queue is empty then this method will return null.

Returns:
the event object, or null if none are available.

getQueueSize

public int getQueueSize()
Indicates if the event queue is empty.

Returns:
the number of event objects in the queue.

isEmpty

public boolean isEmpty()
Indicates if the event queue is empty.

Returns:
true if the queue is empty; false if not.

notifyThread

public void notifyThread()
Notifies our event processing thread that the queue has events to process. Invokes notify() on the queue object.


waitForEvent

public java.lang.Object waitForEvent()
Waits for the queue to have events. Invokes wait() on the queue object if running.

Returns:
Event if available, null otherwise.

waitForEvent

public java.lang.Object waitForEvent(long waitTimeMs)
Waits for the queue to have events. Invokes wait() on the queue object if running.

Parameters:
waitTimeMs - the maximum number of milliseconds to wait for the thread-notify, or 0 to wait indefinitely.
Returns:
Event if available, null otherwise.

waitForNotify

public int waitForNotify(long waitTimeMs)
Waits for a thread-notify on the queue, up to the given number of milliseconds. Invokes wait() on the queue object if running.

Parameters:
waitTimeMs - the maximum number of milliseconds to wait for the thread-notify, or 0 to wait indefinitely.
Returns:
The number of elements in the queue.

waitForNotify

public int waitForNotify()
Waits for a thread-notify on the queue. Invokes wait() on the queue object if running.

Returns:
The number of elements in the queue.

checkForEvent

public boolean checkForEvent()
Waits for the queue to have events. Invokes wait() on the queue object if running.

Returns:
true if the queue is not empty, false if empty..

checkForEvent

public boolean checkForEvent(long waitTimeMs)
Waits for the queue to have events. Invokes wait() on the queue object if running.

Parameters:
waitTimeMs - the maximum number of milliseconds to wait for the thread-notify, or 0 to wait indefinitely.
Returns:
true if the queue is not empty, false if empty..

finishRunning

public boolean finishRunning()
Indicates if processing thread should exit.

Returns:
true if processing thread should exit; false if not.

stopThread

public void stopThread()
Stops the thread.

Overrides:
stopThread in class NotifyThread

finishWorkAndStopThread

public void finishWorkAndStopThread()
Finishes pending work and stops the thread.

Overrides:
finishWorkAndStopThread in class NotifyThread

clearEvents

public void clearEvents()
Clears all events from the queue.