use of org.opennms.netmgt.icmp.Pinger in project opennms by OpenNMS.
the class Installer method pingLocalhost.
/**
* <p>pingLocalhost</p>
*
* @throws java.io.IOException if any.
*/
public void pingLocalhost() throws Exception {
String host = "127.0.0.1";
java.net.InetAddress addr = null;
try {
addr = InetAddress.getByName(host);
} catch (java.net.UnknownHostException e) {
System.out.println("UnknownHostException when looking up " + host + ".");
throw e;
}
Pinger pinger;
try {
pinger = new BestMatchPingerFactory().getInstance();
} catch (UnsatisfiedLinkError e) {
System.out.println("UnsatisfiedLinkError while creating an ICMP Pinger. Most likely failed to load " + "libjicmp.so. Try setting the property 'opennms.library.jicmp' to point at the " + "full path name of the libjicmp.so shared library or switch to using the JnaPinger " + "(e.g. 'java -Dopennms.library.jicmp=/some/path/libjicmp.so ...')\n" + "You can also set the 'opennms.library.jicmp6' property in the same manner to specify " + "the location of the JICMP6 library.");
throw e;
} catch (NoClassDefFoundError e) {
System.out.println("NoClassDefFoundError while creating an IcmpSocket. Most likely failed to load libjicmp.so" + "or libjicmp6.so.");
throw e;
} catch (Exception e) {
System.out.println("Exception while creating Pinger.");
throw e;
}
// using regular InetAddress toString here since is just printed for the users benefit
System.out.print("Pinging " + host + " (" + addr + ")...");
Number rtt = pinger.ping(addr);
if (rtt == null) {
System.out.println("failed.!");
} else {
System.out.printf("successful.. round trip time: %.3f ms%n", rtt.doubleValue() / 1000.0);
}
}
Aggregations