Search in sources :

Example 6 with Pinger

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);
    }
}
Also used : InetAddress(java.net.InetAddress) Pinger(org.opennms.netmgt.icmp.Pinger) BestMatchPingerFactory(org.opennms.netmgt.icmp.best.BestMatchPingerFactory) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Pinger (org.opennms.netmgt.icmp.Pinger)6 InetAddress (java.net.InetAddress)3 BestMatchPingerFactory (org.opennms.netmgt.icmp.best.BestMatchPingerFactory)3 UnknownHostException (java.net.UnknownHostException)2 NullPinger (org.opennms.netmgt.icmp.NullPinger)2 PingerFactory (org.opennms.netmgt.icmp.PingerFactory)2 Throwables (com.google.common.base.Throwables)1 Sets (com.google.common.collect.Sets)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1