use of sun.management.snmp.util.JvmContextFactory in project jdk8u_jdk by JetBrains.
the class AdaptorBootstrap method getAdaptorBootstrap.
private static AdaptorBootstrap getAdaptorBootstrap(int port, int trapPort, String bindAddress, boolean useAcl, String aclFileName) {
final InetAddress address;
try {
address = InetAddress.getByName(bindAddress);
} catch (UnknownHostException e) {
throw new AgentConfigurationError(UNKNOWN_SNMP_INTERFACE, e, bindAddress);
}
if (log.isDebugOn()) {
log.debug("initialize", Agent.getText("jmxremote.AdaptorBootstrap.getTargetList.starting" + "\n\t" + PropertyNames.PORT + "=" + port + "\n\t" + PropertyNames.TRAP_PORT + "=" + trapPort + "\n\t" + PropertyNames.BIND_ADDRESS + "=" + address + (useAcl ? ("\n\t" + PropertyNames.ACL_FILE_NAME + "=" + aclFileName) : "\n\tNo ACL") + ""));
}
final InetAddressAcl acl;
try {
acl = useAcl ? new SnmpAcl(System.getProperty("user.name"), aclFileName) : null;
} catch (UnknownHostException e) {
throw new AgentConfigurationError(UNKNOWN_SNMP_INTERFACE, e, e.getMessage());
}
// Create adaptor
final SnmpAdaptorServer adaptor = new SnmpAdaptorServer(acl, port, address);
adaptor.setUserDataFactory(new JvmContextFactory());
adaptor.setTrapPort(trapPort);
// Create MIB
//
final JVM_MANAGEMENT_MIB_IMPL mib = new JVM_MANAGEMENT_MIB_IMPL();
try {
mib.init();
} catch (IllegalAccessException x) {
throw new AgentConfigurationError(SNMP_MIB_INIT_FAILED, x, x.getMessage());
}
// Configure the trap destinations.
//
mib.addTargets(getTargetList(acl, trapPort));
//
try {
// Will wait until the adaptor starts or fails to start.
// If the adaptor fails to start, a CommunicationException or
// an InterruptedException is thrown.
//
adaptor.start(Long.MAX_VALUE);
} catch (Exception x) {
Throwable t = x;
if (x instanceof com.sun.jmx.snmp.daemon.CommunicationException) {
final Throwable next = t.getCause();
if (next != null)
t = next;
}
throw new AgentConfigurationError(SNMP_ADAPTOR_START_FAILED, t, address + ":" + port, "(" + t.getMessage() + ")");
}
//
if (!adaptor.isActive()) {
throw new AgentConfigurationError(SNMP_ADAPTOR_START_FAILED, address + ":" + port);
}
try {
// Add MIB to adaptor
//
adaptor.addMib(mib);
// Add Adaptor to the MIB
//
mib.setSnmpAdaptor(adaptor);
} catch (RuntimeException x) {
new AdaptorBootstrap(adaptor, mib).terminate();
throw x;
}
log.debug("initialize", Agent.getText("jmxremote.AdaptorBootstrap.getTargetList.initialize1"));
log.config("initialize", Agent.getText("jmxremote.AdaptorBootstrap.getTargetList.initialize2", address.toString(), java.lang.Integer.toString(adaptor.getPort())));
return new AdaptorBootstrap(adaptor, mib);
}
Aggregations