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.");
}
}
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);
}
}
Aggregations