Search in sources :

Example 61 with JMXConnector

use of javax.management.remote.JMXConnector in project jvm-tools by aragozin.

the class JmxConnectionInfo method connectJmx.

@SuppressWarnings("resource")
private MBeanServerConnection connectJmx(String host, int port, Map<String, Object> props) {
    try {
        String proto = System.getProperty("jmx.service.protocol", "rmi");
        final String uri = "rmi".equals(proto) ? "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" : "service:jmx:" + proto + "://" + host + ":" + port;
        JMXServiceURL jmxurl = new JMXServiceURL(uri);
        JMXConnector conn = props == null ? JMXConnectorFactory.connect(jmxurl) : JMXConnectorFactory.connect(jmxurl, props);
        // TODO credentials
        MBeanServerConnection mserver = conn.getMBeanServerConnection();
        return mserver;
    } catch (MalformedURLException e) {
        commandHost.fail("JMX Connection failed: " + e.toString(), e);
    } catch (IOException e) {
        commandHost.fail("JMX Connection failed: " + e.toString(), e);
    }
    return null;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 62 with JMXConnector

use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.

the class TreeWalker method main.

public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("localhost").setPort("1099").build();
    JMXConnector conn = null;
    try {
        conn = server.getServerConnection();
        MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
        TreeWalker tw = new TreeWalker();
        tw.walkTree(mbeanServer);
    } catch (IOException e) {
        log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 63 with JMXConnector

use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.

the class TreeWalker2 method main.

/** */
public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("localhost").setPort("1099").build();
    JMXConnector conn = null;
    try {
        conn = server.getServerConnection();
        MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
        TreeWalker2 tw = new TreeWalker2();
        tw.walkTree(mbeanServer, server);
    } catch (IOException e) {
        log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 64 with JMXConnector

use of javax.management.remote.JMXConnector in project jmxtrans by jmxtrans.

the class TreeWalker3 method main.

/** */
public static void main(String[] args) throws Exception {
    Server server = Server.builder().setHost("w2").setPort("1105").build();
    JMXConnector conn = null;
    try {
        conn = server.getServerConnection();
        MBeanServerConnection mbeanServer = conn.getMBeanServerConnection();
        TreeWalker3 tw = new TreeWalker3();
        tw.walkTree(mbeanServer, server);
    } catch (IOException e) {
        log.error("Problem processing queries for server: " + server.getHost() + ":" + server.getPort(), e);
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Server(com.googlecode.jmxtrans.model.Server) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 65 with JMXConnector

use of javax.management.remote.JMXConnector in project jvm-breakglass by matlux.

the class MBeanTest method testStartStopViaJMX.

@Test
public void testStartStopViaJMX() throws Exception {
    int port = 9876;
    JMXServiceURL url = new JMXServiceURL(String.format("service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi", port));
    JMXConnectorServer jmxServer = createJMXServer(port, url);
    try {
        jmxServer.start();
        assertFalse(nreplServer.isStarted());
        JMXConnector connector = JMXConnectorFactory.connect(url);
        try {
            MBeanServerConnection conn = connector.getMBeanServerConnection();
            ObjectName objectName = MBeanRegistration.getObjectName();
            NreplMBean proxy = JMX.newMBeanProxy(conn, objectName, NreplMBean.class);
            assertFalse(proxy.isStarted());
            proxy.start();
            assertTrue(proxy.isStarted());
            proxy.stop();
            assertFalse(proxy.isStarted());
        } finally {
            connector.close();
        }
    } finally {
        jmxServer.stop();
    }
    assertFalse(nreplServer.isStarted());
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) JMXConnectorServer(javax.management.remote.JMXConnectorServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

JMXConnector (javax.management.remote.JMXConnector)118 MBeanServerConnection (javax.management.MBeanServerConnection)85 JMXServiceURL (javax.management.remote.JMXServiceURL)78 ObjectName (javax.management.ObjectName)54 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 MBeanServer (javax.management.MBeanServer)37 IOException (java.io.IOException)35 HashMap (java.util.HashMap)27 Test (org.junit.Test)22 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 Attribute (javax.management.Attribute)13 MalformedURLException (java.net.MalformedURLException)12 RemoteException (java.rmi.RemoteException)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 LocateRegistry (java.rmi.registry.LocateRegistry)8 Registry (java.rmi.registry.Registry)8 Properties (java.util.Properties)7