org.opennms.bb.dp.actiond.components
Class ActiondEventListener

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.opennms.bb.dp.common.components.PollerThread
              |
              +--org.opennms.bb.dp.actiond.components.ActiondEventListener
All Implemented Interfaces:
Runnable

public class ActiondEventListener
extends PollerThread

ActiondEventListener extends the PollerThread for the pause/resume/shutdown functionality

Listens for events sent as XML over JSDT from the event daemon (eventd). Received data as 'EventsReader'(conatining the input stream) is added to the 'listenerQ'

It also maintains a pool of RunnableConsumerThreads that read and run the EventsReader objects added to the listenerQ to actually parse the input streams to events('EventBlocks') in order to extract any automatic actions associated with the event - the 'EventsReader's are then added to the 'actionQ' where they are read by 'ExecuteAction' threads and the actions actually executed by launching a new process.

Version:
$Revision: 1.2 $
Author:
Mike, Sowmya Kumaraswamy, Brian Weaver, OpenNMS.org

Field Summary
private static int INIT_NUM_READERS
          The initial number of threads.
private  PCQueue m_actionQ
          The queue to which completed reader objects are sent for further processing.
private  List m_eventReaders
          The RunnableConsumerThread thread pool.
private  ActiondEventReceiver m_eventReceiver
          The handler for events coming in through JSDT from eventd.
private static Map m_eventsParserPool
          A hash table for the parser pool to be used by the 'RunnableConsumerThread' pool - a parser is added to the pool for each thread in the pool so that when the threads can then look up their parser by using the current thread ID
private  PCQueue m_listenerQ
          The queue to which the incoming events are added.
private static int max_readers
          The max number of RunnableConsumerThreads that should be started by the manager.
private static String PROP_MAX_EVENT_LISTENER_THREADS
          The property name that contains the maximum number of threads to be used by the ActiondEventListenr for parsing event XML streams.
 
Fields inherited from class org.opennms.bb.dp.common.components.PollerThread
m_curOpStatus, STATUS_MASK, STATUS_NORMAL, STATUS_PAUSED, STATUS_PAUSING, STATUS_RESUMING, STATUS_SHUTDOWN, STATUS_STARTING, STATUS_TERMINATING
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
ActiondEventListener(PCQueue actionQ)
          Creates the ActiondEventListener thread of actiond that listens for events via JSDT from eventd
 
Method Summary
(package private) static void ()
           
static org.apache.xerces.parsers.SAXParser getEventsParser(Object key)
          Returns the SAX based parser that can be used to decompose the event.
 void run()
          Loop through and keep track of the status changes.
 void shutdown()
          Initiates the shutdown sequence and waits for this thread to exit.
protected  void threadsVsQueueSizeCheck()
          After each read from the listenerQ, the threads in the thread pool call this method to adjust the number of threads in the pool if necessary If the number of entries in the queue is more than double the number of threads, the number of threads is increased by one until the configurable maximum number of threads is reached If the number of threads in thepool is more than double the number of entries in the queue, the number of threads is decreased by one until the predefined initial number of threads is reached
 
Methods inherited from class org.opennms.bb.dp.common.components.PollerThread
getCtrlStatus, getOpStatus, pauseOperation, pauseThread, resumeOperation, resumeThread, setCtrlStatus, setOpStatus, setUserStatus, shutdownThread
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROP_MAX_EVENT_LISTENER_THREADS

private static final String PROP_MAX_EVENT_LISTENER_THREADS

The property name that contains the maximum number of threads to be used by the ActiondEventListenr for parsing event XML streams.


INIT_NUM_READERS

private static int INIT_NUM_READERS

The initial number of threads.


m_listenerQ

private PCQueue m_listenerQ

The queue to which the incoming events are added.


m_actionQ

private PCQueue m_actionQ

The queue to which completed reader objects are sent for further processing.


m_eventReceiver

private ActiondEventReceiver m_eventReceiver

The handler for events coming in through JSDT from eventd.


max_readers

private static int max_readers

The max number of RunnableConsumerThreads that should be started by the manager.


m_eventReaders

private List m_eventReaders
The RunnableConsumerThread thread pool. Responsible for running reader objects which parse the XML input stream and build a list of Event objects for later processing by the launchManager. When the reader object is finished processing it is placed on the m_actionQ.

m_eventsParserPool

private static Map m_eventsParserPool
A hash table for the parser pool to be used by the 'RunnableConsumerThread' pool - a parser is added to the pool for each thread in the pool so that when the threads can then look up their parser by using the current thread ID
Constructor Detail

ActiondEventListener

public ActiondEventListener(PCQueue actionQ)
                     throws ActiondEventListenerException

Creates the ActiondEventListener thread of actiond that listens for events via JSDT from eventd

The ActiondEventListener also has a pool of 'RunnableConsumerThread' threads that reads the input streams added by the individual listeners and parses the streams (this is done by running the EventsReader objects in the listenerQ)

Throws:
throws - ActiondEventListenerException if any of the handlers fail to get created
Method Detail

static void ()

threadsVsQueueSizeCheck

protected void threadsVsQueueSizeCheck()
After each read from the listenerQ, the threads in the thread pool call this method to adjust the number of threads in the pool if necessary If the number of entries in the queue is more than double the number of threads, the number of threads is increased by one until the configurable maximum number of threads is reached If the number of threads in thepool is more than double the number of entries in the queue, the number of threads is decreased by one until the predefined initial number of threads is reached

run

public void run()
Loop through and keep track of the status changes. When a pause/ resume/shutdown is recieved, the status is updated and the handler threads are paused/resumed as appropriate
Overrides:
run in class Thread

shutdown

public void shutdown()

Initiates the shutdown sequence and waits for this thread to exit.

Overrides:
shutdown in class PollerThread
Following copied from class: org.opennms.bb.dp.common.components.PollerThread
See Also:
PollerThread.STATUS_TERMINATING, Object.notifyAll()

getEventsParser

public static org.apache.xerces.parsers.SAXParser getEventsParser(Object key)
Returns the SAX based parser that can be used to decompose the event. Use the getContentHandler method of the parser to get the event parser!
Parameters:
key - the currently running thread
Returns:
The SAX parser that can be used to decompose the event object.
See Also:
org.apache.xerces.parser.SAXParser#getContentHandler, org.apache.soap.sax.SAXParser#getContentHandler