org.opennms.bb.dp.discovery.components
Class DiscPingManager

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

public final class DiscPingManager
extends PollerThread

The DiscPingManager is the thread responsible to send and receive
 the PING requests to discover nodes

 It maintains a pool of DiscPingerThreads to send out the PING requests. 
 These threads read off the m_pingRequestQ to which the IPGenerator queues 
 node and send out the requests to the icmpd

 It also has a DiscPingReplyReceiver thread that recieves all the filtered
 replies from the icmpd and queues it back to the main thread. Once a reply
 is received, the manager notifies the DiscPinger thread that was in charge 
 of sending out the request for which the reply has been received so
 that it stops any retries that might be pending and starts on the next 
 address

 Once a reply has been received, the capsd is informed about the new node
 found

Author:
Sowmya

Inner Class Summary
private static class DiscPingManager.AddressToSoapDocument
          This static class is used to build an compliant SOAP document that is sent to the capabilities daemon.
private  class DiscPingManager.ManagerClient
          Extends the PollerClient class to allow the string constructor to be called.
 
Field Summary
private static long BASE_MONITOR_THREADID
          Base thread id for the monitor pinger threads...this value distinguishes a thread in the monitor pool from a thread in the discovery pool.
private  boolean bMonitorThreadPoolCreated
          True if the monitor thread pool has already been created and the MonitorPinger threads started.
private static int INIT_NUM_MONITOR_POLLERS
          the initial number of monitor pinger threads
private  com.sun.media.jsdt.Channel m_channel
          JSDT channel that capsd is listening on
private  PollerClient m_client
          JSDT client identifier of this thread
private  short m_filterID
          Filter to be used for communication with icmpd
private  int m_maxNumMonitorThreads
          Max number of MonitorPinger threads to create.
private  List m_monitorPollers
          MonitorPinger thread pool
private  com.sun.media.jsdt.Channel m_monitorReplyChannel
           
private  PollerClient m_monitorReplyClient
           
private  PCQueue m_monitorRequestQ
          queue to which MonitorRequestReceiver adds the next address to ping
private  com.sun.media.jsdt.Session m_monitorSession
           
private  List m_pollers
          thread pool
private  DaemonConnection m_portal
          icmpd portal
private  DiscPingReplyReceiver m_receiver
          ping receiver thread
private  PCQueue m_replyQ
          queue to which DiscReplyReceiver adds the address whose ping reply was received
private  PCQueue m_requestQ
          queue to which IPGenerator adds the next address to ping
private  com.sun.media.jsdt.Session m_session
          JSDT session in which discovery and capsd communicate
 
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
DiscPingManager(int port, long nThreads, long nPktsPerSec, PCQueue requestQ, int maxMonitorThreads, PCQueue monitorRequestQ)
          The ping manager's constructor is used to initialize the connection to the icmpd, open the jsdt connections, and startup the pinger thread pool.
 
Method Summary
private  MonitorPinger getMonitorPingSender(long threadID)
          Find the MonitorPinger thread that was assigned to send ping packets for this IP Address.
 boolean getOkResponse(DaemonConnection dc)
          Get's the response message from the icmp daemon and checks it for a zero return code.
private  DiscPinger getPingSender(long threadID)
          Find the thread that was assigned to send ping packets for this IP Address.
private  boolean jsdtConnect(String name)
          Creates a connection to the JSDT registry and also creates the session for sending updates about discovered nodes.
private  boolean jsdtConnectMonitor(String name)
          Creates a connection to the JSDT registry and also creates the session/channel through which the MonitorPinger threads will send poll results to the ICMP service monitor.
 void run()
          Wait for a notify() - the thread is notified if there is a status change or by the DiscReplyReciever thread if a reply has been received for any ping request Everytime it is interrupted from a wait, it checks for a status change - if there is a status change, appropriate action is taken if the status is normal, it means a reply has been received, it reads from the recieve Q, informs the pinger thread that sent the request out, informs capsd and goes back to waiting
 void shutdown()
          Initiates the shutdown sequence and waits for the ping manager thread to exit.
protected  void threadsVsQueueSizeCheck()
          After each read from the monitorRequestQ, the threads in the monitor 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
 
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

m_requestQ

private PCQueue m_requestQ
queue to which IPGenerator adds the next address to ping

m_monitorRequestQ

private PCQueue m_monitorRequestQ
queue to which MonitorRequestReceiver adds the next address to ping

m_replyQ

private PCQueue m_replyQ
queue to which DiscReplyReceiver adds the address whose ping reply was received

m_pollers

private List m_pollers
thread pool

m_receiver

private DiscPingReplyReceiver m_receiver
ping receiver thread

m_filterID

