Search in sources :

Example 1 with PingerFactory

use of org.opennms.netmgt.icmp.PingerFactory in project opennms by OpenNMS.

the class CamelBlueprintTest method doPreSetup.

/**
     * Use Aries Blueprint synchronous mode to avoid a blueprint deadlock bug. Also, make sure
     * the PingerFactory is reset so DSCP/fragment bits are cleared.
     *
     * @see https://issues.apache.org/jira/browse/ARIES-1051
     * @see https://access.redhat.com/site/solutions/640943
     */
@Override
public void doPreSetup() throws Exception {
    System.setProperty("org.apache.aries.blueprint.synchronous", Boolean.TRUE.toString());
    System.setProperty("de.kalpatec.pojosr.framework.events.sync", Boolean.TRUE.toString());
    try {
        final PingerFactory pingerFactory = getOsgiService(PingerFactory.class, 2000);
        if (pingerFactory instanceof AbstractPingerFactory) {
            ((AbstractPingerFactory) pingerFactory).reset();
        }
    } catch (final Exception e) {
        LOG.warn("Failed to get PingerFactory. This may be intentional.");
    }
}
Also used : PingerFactory(org.opennms.netmgt.icmp.PingerFactory) AbstractPingerFactory(org.opennms.netmgt.icmp.AbstractPingerFactory) AbstractPingerFactory(org.opennms.netmgt.icmp.AbstractPingerFactory)

Example 2 with PingerFactory

use of org.opennms.netmgt.icmp.PingerFactory in project opennms by OpenNMS.

the class CLIPinger method doMain.

public void doMain(String[] args) throws CmdLineException {
    setPropertiesIfPossible();
    CmdLineParser parser = new CmdLineParser(this);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        parser.printUsage(System.err);
        System.exit(1);
    }
    InetAddress host;
    double rttMs;
    if (s_arguments.isEmpty()) {
        parser.printUsage(System.err);
        System.exit(1);
    }
    try {
        host = InetAddress.getByName(s_arguments.get(0));
        final PingerFactory pf = new BestMatchPingerFactory();
        final Pinger p = pf.getInstance(Integer.decode(s_dscp), s_allowFragmentation);
        for (int i = 0; i < s_count; i++) {
            Number rtt = p.ping(host, s_timeout, s_retries);
            if (rtt == null) {
                System.out.println("request timed out");
            } else {
                rttMs = rtt.doubleValue() / 1000.0;
                System.out.println("Reply from " + host.getHostName() + " (" + host.getHostAddress() + "): time=" + rttMs + " ms");
            }
            if (i < s_count - 1) {
                Thread.sleep(s_interval);
            }
        }
    } catch (UnknownHostException ex) {
        System.out.println("Unknown host " + args[0]);
        System.exit(1);
    } catch (Throwable ex) {
        System.out.println("Unexpected exception while pinging " + args[0] + ": " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    } finally {
        System.exit(0);
    }
}
Also used : Pinger(org.opennms.netmgt.icmp.Pinger) PingerFactory(org.opennms.netmgt.icmp.PingerFactory) BestMatchPingerFactory(org.opennms.netmgt.icmp.best.BestMatchPingerFactory) CmdLineParser(org.kohsuke.args4j.CmdLineParser) BestMatchPingerFactory(org.opennms.netmgt.icmp.best.BestMatchPingerFactory) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

PingerFactory (org.opennms.netmgt.icmp.PingerFactory)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1 AbstractPingerFactory (org.opennms.netmgt.icmp.AbstractPingerFactory)1 Pinger (org.opennms.netmgt.icmp.Pinger)1 BestMatchPingerFactory (org.opennms.netmgt.icmp.best.BestMatchPingerFactory)1