Search in sources :

Example 76 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project LogHub by fbacchella.

the class Helper method start.

public static JMXConnectorServer start(PROTOCOL protocol, String host, int port) throws IOException, NotBoundException {
    MBeanServer mbs;
    JMXServiceURL url;
    JMXConnectorServer cs;
    String path = "/";
    String protocolString = protocol.toString();
    Map<String, Object> jmxenv = new HashMap<>();
    if (protocol == PROTOCOL.rmi) {
        // If listen bound to a given ip, and jmx protocol is rmi, use it as the rmi's property hostname.
        if (!"0.0.0.0".equals(host) && System.getProperty("java.rmi.server.hostname") == null) {
            System.setProperty("java.rmi.server.hostname", host);
            // Not sure if it's useful, hostname is resolve in sun.rmi.transport.tcp.TCPEndpoint, using InetAddress.getLocalHost() if
            // this property is not defined.
            // But it might be hiding in other places
            jmxenv.put("java.rmi.server.hostname", host);
        }
        protocolString = "rmi";
        java.rmi.registry.LocateRegistry.createRegistry(port);
        path = "/jndi/rmi://" + host + ":" + port + "/jmxrmi";
    }
    url = new JMXServiceURL(protocolString, host, port, path);
    mbs = ManagementFactory.getPlatformMBeanServer();
    cs = JMXConnectorServerFactory.newJMXConnectorServer(url, jmxenv, mbs);
    cs.start();
    return cs;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) MBeanServer(javax.management.MBeanServer) JMXConnectorServer(javax.management.remote.JMXConnectorServer)

Example 77 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jbossws-cxf by jbossws.

the class JBossWSTestHelper method getServerConnection.

private static MBeanServerConnection getServerConnection(String jmxServiceUrl) {
    final String urlString = System.getProperty("jmx.service.url", jmxServiceUrl);
    JMXServiceURL serviceURL = null;
    JMXConnector connector = null;
    try {
        serviceURL = new JMXServiceURL(urlString);
    } catch (MalformedURLException e1) {
        throw new IllegalStateException(e1);
    }
    // add more tries to get the connection. Workaround to fix some test failures caused by connection is not established in 5 seconds
    for (int i = 0; i < AS_SERVER_CONN_RETRIEVAL_ATTEMPTS && connector == null; i++) {
        try {
            connector = JMXConnectorFactory.connect(serviceURL, null);
        } catch (IOException ex) {
            throw new IllegalStateException("Cannot obtain MBeanServerConnection to: " + urlString, ex);
        } catch (RuntimeException e) {
            if (e.getMessage().contains("WAITING") && i < AS_SERVER_CONN_RETRIEVAL_ATTEMPTS - 1) {
                continue;
            } else {
                throw e;
            }
        }
    }
    try {
        return connector.getMBeanServerConnection();
    } catch (Exception e) {
        throw new IllegalStateException("Cannot obtain MBeanServerConnection to: " + urlString, e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 78 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project fabric8 by fabric8io.

the class RestJsonSchemaJMXTest method connectToMBserver.

private void connectToMBserver() throws IOException {
    jmxServerURL = jmxServerURL == null ? DEFAULT_JMXSERVICE_URL : jmxServerURL;
    JMXServiceURL url = new JMXServiceURL(jmxServerURL);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    mbsc = jmxc.getMBeanServerConnection();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector)

Example 79 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project derby by apache.

the class JMXConnectionDecorator method getJmxUrl.

/**
 * Creates a URL for connecting to the platform MBean server on the host
 * specified by the network server hostname of this test configuration.
 * The JMX port number used is also retreived from the test configuration.
 * @return a service URL for connecting to the platform MBean server
 * @throws MalformedURLException if the URL is malformed
 */
private JMXServiceURL getJmxUrl() throws MalformedURLException {
    // NOTE: This hostname is only valid in a client/server configuration
    String hostname = TestConfiguration.getCurrent().getHostName();
    // String hostname = TestConfiguration.DEFAULT_HOSTNAME; // for embedded?
    int jmxPort = TestConfiguration.getCurrent().getJmxPort();
    /* "jmxrmi" is the name of the RMI server connector of the platform
         * MBean server, which is used by Derby */
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostname + ":" + jmxPort + "/jmxrmi");
    return url;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL)

Example 80 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project bboxdb by jnidzwetzki.

the class Shutdown method main.

/**
 * Call the JMX service to shutdown the application
 *
 * @param args
 */
public static void main(final String[] args) throws Exception {
    if (args.length != 2) {
        System.err.println("Usage: Shutdown <Port> <Password>");
        System.exit(-1);
    }
    final int jmxPort = MathUtil.tryParseIntOrExit(args[0], () -> args[0] + " is not a valid port");
    final String password = args[1];
    // Set username and password
    final Map<String, String[]> env = new HashMap<>();
    final String[] credentials = { "controlRoleUser", password };
    env.put(JMXConnector.CREDENTIALS, credentials);
    // Connect to JMX
    System.out.println("Connecting to JMX shutdown service.");
    final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + jmxPort + "/jmxrmi");
    final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
    final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    final ObjectName mbeanName = new ObjectName(JMXService.MBEAN_LIFECYCLE);
    final LifecycleMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, LifecycleMBean.class, true);
    try {
        mbeanProxy.shutdown();
        jmxc.close();
    } catch (Exception e) {
    // Server performs shutdown, JMX connection will be terminated
    // So, ignore exception
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) LifecycleMBean(org.bboxdb.jmx.LifecycleMBean) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Aggregations

JMXServiceURL (javax.management.remote.JMXServiceURL)280 JMXConnector (javax.management.remote.JMXConnector)150 MBeanServerConnection (javax.management.MBeanServerConnection)107 ObjectName (javax.management.ObjectName)90 IOException (java.io.IOException)78 HashMap (java.util.HashMap)75 MBeanServer (javax.management.MBeanServer)71 JMXConnectorServer (javax.management.remote.JMXConnectorServer)64 MalformedURLException (java.net.MalformedURLException)45 RemoteException (java.rmi.RemoteException)22 Test (org.junit.Test)22 Map (java.util.Map)16 UnknownHostException (java.net.UnknownHostException)14 Properties (java.util.Properties)14 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 MalformedObjectNameException (javax.management.MalformedObjectNameException)13 LocateRegistry (java.rmi.registry.LocateRegistry)12 Registry (java.rmi.registry.Registry)12 ArrayList (java.util.ArrayList)11