org.opennms.netmgt.ping
Class ReplyReceiver

java.lang.Object
  extended by org.opennms.netmgt.ping.ReplyReceiver
All Implemented Interfaces:
Runnable, org.opennms.core.fiber.Fiber, org.opennms.core.fiber.PausableFiber

public final class ReplyReceiver
extends Object
implements org.opennms.core.fiber.PausableFiber, Runnable

This class is designed to be a single point of reciept for all ICMP messages received by an org.opennms.protocols.icmp.IcmpSocketIcmpSocket instance. The class implements the PausableFiberinterface as a means to control the operation of the receiver.

Once the receiver is started it will process all recieved datagrams and filter them based upon their ICMP code and the filter identifier used to construct the reciever. All ICMP messages, except for Echo Replies, are discared by the reciever. In addition, only those echo replies that have their identifier set to the passed filter identifier are also discarded.

Received datagrams that pass the requirement of the receiver are added to the reply queue for processing by the application. Only instances of the Replyclass are added to the queue for processing.

Author:
Sowmya , Brian Weaver , OpenNMS

Field Summary
 
Fields inherited from interface org.opennms.core.fiber.PausableFiber
PAUSE_PENDING, PAUSED, RESUME_PENDING
 
Fields inherited from interface org.opennms.core.fiber.Fiber
RUNNING, START_PENDING, STARTING, STATUS_NAMES, STOP_PENDING, STOPPED
 
Constructor Summary
ReplyReceiver(org.opennms.protocols.icmp.IcmpSocket portal, org.opennms.core.queue.FifoQueue<Reply> replyQ, short filterID)
           Constructs a ping reciever thread that reads datagrams from the connection and adds them to the queue.
 
Method Summary
 String getName()
          Returns the name of this fiber.
 int getStatus()
          Returns the status of the fiber.
 void pause()
          Pauses the reciever.
protected  void process(DatagramPacket pkt)
           Processes the received datagram and adds a new Reply instance to the reply queue.
 void resume()
          Resumes the recipt and processing of ICMP messages.
 void run()
          The run() method does the actual work of reading messages from the daemon and placing those messages in the appropriate queue for use by other threads.
 void start()
          Starts the ICMP receiver.
 void stop()
          Stops the current receiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplyReceiver

public ReplyReceiver(org.opennms.protocols.icmp.IcmpSocket portal,
                     org.opennms.core.queue.FifoQueue<Reply> replyQ,
                     short filterID)

Constructs a ping reciever thread that reads datagrams from the connection and adds them to the queue. As each datagram is received and processed by the receiver, replies matching the criteria are added to the queue. Each reply must be of type ICMP Echo Reply, its identity must match the filterID, and its length must be equal to the ping packet'slength.

Parameters:
portal - The ICMP socket
replyQ - The reply queue for matching messages.
filterID - The ICMP Identity for matching.
Method Detail

process

protected void process(DatagramPacket pkt)
                throws InterruptedException,
                       org.opennms.core.queue.FifoQueueException

Processes the received datagram and adds a new Reply instance to the reply queue. The recieved packet must pass the following criteria:

Parameters:
pkt - The datagram to process.
Throws:
InterruptedException - Thrown if the thread is interrupted.
org.opennms.core.fiber.FifoQueueException - Thrown if a queue exception occurs adding a new reply.
org.opennms.core.queue.FifoQueueException

start

public final void start()
Starts the ICMP receiver. Once started the receiver reads new messages from the ICMP socket and processes them. Packets that match the proper criteria are added to the queue. If the receiver is already started then an exception is thrown.

Specified by:
start in interface org.opennms.core.fiber.Fiber
Throws:
IllegalStateException - Thrown if the receiver has already been started.

stop

public final void stop()
Stops the current receiver. If the receiver was never started then an exception is thrown.

Specified by:
stop in interface org.opennms.core.fiber.Fiber
Throws:
IllegalStateException - Thrown if the receiver was never started.

pause

public final void pause()
Pauses the reciever. While the receiver is pauses the it still reads and processes new ICMP datagrams. However, all datagrams are discarded while in a paused state regardless of matching criteria. Messages are still read since the operating system will continue to deliver them.

Specified by:
pause in interface org.opennms.core.fiber.PausableFiber

resume

public final void resume()
Resumes the recipt and processing of ICMP messages.

Specified by:
resume in interface org.opennms.core.fiber.PausableFiber

getName

public final String getName()
Returns the name of this fiber.

Specified by:
getName in interface org.opennms.core.fiber.Fiber
Returns:
The fiber's name.

getStatus

public final int getStatus()
Returns the status of the fiber.

Specified by:
getStatus in interface org.opennms.core.fiber.Fiber
Returns:
The fiber's status.

run

public final void run()
The run() method does the actual work of reading messages from the daemon and placing those messages in the appropriate queue for use by other threads.

Specified by:
run in interface Runnable


Copyright ? 2008. All Rights Reserved.