Search in sources :

Example 1 with JvmContextFactory

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);
}
Also used : SnmpAcl(com.sun.jmx.snmp.IPAcl.SnmpAcl) UnknownHostException(java.net.UnknownHostException) InetAddressAcl(com.sun.jmx.snmp.InetAddressAcl) JVM_MANAGEMENT_MIB_IMPL(sun.management.snmp.jvminstr.JVM_MANAGEMENT_MIB_IMPL) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JvmContextFactory(sun.management.snmp.util.JvmContextFactory) SnmpAdaptorServer(com.sun.jmx.snmp.daemon.SnmpAdaptorServer) AgentConfigurationError(sun.management.AgentConfigurationError) InetAddress(java.net.InetAddress)

Aggregations

SnmpAcl (com.sun.jmx.snmp.IPAcl.SnmpAcl)1 InetAddressAcl (com.sun.jmx.snmp.InetAddressAcl)1 SnmpAdaptorServer (com.sun.jmx.snmp.daemon.SnmpAdaptorServer)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 AgentConfigurationError (sun.management.AgentConfigurationError)1 JVM_MANAGEMENT_MIB_IMPL (sun.management.snmp.jvminstr.JVM_MANAGEMENT_MIB_IMPL)1 JvmContextFactory (sun.management.snmp.util.JvmContextFactory)1