Search in sources :

Example 1 with JMXMPConnectorServer

use of javax.management.remote.jmxmp.JMXMPConnectorServer in project Payara by payara.

the class JMXMPConnectorStarter method startJMXMPConnectorServer.

private JMXConnectorServer startJMXMPConnectorServer(final int port) throws MalformedURLException, IOException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    final Map<String, Object> env = new HashMap<String, Object>();
    env.put("jmx.remote.protocol.provider.pkgs", "com.sun.jmx.remote.protocol");
    env.put("jmx.remote.protocol.provider.class.loader", this.getClass().getClassLoader());
    env.put("jmx.remote.rmi.server.credential.types", new String[] { String[].class.getName(), String.class.getName() });
    JMXAuthenticator authenticator = getAccessController();
    if (authenticator != null) {
        env.put("jmx.remote.authenticator", authenticator);
    }
    final JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:" + JMXMP + "://" + hostname() + ":" + port);
    JMXConnectorServer jmxmp = null;
    boolean startedOK = false;
    try {
        jmxmp = new JMXMPConnectorServer(serviceURL, env, mMBeanServer);
        if (mBootListener != null) {
            jmxmp.addNotificationListener(mBootListener, null, serviceURL.toString());
        }
        jmxmp.start();
        startedOK = true;
    } catch (final Exception e) {
        e.printStackTrace();
    } finally {
        // we do it this way so that the original exeption will be thrown out
        if (!startedOK) {
            try {
                if (jmxmp != null) {
                    jmxmp.stop();
                }
            } catch (Exception e) {
                ignore(e);
            }
        }
    }
    mJMXServiceURL = serviceURL;
    mConnectorServer = jmxmp;
    return mConnectorServer;
}
Also used : HashMap(java.util.HashMap) JMXMPConnectorServer(javax.management.remote.jmxmp.JMXMPConnectorServer) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MalformedURLException(java.net.MalformedURLException) MBeanRegistrationException(javax.management.MBeanRegistrationException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 JMXMPConnectorServer (javax.management.remote.jmxmp.JMXMPConnectorServer)1