org.opennms.bb.dp.eventd
Class UDPHandler

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

public class UDPHandler
extends PollerThread

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

It handles all the events sent to eventd via UDP. It handles events that are 16K or lesser in size

Comments: Some code adpated/changed from Rick's initial code for eventd - sk

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

Inner Class Summary
private static class UDPHandler.DatagramPacketHandler
          When the UDPHandler blocks on the 'receive()', there is no reliable way to interrupt the thread on a status change.
 
Field Summary
private static int BUF_SIZE
          Buffer size used for input
private  UDPHandler.DatagramPacketHandler m_handler
          The datagram packet handler that accepts datagram packets and queues them back to the main thread
private  PCQueue m_readerQ
          queue to the eventExpander
private  DatagramSocket m_server
          UDP socket on which events are received
private  PCQueue m_udpQ
          queue between the inner class that accepts new datagram packets 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) UDPHandler(int port, PCQueue readerQ)
          Constructs a handler listening at the port 'port'
 
Method Summary
 void run()
          The main method of the UDPHandler that reads the datagram packets from the 'udpQ'.
private  int setUpComm()
          Called to setup the communications channel buffers.
 void shutdown()
          Initiates the shutdown sequence and waits for this thread to exit.
 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

BUF_SIZE

private static final int BUF_SIZE
Buffer size used for input

m_readerQ

private PCQueue m_readerQ
queue to the eventExpander

m_server

private DatagramSocket m_server
UDP socket on which events are received

m_udpQ

private PCQueue m_udpQ
queue between the inner class that accepts new datagram packets and the main thread

m_handler

private UDPHandler.DatagramPacketHandler m_handler
The datagram packet handler that accepts datagram packets and queues them back to the main thread

numEventsRcvd

private static int numEventsRcvd
Constructor Detail

UDPHandler

UDPHandler(int port,
           PCQueue readerQ)
     throws SocketException
Constructs a handler listening at the port 'port'
Parameters:
eListener - the event listener
port - port number on which this handler is to listen
readerQ - queue to which incoming events are to be addded
Throws:
throws - java.net.SocketException if the socket cannot be opened or if it cannot bind to the port number
throws - org.xml.sax.SAXException if the events parser cannot be created
Method Detail

setUpComm

private int setUpComm()
Called to setup the communications channel buffers. The method attempts to set the receive buffer size to 16k. If it fails then the default buffer size is recovered. If the default buffer size cannot be recovered then a zero is returned.
Returns:
The communications channel receive buffer size. A zero is returned on error

run

public void run()
The main method of the UDPHandler that reads the datagram packets from the 'udpQ'. A 'EventsReader' is created for each of the packets and queued to the listener queue from where the 'EventListener' thread pool picks it up and parses the input stream before closing the input stream in EventsReader
Overrides:
run in class Thread

start

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

shutdown

public void shutdown()

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

Close the datagram socket and the internal queue and shutdown the datagram packet reciever thread
Overrides:
shutdown in class PollerThread
Following copied from class: org.opennms.bb.dp.common.components.PollerThread
See Also:
PollerThread.STATUS_TERMINATING, Object.notifyAll()