Search in sources :

Example 71 with MBeanServerConnection

use of javax.management.MBeanServerConnection 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 72 with MBeanServerConnection

use of javax.management.MBeanServerConnection 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 73 with MBeanServerConnection

use of javax.management.MBeanServerConnection 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 74 with MBeanServerConnection

use of javax.management.MBeanServerConnection 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)

Example 75 with MBeanServerConnection

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

the class MBeanTest method testStartViaJMX.

@Test
public void testStartViaJMX() throws Exception {
    int port = 9875;
    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());
        } finally {
            connector.close();
        }
        assertTrue(nreplServer.isStarted());
    } finally {
        jmxServer.stop();
    }
}
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

MBeanServerConnection (javax.management.MBeanServerConnection)125 JMXConnector (javax.management.remote.JMXConnector)84 ObjectName (javax.management.ObjectName)73 JMXServiceURL (javax.management.remote.JMXServiceURL)59 JMXConnectorServer (javax.management.remote.JMXConnectorServer)38 Test (org.junit.Test)35 IOException (java.io.IOException)31 MBeanServer (javax.management.MBeanServer)28 HashMap (java.util.HashMap)23 Attribute (javax.management.Attribute)15 NotificationListener (javax.management.NotificationListener)13 MalformedURLException (java.net.MalformedURLException)12 ArrayList (java.util.ArrayList)12 Notification (javax.management.Notification)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Map (java.util.Map)10 List (java.util.List)8 RemoteException (java.rmi.RemoteException)7 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7