org.opennms.bb.dp.eventd
Class TCPHandler

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

public class TCPHandler
extends PollerThread

TCPHandler handles TCP connections to the eventd. For each conenction accepted, it creates a 'SocketShadowInputStream' object to pass the input stream of the socket to be parsed for events

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

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

Inner Class Summary
private static class TCPHandler.ConnectionHandler
          When the TCPHandler blocks on the 'accept()', there is no reliable way to interrupt the thread on a status change.
private static class TCPHandler.Counter
          The counter class is used to ensure that the count is kept accurate when multiple threads could be trying to adjust the count at the same time.
private  class TCPHandler.SocketShadowInputStream
          An input stream that is a a shadow of the socket's input stream except that on a close(), the socket is closed so that the input stream is still open for parse - the input stream is closed after the parse is complete
 
Field Summary
private static int CONN_BACKLOG
          the length of the queue of connections
private  TCPHandler.Counter m_connections
          the current number of connections being handled - is updated during the creation and close of the inner class SocketShadowInputStream
private  TCPHandler.ConnectionHandler m_handler
          The connection handler that accepts connections and queues them back to the main thread
private  PCQueue m_readerQ
          queue of the EventsReaders
private  ServerSocket m_server
          The socket on which eventd/eventListener listens for TCP connections
private  PCQueue m_tcpQ
          queue between the inner class that accepts new connections and the main thread
private static int numEventsRcvd
           
 
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
(package private) TCPHandler(int port, PCQueue readerQ)
          Instantiate the TCPHandler at the said port with the default name
(package private) TCPHandler(String name, int port, PCQueue readerQ)
          Instantiate the TCPHandler at the said port with the specified name
 
Method Summary
 void run()
          The main method that keeps track of status changes and reads accepted connections from the 'tcpQ'.
 void shutdown()
          Shutdown operation.
 void start()
          Start operation
 
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, 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

CONN_BACKLOG

private static final int CONN_BACKLOG
the length of the queue of connections

m_server

private ServerSocket m_server
The socket on which eventd/eventListener listens for TCP connections

m_readerQ

private PCQueue m_readerQ
queue of the EventsReaders

m_tcpQ

private PCQueue m_tcpQ
queue between the inner class that accepts new connections and the main thread

m_handler

private TCPHandler.ConnectionHandler m_handler
The connection handler that accepts connections and queues them back to the main thread

m_connections

private TCPHandler.Counter m_connections
the current number of connections being handled - is updated during the creation and close of the inner class SocketShadowInputStream

numEventsRcvd

private static int numEventsRcvd
Constructor Detail

TCPHandler

TCPHandler(int port,
           PCQueue readerQ)
     throws IOException
Instantiate the TCPHandler at the said port with the default name
Parameters:
port - port number to be used by the handler
readerQ - queue to which the incoming events are to be added
Throws:
IOException - Thrown if communication port cannot be set up
org.apache.sax.SAXException - Thrown if the event parser pool cannot be created

TCPHandler

TCPHandler(String name,
           int port,
           PCQueue readerQ)
     throws IOException
Instantiate the TCPHandler at the said port with the specified name
Parameters:
name - name of this thread
port - port number to be used by the handler
readerQ - queue to which the incoming events are to be added
Throws:
IOException - Thrown if communication port cannot be set up
org.apache.sax.SAXException - Thrown if the event parser pool cannot be created
Method Detail

run

public void run()
The main method that keeps track of status changes and reads accepted connections from the 'tcpQ'. For each accepted connection, a 'SocketShadowInputStream' is created and added to the listener queue from where the EventListener thread pool picks it up and parses it before closing it
Overrides:
run in class Thread

start

public void start()
Start operation
Overrides:
start in class Thread

shutdown

public void shutdown()
Shutdown operation. Close the server socket and the internal queue and shutdown the ConnectionHandler thread
Overrides:
shutdown in class PollerThread
Following copied from class: org.opennms.bb.dp.common.components.PollerThread
See Also:
PollerThread.STATUS_TERMINATING, Object.notifyAll()