Search in sources :

Example 66 with JMXConnector

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

Example 67 with JMXConnector

use of javax.management.remote.JMXConnector in project druid by alibaba.

the class DruidStat method printDruidStat.

@SuppressWarnings("all")
public static void printDruidStat(Option option) throws Exception {
    PrintStream out = option.getPrintStream();
    String address = loadManagementAgentAndGetAddress(option.getPid());
    JMXServiceURL jmxUrl = new JMXServiceURL(address);
    JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl);
    MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection();
    if (option.printDataSourceData()) {
        List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.DATA_SOURCE);
        TabledDataPrinter.printDataSourceData(content, option);
    }
    if (option.printSqlData()) {
        List<Map<String, Object>> content = (List<Map<String, Object>>) invokeService(jmxConn, Option.SQL);
        if (content == null) {
            out.println("无SqlStat统计数据,请检查是否已执行了SQL");
        } else {
            TabledDataPrinter.printSqlData(content, option);
        }
    }
    if (option.printActiveConn()) {
        List<List<String>> content = (List<List<String>>) invokeService(jmxConn, Option.ACTIVE_CONN);
        if (content == null || content.size() == 0) {
            out.println("目前无活动中的数据库连接");
        } else {
            TabledDataPrinter.printActiveConnStack(content, option);
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) PrintStream(java.io.PrintStream) JMXConnector(javax.management.remote.JMXConnector) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 68 with JMXConnector

use of javax.management.remote.JMXConnector in project otter by alibaba.

the class JmxLoaderIntegration method test_simple.

@Test
public void test_simple() {
    MBeanServer mBeanServer = exporter.getServer();
    try {
        ObjectName objectName = new ObjectName("bean:name=otterControllor");
        MBeanInfo nodeInfo = mBeanServer.getMBeanInfo(objectName);
        System.out.println(nodeInfo);
        Object result = mBeanServer.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);
        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/mbean");
        Map environment = null;
        JMXConnector cntor = JMXConnectorFactory.connect(address, environment);
        MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
        String domain = mbsc.getDefaultDomain();
        System.out.println(domain);
        result = mbsc.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);
    } catch (Exception e) {
        want.fail(e.getMessage());
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MBeanInfo(javax.management.MBeanInfo) JMXConnector(javax.management.remote.JMXConnector) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection) RemoteException(java.rmi.RemoteException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.node.etl.BaseOtterTest)

Example 69 with JMXConnector

use of javax.management.remote.JMXConnector in project spring-framework by spring-projects.

the class ConnectorServerFactoryBeanTests method checkServerConnection.

private void checkServerConnection(MBeanServer hostedServer) throws IOException, MalformedURLException {
    // Try to connect using client.
    JMXServiceURL serviceURL = new JMXServiceURL(ConnectorServerFactoryBean.DEFAULT_SERVICE_URL);
    JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
    assertNotNull("Client Connector should not be null", connector);
    // Get the MBean server connection.
    MBeanServerConnection connection = connector.getMBeanServerConnection();
    assertNotNull("MBeanServerConnection should not be null", connection);
    // Test for MBean server equality.
    assertEquals("Registered MBean count should be the same", hostedServer.getMBeanCount(), connection.getMBeanCount());
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 70 with JMXConnector

use of javax.management.remote.JMXConnector in project opennms by OpenNMS.

the class JmxCommand method execute.

protected void execute() throws CmdLineException, CmdRunException {
    try (JMXConnector connector = getJmxConnector()) {
        MBeanServerConnection mbeanServerConnection = connector.getMBeanServerConnection();
        execute(mbeanServerConnection);
    } catch (MBeanServerQueryException | JMException | IOException e) {
        throw new CmdRunException(e);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerQueryException(org.opennms.features.jmxconfiggenerator.jmxconfig.query.MBeanServerQueryException) JMException(javax.management.JMException) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

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