|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.veraxsystems.icmp.ping.Ping
public class Ping
Ping is the class implementing the ICMP Echo request known as network "ping" functionality.
Class is defined as static and requires initialization before it can be used init()
.
The ICMP communication is performed via IcmpJniBridge
object that is created during
initialization (only one such object is used for all echo requests).
Class uses two internal threads for its activity. One reads ICMP application issued requests and
sends ICMP echo messages while the second one reads responses and handles requests timeouts.
At the end of using the release()
method must be called to release resources especially
ICMP socket.
ICMP echo requests (pings) are sent asynchronously. Requests are issued by echo()
method that has provided result handler executed either on request response or processing error.
Obtaining error as result of operation means that either fatal error occurred or Ping class has been
released. In such case further processing is not possible and Ping class must be re-initialized.
All methods are synchronized to avoid sending echo during class initialization/releasing.
Constructor Summary | |
---|---|
Ping()
|
Method Summary | |
---|---|
static PingResult[] |
echo(java.net.InetAddress[] addresses,
byte[] dataToSend,
int timeout)
Send the set of ICMP echo requests. |
static PingResult[] |
echo(java.net.InetAddress[] addresses,
int dataLength,
int timeout)
Send the set of default ICMP echo requests. |
static int |
echo(java.net.InetAddress address,
byte[] dataToSend,
int timeoutVal,
PingResponseHandler handler)
Send ICMP echo request. |
static int |
echo(java.net.InetAddress address,
int dataLength,
int timeoutVal,
PingResponseHandler handler)
Send default ICMP echo request. |
static void |
init()
Initialize Ping class. |
static void |
release()
Release resources allocated in init() method. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Ping()
Method Detail |
---|
public static void init() throws PingErrorException
release()
method must be used. Without it allocated
resources are not released.
PingErrorException
- issued when either initialization already has been done or
other fatal error occurs (with socket creation or thread starting)public static void release()
init()
method.
Method always succeeds. Eventual internal exceptions are either properly handled
or logged using Logger
.
public static int echo(java.net.InetAddress address, byte[] dataToSend, int timeoutVal, PingResponseHandler handler) throws PingErrorException
address
- IP address of host to send ICMP echo requestdataToSend
- data to be send as part of ICMP messagetimeoutVal
- expressed in milliseconds time to wait for echo responsehandler
- asynchronous result handler
PingErrorException
- issued if Ping class is not initializedpublic static int echo(java.net.InetAddress address, int dataLength, int timeoutVal, PingResponseHandler handler) throws PingErrorException
address
- IP address of host to send ICMP echo requestdataLength
- the length of default data to be senttimeoutVal
- expressed in milliseconds time to wait for echo responsehandler
- asynchronous result handler
PingErrorException
- issued if Ping class is not initializedpublic static PingResult[] echo(java.net.InetAddress[] addresses, byte[] dataToSend, int timeout) throws PingErrorException
Each echo result is placed in array of results corresponding to addresses
parameter (it means for each input host
the result is placed in corresponding element of result array).
Each request timeout is calculated separately - it means that its calculation starts in the moment
when request is sent (not when echo
method is called). Such behavior leads to
situation that echo
execution lasts slightly longer than timeout specified.
Method reports exception when either Ping
is not initialized or current thread is interrupted.
addresses
- array of host addresses send ICMP echo requestsdataToSend
- data to be send as part of ICMP messagetimeout
- expressed in milliseconds time to wait for echo response
PingErrorException
- issued if Ping class is not initialized or thread is interruptedpublic static PingResult[] echo(java.net.InetAddress[] addresses, int dataLength, int timeout) throws PingErrorException
Each echo result is placed in array of results corresponding to addresses
parameter (it means for each input host
the result is placed in corresponding element of result array).
Each request timeout is calculated separately - it means that its calculation starts in the moment
when request is sent (not when echo
method is called). Such behavior leads to
situation that echo
execution lasts slightly longer than timeout specified.
Method reports exception when either Ping
is not initialized or current thread is interrupted.
Default data construction is based on Windows ping command behavior and contains string: "abc...w".
addresses
- array of host addresses send ICMP echo requestsdataLength
- the length of default data to be senttimeout
- expressed in milliseconds time to wait for echo response
PingErrorException
- issued if Ping class is not initialized or thread is interrupted
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |