Java Code Examples for javax.management.remote.JMXConnectorFactory#newJMXConnector()

The following examples show how to use javax.management.remote.JMXConnectorFactory#newJMXConnector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 2
Source File: ProviderTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 3
Source File: ProviderTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 4
Source File: ProviderTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 5
Source File: ProviderTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 6
Source File: MBeanWrapper.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
MBeanWrapper( int jvmPort ) throws MonitorConfigurationException {

        this.jvmPort = jvmPort;
        try {
            JMXConnector connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"
                                                                                           + this.jvmPort
                                                                                           + "/jmxrmi"),
                                                                         null);
            connector.connect();

            this.connection = connector.getMBeanServerConnection();
        } catch (Exception e) {
            final String msg = "Error initializing the JMV monitor. Unable to connect to JVM at port "
                               + this.jvmPort;
            log.error(msg, e);
            throw new MonitorConfigurationException(msg, e);
        }
    }
 
Example 7
Source File: ProviderTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 8
Source File: ProviderTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 9
Source File: ProviderTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 10
Source File: ProviderTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 11
Source File: ProviderTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
Example 12
Source File: RMIExitTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 13
Source File: RMIExitTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 14
Source File: RMIExitTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 15
Source File: RMIExitTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 16
Source File: RMIExitTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 17
Source File: RMIExitTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 18
Source File: MemoryConsumptionTestClient.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private MemoryStatistic collectMemoryStatistics(Map<String, String> options) throws Exception
{
    String host = options.get(JMX_HOST_ARG);
    String port = options.get(JMX_PORT_ARG);
    String user = options.get(JMX_USER_ARG);
    String password = options.get(JMX_USER_PASSWORD_ARG);

    if (!"".equals(host) && !"".equals(port) && !"".equals(user) && !"".equals(password))
    {
        Map<String, Object> environment = Collections.<String, Object>singletonMap(JMXConnector.CREDENTIALS, new String[]{user, password});

        try(JMXConnector jmxConnector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ":" + port + "/jmxrmi"), environment))
        {
            jmxConnector.connect();
            final MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
            final ObjectName memoryMBean = new ObjectName("java.lang:type=Memory");
            String gcCollectorMBeanName = options.get(JMX_GARBAGE_COLLECTOR_MBEAN);
            if (gcCollectorMBeanName.equals(""))
            {
                mBeanServerConnection.invoke(memoryMBean, "gc", null, null);
                MemoryStatistic memoryStatistics = new MemoryStatistic();
                collectMemoryStatistics(memoryStatistics, mBeanServerConnection, memoryMBean);
                return memoryStatistics;
            }
            else
            {
                ObjectName gcMBean = new ObjectName(gcCollectorMBeanName);
                if (mBeanServerConnection.isRegistered(gcMBean))
                {
                    return collectMemoryStatisticsAfterGCNotification(mBeanServerConnection, gcMBean);
                }
                else
                {
                    Set<ObjectName> existingGCs = mBeanServerConnection.queryNames(new ObjectName("java.lang:type=GarbageCollector,name=*"), null);
                    throw new IllegalArgumentException("MBean '" +gcCollectorMBeanName + "' does not exists! Registered GC MBeans :" + existingGCs);
                }
            }
        }
    }
    return null;
}
 
Example 19
Source File: RMIExitTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
Example 20
Source File: RMIExitTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}