Search in sources :

Example 61 with JMXConnectorServer

use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.

the class RMIConnectorNullSubjectConnTest method main.

public static void main(String[] args) throws Exception {
    System.out.println("---RMIConnectorNullSubjectConnTest starting...");
    JMXConnectorServer connectorServer = null;
    JMXConnector connectorClient = null;
    try {
        MBeanServer mserver = ManagementFactory.getPlatformMBeanServer();
        JMXServiceURL serverURL = new JMXServiceURL("rmi", "localhost", 0);
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, null, mserver);
        connectorServer.start();
        JMXServiceURL serverAddr = connectorServer.getAddress();
        connectorClient = JMXConnectorFactory.connect(serverAddr, null);
        connectorClient.connect();
        Field nullSubjectConnField = RMIConnector.class.getDeclaredField("nullSubjectConnRef");
        nullSubjectConnField.setAccessible(true);
        WeakReference<MBeanServerConnection> weak = (WeakReference<MBeanServerConnection>) nullSubjectConnField.get(connectorClient);
        if (weak != null && weak.get() != null) {
            throw new RuntimeException("nullSubjectConnRef must be null at initial time.");
        }
        MBeanServerConnection conn1 = connectorClient.getMBeanServerConnection(null);
        MBeanServerConnection conn2 = connectorClient.getMBeanServerConnection(null);
        if (conn1 == null) {
            throw new RuntimeException("A connection with null subject should not be null.");
        } else if (conn1 != conn2) {
            throw new RuntimeException("The 2 connections with null subject are not equal.");
        }
        conn1 = null;
        conn2 = null;
        int i = 1;
        do {
            System.gc();
            Thread.sleep(100);
            weak = (WeakReference<MBeanServerConnection>) nullSubjectConnField.get(connectorClient);
        } while ((weak != null && weak.get() != null) && i++ < 60);
        System.out.println("---GC times: " + i);
        if (weak != null && weak.get() != null) {
            throw new RuntimeException("Failed to clean RMIConnector's nullSubjectConn");
        } else {
            System.out.println("---RMIConnectorNullSubjectConnTest: PASSED!");
        }
    } finally {
        try {
            connectorClient.close();
            connectorServer.stop();
        } catch (Exception e) {
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Field(java.lang.reflect.Field) JMXConnector(javax.management.remote.JMXConnector) WeakReference(java.lang.ref.WeakReference) MBeanServerConnection(javax.management.MBeanServerConnection) JMXConnectorServer(javax.management.remote.JMXConnectorServer) MBeanServer(javax.management.MBeanServer)

Example 62 with JMXConnectorServer

use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.

the class MapNullValuesTest method nullKeyFactoryTests.

private int nullKeyFactoryTests() {
    int errorCount = 0;
    echo("");
    echo(dashedMessage("Run Null Key Factory Tests"));
    echo("\tMap = " + map3);
    try {
        String urlStr = "service:jmx:rmi:///jndi/rmi://:" + port + "/NullKeyFactory";
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
        JMXServiceURL url = null;
        JMXConnectorServer jmxcs = null;
        JMXConnector jmxc = null;
        echo("\tJMXConnectorServerFactory.newJMXConnectorServer()");
        try {
            url = new JMXServiceURL(urlStr + "1");
            jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, map3, mbs);
            errorCount++;
            echo("\tTest FAILED!");
        } catch (Exception e) {
            echo("\tException Message: " + e.getMessage());
            echo("\tTest PASSED!");
        }
        echo("\tJMXConnectorServerFactory.toJMXConnector()");
        try {
            url = new JMXServiceURL(urlStr + "2");
            jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
            jmxcs.start();
            jmxcs.toJMXConnector(map3);
            errorCount++;
            echo("\tTest FAILED!");
        } catch (Exception e) {
            echo("\tException Message: " + e.getMessage());
            echo("\tTest PASSED!");
        } finally {
            jmxcs.stop();
        }
        echo("\tJMXConnectorFactory.newJMXConnector()");
        try {
            url = new JMXServiceURL(urlStr + "3");
            jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
            jmxcs.start();
            jmxc = JMXConnectorFactory.newJMXConnector(jmxcs.getAddress(), map3);
            errorCount++;
            echo("\tTest FAILED!");
        } catch (Exception e) {
            echo("\tException Message: " + e.getMessage());
            echo("\tTest PASSED!");
        } finally {
            jmxcs.stop();
        }
        echo("\tJMXConnectorFactory.connect()");
        try {
            url = new JMXServiceURL(urlStr + "4");
            jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
            jmxcs.start();
            jmxc = JMXConnectorFactory.connect(jmxcs.getAddress(), map3);
            errorCount++;
            echo("\tTest FAILED!");
        } catch (Exception e) {
            echo("\tException Message: " + e.getMessage());
            echo("\tTest PASSED!");
        } finally {
            jmxcs.stop();
        }
        echo("\tJMXConnector.connect()");
        try {
            url = new JMXServiceURL(urlStr + "5");
            jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
            jmxcs.start();
            jmxc = JMXConnectorFactory.newJMXConnector(jmxcs.getAddress(), null);
            jmxc.connect(map3);
            errorCount++;
            echo("\tTest FAILED!");
        } catch (Exception e) {
            echo("\tException Message: " + e.getMessage());
            echo("\tTest PASSED!");
        } finally {
            jmxcs.stop();
        }
    } catch (Exception e) {
        echo("\tGot unexpected exception!");
        e.printStackTrace(System.out);
        errorCount = 1;
    }
    if (errorCount == 0) {
        echo("");
        echo(dashedMessage("Null Key Factory Tests PASSED!"));
    } else {
        echo("");
        echo(dashedMessage("Null Key Factory Tests FAILED!"));
    }
    return errorCount;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) RemoteException(java.rmi.RemoteException) MBeanServer(javax.management.MBeanServer) JMXConnectorServer(javax.management.remote.JMXConnectorServer)

Example 63 with JMXConnectorServer

use of javax.management.remote.JMXConnectorServer in project jdk8u_jdk by JetBrains.

the class MapNullValuesTest method jmxConnectorFactoryTests.

private int jmxConnectorFactoryTests() {
    int errorCount = 0;
    echo("");
    echo(dashedMessage("Run JMXConnectorFactory Tests"));
    for (int i = 0; i < maps.length - 1; i++) {
        echo("\n>>> JMXConnectorFactory Test [" + i + "]");
        try {
            echo("\tMap = " + maps[i]);
            echo("\tCreate the MBean server");
            MBeanServer mbs = MBeanServerFactory.createMBeanServer();
            echo("\tCreate the RMI connector server");
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + port + "/JMXConnectorFactory" + i);
            JMXConnectorServer jmxcs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
            echo("\tStart the RMI connector server");
            jmxcs.start();
            echo("\tCreate and connect the RMI connector");
            JMXConnector jmxc = JMXConnectorFactory.connect(jmxcs.getAddress(), maps[i]);
            echo("\tClose the RMI connector");
            jmxc.close();
            echo("\tTest [" + i + "] PASSED!");
        } catch (Exception e) {
            errorCount++;
            echo("\tTest [" + i + "] FAILED!");
            e.printStackTrace(System.out);
        }
    }
    if (errorCount == 0) {
        echo("");
        echo(dashedMessage("JMXConnectorFactory Tests PASSED!"));
    } else {
        echo("");
        echo(dashedMessage("JMXConnectorFactory Tests FAILED!"));
    }
    return errorCount;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) RemoteException(java.rmi.RemoteException) MBeanServer(javax.management.MBeanServer) JMXConnectorServer(javax.management.remote.JMXConnectorServer)

Aggregations

JMXConnectorServer (javax.management.remote.JMXConnectorServer)63 JMXServiceURL (javax.management.remote.JMXServiceURL)57 JMXConnector (javax.management.remote.JMXConnector)47 MBeanServer (javax.management.MBeanServer)44 MBeanServerConnection (javax.management.MBeanServerConnection)38 ObjectName (javax.management.ObjectName)31 HashMap (java.util.HashMap)24 IOException (java.io.IOException)13 MalformedURLException (java.net.MalformedURLException)13 RemoteException (java.rmi.RemoteException)13 NotificationListener (javax.management.NotificationListener)12 Notification (javax.management.Notification)11 Attribute (javax.management.Attribute)9 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7 Map (java.util.Map)7 Properties (java.util.Properties)7 JMXPluggableAuthenticator (com.sun.jmx.remote.security.JMXPluggableAuthenticator)5 UnknownHostException (java.net.UnknownHostException)5 Test (org.junit.Test)5