Search in sources :

Example 31 with JMXServiceURL

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

the class DaemonRMIExporterTest method main.

public static void main(String[] args) throws Exception {
    Set<Thread> initialNonDaemonThreads = getNonDaemonThreads();
    JMXServiceURL addr = new JMXServiceURL("rmi", null, 0);
    System.out.println("DaemonRMIExporterTest: Creating a RMIConnectorServer on " + addr);
    Map<String, ?> env = Collections.singletonMap("jmx.remote.x.daemon", "true");
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(addr, env, MBeanServerFactory.createMBeanServer());
    server.start();
    System.out.println("DaemonRMIExporterTest: Started the server on " + server.getAddress());
    System.out.println("DaemonRMIExporterTest: Connecting a client to the server ...");
    final JMXConnector conn = JMXConnectorFactory.connect(server.getAddress());
    conn.getMBeanServerConnection().getDefaultDomain();
    System.out.println("DaemonRMIExporterTest: Closing the client ...");
    conn.close();
    System.out.println("DaemonRMIExporterTest No more user code to execute, the VM should " + "exit normally, otherwise will be blocked forever if the bug is not fixed.");
    long deadline = System.currentTimeMillis() + 10000;
    ok: {
        while (System.currentTimeMillis() < deadline) {
            Set<Thread> nonDaemonThreads = getNonDaemonThreads();
            nonDaemonThreads.removeAll(initialNonDaemonThreads);
            if (nonDaemonThreads.isEmpty())
                break ok;
            System.out.println("Non-daemon threads: " + nonDaemonThreads);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
        }
        throw new Exception("TEST FAILED: non-daemon threads remain");
    }
    System.out.println("TEST PASSED");
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) JMXConnectorServer(javax.management.remote.JMXConnectorServer)

Example 32 with JMXServiceURL

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

the class GetConnectionTest method test.

private static boolean test(String proto) throws Exception {
    JMXConnector client;
    try {
        JMXServiceURL url = new JMXServiceURL(proto, null, 0);
        client = JMXConnectorFactory.newJMXConnector(url, null);
    } catch (MalformedURLException e) {
        System.out.println("Protocol " + proto + " not supported, ignoring");
        return true;
    }
    // IOException is expected
    try {
        MBeanServerConnection connection = client.getMBeanServerConnection();
        System.out.println("FAILED: Expected IOException is not thrown.");
        return false;
    } catch (IOException e) {
        System.out.println("PASSED");
        return true;
    }
}
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 33 with JMXServiceURL

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

the class RMIExitTest method test.

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) Notification(javax.management.Notification) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JMXConnectorServer(javax.management.remote.JMXConnectorServer) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener)

Example 34 with JMXServiceURL

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

the class URLTest method main.

public static void main(String[] args) throws Exception {
    System.out.println("Testing that JMXServiceURL accepts the same " + "hosts as java.net.URI");
    System.out.println("(Except that it allows empty host names and " + "forbids a trailing \".\")");
    System.out.println();
    int failures = 0;
    for (int pass = 1; pass <= 2; pass++) {
        final boolean accept = (pass == 1);
        System.out.println("  Hosts that should " + (accept ? "" : "not ") + "work");
        String[] hosts = accept ? good : bad;
        for (int i = 0; i < hosts.length; i++) {
            final String host = hosts[i];
            System.out.print("    " + host + ": ");
            boolean jmxAccept = true;
            try {
                new JMXServiceURL("rmi", hosts[i], 0);
            } catch (MalformedURLException e) {
                jmxAccept = false;
            }
            boolean uriAccept;
            try {
                final URI uri = new URI("http://" + host + "/");
                uriAccept = (uri.getHost() != null);
            } catch (URISyntaxException e) {
                uriAccept = false;
            }
            final int len = host.length();
            if (accept != uriAccept && len != 0 && !(len > 1 && host.charAt(len - 1) == '.' && host.charAt(len - 2) != '.')) {
                // JMXServiceURL allows empty host name; also
                // java.net.URI allows trailing dot in hostname,
                // following RFC 2396, but JMXServiceURL doesn't,
                // following RFC 2609
                System.out.println("TEST BUG: URI accept=" + uriAccept);
                failures++;
            } else {
                if (jmxAccept == accept)
                    System.out.println("OK");
                else {
                    System.out.println("FAILED");
                    failures++;
                }
            }
        }
        System.out.println();
    }
    if (failures == 0)
        System.out.println("Test passed");
    else {
        System.out.println("TEST FAILURES: " + failures);
        System.exit(1);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 35 with JMXServiceURL

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

the class RMIConnectorLogAttributesTest method connectToServer.

private JMXConnector connectToServer(JMXConnectorServer server) throws IOException, MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException {
    JMXServiceURL url = server.getAddress();
    Map<String, Object> env = new HashMap<String, Object>();
    JMXConnector connector = JMXConnectorFactory.connect(url, env);
    System.out.println("DEBUG: Client connected to RMI at: " + url);
    return connector;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector)

Aggregations

JMXServiceURL (javax.management.remote.JMXServiceURL)273 JMXConnector (javax.management.remote.JMXConnector)146 MBeanServerConnection (javax.management.MBeanServerConnection)107 ObjectName (javax.management.ObjectName)90 IOException (java.io.IOException)75 HashMap (java.util.HashMap)75 MBeanServer (javax.management.MBeanServer)70 JMXConnectorServer (javax.management.remote.JMXConnectorServer)64 MalformedURLException (java.net.MalformedURLException)45 RemoteException (java.rmi.RemoteException)22 Test (org.junit.Test)20 Map (java.util.Map)16 UnknownHostException (java.net.UnknownHostException)14 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 Properties (java.util.Properties)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)13 LocateRegistry (java.rmi.registry.LocateRegistry)12 Registry (java.rmi.registry.Registry)12 ArrayList (java.util.ArrayList)11