private short m_filterID
Filter to be used for communication with icmpd

m_client

private PollerClient m_client
JSDT client identifier of this thread

m_session

private com.sun.media.jsdt.Session m_session
JSDT session in which discovery and capsd communicate

m_channel

private com.sun.media.jsdt.Channel m_channel
JSDT channel that capsd is listening on

m_portal

private DaemonConnection m_portal
icmpd portal

m_monitorSession

private com.sun.media.jsdt.Session m_monitorSession

m_monitorReplyChannel

private com.sun.media.jsdt.Channel m_monitorReplyChannel

m_monitorReplyClient

private PollerClient m_monitorReplyClient

m_monitorPollers

private List m_monitorPollers
MonitorPinger thread pool

m_maxNumMonitorThreads

private int m_maxNumMonitorThreads
Max number of MonitorPinger threads to create.

bMonitorThreadPoolCreated

private boolean bMonitorThreadPoolCreated
True if the monitor thread pool has already been created and the MonitorPinger threads started. False otherwise.

INIT_NUM_MONITOR_POLLERS

private static int INIT_NUM_MONITOR_POLLERS
the initial number of monitor pinger threads

BASE_MONITOR_THREADID

private static final long BASE_MONITOR_THREADID
Base thread id for the monitor pinger threads...this value distinguishes a thread in the monitor pool from a thread in the discovery pool. This was necessary because we weren't able to distinguish between the two thread pools based on filter ID.
Constructor Detail

DiscPingManager

public DiscPingManager(int port,
                       long nThreads,
                       long nPktsPerSec,
                       PCQueue requestQ,
                       int maxMonitorThreads,
                       PCQueue monitorRequestQ)
                throws IOException

The ping manager's constructor is used to initialize the connection to the icmpd, open the jsdt connections, and startup the pinger thread pool. In addition is also starts the icmp receiver thread for discovery and prepares the thread for prime time.

Parameters:
port - The port for the icmpd connection
nThreads - The number of poller threads to create
nPktsPerSec - The limiter number for sending icmp messages.
PCQueue - The input icmp request queue to be managed.
nThreads - The maximum number of monitor poller threads to create
PCQueue - A 2nd icmp request Q for incoming ICMP Service Monitor requests
Throws:
IOException - Thrown if an error occurs with the icmpd connection.
RuntimeException - Thrown if an error occurs setting up threads or the JSDT collaboritive environment.
Method Detail

jsdtConnect

private boolean jsdtConnect(String name)
                     throws InterruptedException

Creates a connection to the JSDT registry and also creates the session for sending updates about discovered nodes.

Parameters:
name - The name of the new client.
Returns:
True if the connection is created, false otherwise.
Throws:
InterruptedException - Thrown if the thread is interrupted while attempting to setup the jsdt connection.

jsdtConnectMonitor

private boolean jsdtConnectMonitor(String name)
                            throws InterruptedException

Creates a connection to the JSDT registry and also creates the session/channel through which the MonitorPinger threads will send poll results to the ICMP service monitor.

Parameters:
name - The name of the new client.
Returns:
True if the connection is created, false otherwise.
Throws:
InterruptedException - Thrown if the thread is interrupted while attempting to setup the jsdt connection.

threadsVsQueueSizeCheck

protected void threadsVsQueueSizeCheck()
After each read from the monitorRequestQ, the threads in the monitor 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

getPingSender

private DiscPinger getPingSender(long threadID)

Find the thread that was assigned to send ping packets for this IP Address.

Parameters:
threadID - the id of the thread to find

getMonitorPingSender

private MonitorPinger getMonitorPingSender(long threadID)

Find the MonitorPinger thread that was assigned to send ping packets for this IP Address.

Parameters:
threadID - the id of the thread to find

getOkResponse

public boolean getOkResponse(DaemonConnection dc)
                      throws IOException

Get's the response message from the icmp daemon and checks it for a zero return code. If an I/O error occurs then an exception is thrown. The value of the boolean return indicates the success or failure of the last message

Parameters:
dc - The connection to the icmp daemon
Returns:
A value of true is returned if no error occured. A false value indicates that an error occured with the last control message.
Throws:
IOException - Thrown if there is an error communicating with the icmpd.

run

public void run()
Wait for a notify() - the thread is notified if there is a status change or by the DiscReplyReciever thread if a reply has been received for any ping request Everytime it is interrupted from a wait, it checks for a status change - if there is a status change, appropriate action is taken if the status is normal, it means a reply has been received, it reads from the recieve Q, informs the pinger thread that sent the request out, informs capsd and goes back to waiting
Overrides:
run in class Thread

shutdown

public void shutdown()

Initiates the shutdown sequence and waits for the ping manager 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()