org.lwes.listener
Class ThreadedProcessor

java.lang.Object
  extended by org.lwes.listener.ThreadedProcessor
All Implemented Interfaces:
java.lang.Runnable

public class ThreadedProcessor
extends java.lang.Object
implements java.lang.Runnable

A threaded, queueing event processor. This class requires setting a class to enqueue events (for example, a network listener) and a class to dequeue events (for example, writing to disk).

Author:
Anthony Molinaro, Michael P. Lum

Constructor Summary
ThreadedProcessor()
          Default constructor.
 
Method Summary
 ThreadedDequeuer getDequeuer()
          Gets the dequeuer being used by this event processor
 int getDequeuerPriority()
          Returns the thread priority of the dequeuer.
 ThreadedEnqueuer getEnqueuer()
          Gets the enqueuer being used by this event processor
 int getEnqueuerPriority()
          Returns the thread priority of the enqueuer.
 java.util.List<QueueElement> getQueue()
          Returns the List being used as the queue
 void initialize()
          Initializes the processor to handle events.
 void run()
          The thread's execution loop.
 void setDequeuer(ThreadedDequeuer dequeuer)
          Sets the dequeuer to use for this event processor.
 void setDequeuerPriority(int priority)
          Sets the thread priority of the dequeuer
 void setEnqueuer(ThreadedEnqueuer enqueuer)
          Sets the enqueuer to use for this event processor.
 void setEnqueuerPriority(int priority)
          Sets the thread priority of the enqueuer.
 void setQueue(java.util.List<QueueElement> queue)
          Sets the List being used as the queue.
 void shutdown()
          Shuts down the event listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadedProcessor

public ThreadedProcessor()
Default constructor.

Method Detail

getEnqueuer

public ThreadedEnqueuer getEnqueuer()
Gets the enqueuer being used by this event processor

Returns:
the ThreadedEnqueuer being used by this processor

setEnqueuer

public void setEnqueuer(ThreadedEnqueuer enqueuer)
Sets the enqueuer to use for this event processor.

Parameters:
enqueuer - the ThreadedEnqueuer to use

getDequeuer

public ThreadedDequeuer getDequeuer()
Gets the dequeuer being used by this event processor

Returns:
the ThreadedDequeuer being used by this processor

setDequeuer

public void setDequeuer(ThreadedDequeuer dequeuer)
Sets the dequeuer to use for this event processor.

Parameters:
dequeuer - the ThreadedDequeuer to use

getQueue

public java.util.List<QueueElement> getQueue()
Returns the List being used as the queue

Returns:
the List object

setQueue

public void setQueue(java.util.List<QueueElement> queue)
Sets the List being used as the queue. Warning: this list needs to be thread-synchronized!

Parameters:
queue - the List to use for this processor

getEnqueuerPriority

public int getEnqueuerPriority()
Returns the thread priority of the enqueuer.

Returns:
the thread priority

setEnqueuerPriority

public void setEnqueuerPriority(int priority)
Sets the thread priority of the enqueuer.

Parameters:
priority - the thread priority to use

getDequeuerPriority

public int getDequeuerPriority()
Returns the thread priority of the dequeuer.

Returns:
the thread priority

setDequeuerPriority

public void setDequeuerPriority(int priority)
Sets the thread priority of the dequeuer

Parameters:
priority - the thread priority to use

initialize

public void initialize()
                throws EventSystemException
Initializes the processor to handle events. Starts the enqueuer and dequeuer threads.

Throws:
EventSystemException - if there is a problem setting up the processor

shutdown

public void shutdown()
Shuts down the event listener. Stops the enqueuer and dequeuer threads.


run

public final void run()
The thread's execution loop. Doesn't do much because the enqueue and dequeue threads do the heavy lifting.

Specified by:
run in interface java.lang.Runnable