org.opennms.netmgt.ping
Class Pinger
java.lang.Object
org.opennms.netmgt.ping.Pinger
public class Pinger
- extends java.lang.Object
Pinger Design
The pinger has four components that are all static
an icmpSocket
a pendingRequest map
a pendingReply queue (LinkedBlockingQueue)
a timeout queue (DelayQueue)
It also has three threads:
a thread to read from the icmpSocket - (icmp socket reader)
a thread to process the pendingReplyQueue - (icmp reply processor)
a thread to process the timeouts (icmp timeout processor)
Processing:
All requests are asynchronous (if synchronous requests are need that
are implemented using asynchronous requests and blocking callbacks)
Making a request: (client thread)
- create a pingRequest
- add it to a pendingRequestMap
- send the request
- add it to the timeout queue
Reading from the icmp socket: (icmp socket reader)
- read a packet from the socket
- construct a reply object
- verify it is an opennms gen'd packet
- add it to the pendingReply queue
Processing a reply: (icmp reply processor)
- take a reply from the pendingReply queue
- look up and remove the matching request in the pendingRequest map
- call request.processReply(reply) - this will store the reply and
call the handleReply call back
- pending request sets completed to true
Processing a timeout:
- take a request from the timeout queue
- if the request is completed discard it
- otherwise, call request.processTimeout(), this will check the number
of retries and either return a new request with fewer retries or
call the handleTimeout call back
- if processTimeout returns a new request than process it as in Making
a request
Thread Details:
1. The icmp socket reader that will listen on the ICMP socket. It
will pull packets off the socket and construct replies and add
them to a LinkedBlockingQueue
2. The icmp reply processor that will pull replies off the linked
blocking queue and process them. This will result in calling the
PingResponseCallback handleReply method.
3. The icmp timeout processor that will pull PingRequests off of a
DelayQueue. A DelayQueue does not allow things to be removed from
them until the timeout has expired.
|
Constructor Summary |
Pinger()
Initialize a Pinger object, specifying the timeout and retries. |
|
Method Summary |
static void |
initialize()
|
static java.util.List<java.lang.Number> |
parallelPing(java.net.InetAddress host,
int count,
long timeout,
long pingInterval)
|
static java.lang.Long |
ping(java.net.InetAddress host)
Ping a remote host, using the default number of retries and timeouts. |
static java.lang.Long |
ping(java.net.InetAddress host,
long timeout,
int retries)
This method is used to ping a remote host to test for ICMP support. |
static void |
ping(java.net.InetAddress host,
long timeout,
int retries,
short sequenceId,
PingResponseCallback cb)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
DEFAULT_RETRIES
public static final int DEFAULT_RETRIES
- See Also:
- Constant Field Values
Pinger
public Pinger()
throws java.io.IOException
- Initialize a Pinger object, specifying the timeout and retries.
- Parameters:
defaultTimeout - the timeout, in milliseconds, to wait for returned packets.defaultRetries - the number of times to retry a given ping packet
- Throws:
java.io.IOException
initialize
public static void initialize()
throws java.io.IOException
- Throws:
java.io.IOException
ping
public static void ping(java.net.InetAddress host,
long timeout,
int retries,
short sequenceId,
PingResponseCallback cb)
throws java.io.IOException
- Throws:
java.io.IOException
ping
public static java.lang.Long ping(java.net.InetAddress host,
long timeout,
int retries)
throws java.lang.InterruptedException,
java.io.IOException
- This method is used to ping a remote host to test for ICMP support. If
the remote host responds within the specified period, defined by retries
and timeouts, then the response time is returned.
- Parameters:
host - The address to poll.timeout - The time to wait between each retry.retries - The number of times to retry
- Returns:
- The response time in microseconds if the host is reachable and has responded with an echo reply, otherwise a null value.
- Throws:
java.lang.InterruptedException
java.io.IOException
ping
public static java.lang.Long ping(java.net.InetAddress host)
throws java.io.IOException,
java.lang.InterruptedException
- Ping a remote host, using the default number of retries and timeouts.
- Parameters:
host - the host to ping
- Returns:
- the round-trip time of the packet
- Throws:
java.io.IOException
java.lang.InterruptedException
parallelPing
public static java.util.List<java.lang.Number> parallelPing(java.net.InetAddress host,
int count,
long timeout,
long pingInterval)
throws java.io.IOException,
java.lang.InterruptedException
- Throws:
java.io.IOException
java.lang.InterruptedException
Copyright © 2007. All Rights Reserved.