org.lwes.listener
Class ThreadedDequeuer

java.lang.Object
  extended by org.lwes.listener.ThreadedDequeuer
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
DatagramDequeuer

public abstract class ThreadedDequeuer
extends java.lang.Object
implements java.lang.Runnable

An abstract consumer of events.

Author:
Michael P. Lum

Field Summary
protected  java.util.List<QueueElement> queue
           
 
Constructor Summary
ThreadedDequeuer()
          Default constructor.
 
Method Summary
 void addHandler(EventHandler handler)
          Add an event handler to this dequeuer.
 void addHandler(java.lang.String name, EventHandler handler)
          Adds a handler to this dequeuer with a specified name.
protected  void dispatchEvent(Event event)
          Handles events and calls EventHandler handlers.
 EventHandler getHandler(java.lang.String name)
          Get an event handler by name.
protected  ThreadedEventDispatcher getIdleProcessor()
          Gets an idle processor from the list
 int getMaxThreads()
          Gets the maximum number of threads allowed in the system
 java.util.List<QueueElement> getQueue()
          Returns the queue to use for this dequeuer
 void initialize()
          Default initialize() method.
 void makeAvailable(ThreadedEventDispatcher dispatcher)
          Makes a process available for dispatch
 void removeHandler(EventHandler handler)
          Removes a handler so it no longer is processing events
 void removeHandler(java.lang.String name)
          Removes a handler by name so it no longer is processing events
 void run()
          Default run loop.
 void setMaxThreads(int threads)
          Sets the maximum number of threads allowed in the system, up to 64.
 void setQueue(java.util.List<QueueElement> queue)
          Sets the queue to use for this dequeuer.
 void shutdown()
          Default shutdown() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queue

protected java.util.List<QueueElement> queue
Constructor Detail

ThreadedDequeuer

public ThreadedDequeuer()
Default constructor.

Method Detail

getQueue

public java.util.List<QueueElement> getQueue()
Returns the queue to use for this dequeuer

Returns:
the List queue

setQueue

public void setQueue(java.util.List<QueueElement> queue)
Sets the queue to use for this dequeuer. Warning: this List must be thread-synchronized!

Parameters:
queue - the thread-synchronized List element

getMaxThreads

public int getMaxThreads()
Gets the maximum number of threads allowed in the system

Returns:
the number of threads

setMaxThreads

public void setMaxThreads(int threads)
Sets the maximum number of threads allowed in the system, up to 64. The default is 20.

Parameters:
threads - the number of threads to allow.

getHandler

public EventHandler getHandler(java.lang.String name)
Get an event handler by name. Returns null if the handler does not exist.

Parameters:
name - the name of the event handler to fetch
Returns:
the EventHandler

addHandler

public void addHandler(EventHandler handler)
Add an event handler to this dequeuer. Events coming into the system will call all handlers via their callback.

Parameters:
handler - the actual handler

addHandler

public void addHandler(java.lang.String name,
                       EventHandler handler)
Adds a handler to this dequeuer with a specified name. Events coming into the system will call all handlers via their callback.

Parameters:
name - the name of this handler
handler - the actual handler

removeHandler

public void removeHandler(EventHandler handler)
Removes a handler so it no longer is processing events

Parameters:
handler - the handler to remove

removeHandler

public void removeHandler(java.lang.String name)
Removes a handler by name so it no longer is processing events

Parameters:
name - the name of the handler to remove

initialize

public void initialize()
                throws java.io.IOException
Default initialize() method. Should be overridden by classes extending ThreadedEnqueuer.

Throws:
java.io.IOException

shutdown

public void shutdown()
Default shutdown() method. Should be overridden by classes extending ThreadedDequeuer.


run

public void run()
Default run loop. Should be overridden by classes extending ThreadedDequeuer

Specified by:
run in interface java.lang.Runnable

dispatchEvent

protected void dispatchEvent(Event event)
Handles events and calls EventHandler handlers. Typically called from the dequeuer implementation to invoke the handler callbacks.

Parameters:
event - the Event to dispatch to the EventHandlers

getIdleProcessor

protected ThreadedEventDispatcher getIdleProcessor()
Gets an idle processor from the list

Returns:
a ThreadedEventDispatcher

makeAvailable

public void makeAvailable(ThreadedEventDispatcher dispatcher)
Makes a process available for dispatch

Parameters:
dispatcher - the dispatcher to make available