Java Code Examples for javax.management.remote.JMXConnectorServer#start()

The following examples show how to use javax.management.remote.JMXConnectorServer#start() . 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-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 2
Source File: ListenerScaleTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    Sender sender = new Sender();
    mbs.registerMBean(sender, testObjectName);
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    try {
        test(mbs, cs, cc);
    } finally {
        cc.close();
        cs.stop();
    }
}
 
Example 3
Source File: ProviderTest.java    From jdk8u-dev-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 4
Source File: IIOPURLTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    JMXServiceURL inputAddr =
        new JMXServiceURL("service:jmx:iiop://");
    JMXConnectorServer s;
    try {
        s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
    } catch (java.net.MalformedURLException x) {
        try {
            Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
            throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
        } catch (ClassNotFoundException expected) { }
        System.out.println("IIOP protocol not supported, test skipped");
        return;
    }
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    mbs.registerMBean(s, new ObjectName("a:b=c"));
    s.start();
    JMXServiceURL outputAddr = s.getAddress();
    if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
        throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +
                                   outputAddr);
    }
    System.out.println("IIOP URL path looks OK: " + outputAddr);
    JMXConnector c = JMXConnectorFactory.connect(outputAddr);
    System.out.println("Successfully got default domain: " +
                       c.getMBeanServerConnection().getDefaultDomain());
    c.close();
    s.stop();
}
 
Example 5
Source File: RMIDownloadTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testWithException(boolean send)
throws Exception {
    ClassLoader zoobyCL = new ZoobyClassLoader();
    Class<?> zoobyClass = Class.forName("Zooby", false, zoobyCL);
    Object zooby = zoobyClass.newInstance();

    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, null, pmbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    MBeanServerConnection mbsc = cc.getMBeanServerConnection();

    Object rzooby;
    if (send) {
        System.out.println("Sending object...");
        mbsc.setAttribute(getSetName, new Attribute("It", zooby));
        rzooby = getSetInstance.getIt();
    } else {
        System.out.println("Receiving object...");
        getSetInstance.setIt(zooby);
        rzooby = mbsc.getAttribute(getSetName, "It");
    }

    if (!rzooby.getClass().getName().equals("Zooby")) {
        throw new Exception("FAILED: remote object is not a Zooby");
    }
    if (rzooby.getClass().getClassLoader() ==
            zooby.getClass().getClassLoader()) {
        throw new Exception("FAILED: same class loader: " +
                zooby.getClass().getClassLoader());
    }

    cc.close();
    cs.stop();
}
 
Example 6
Source File: Server.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
   // The MBeanServer
   MBeanServer server = MBeanServerFactory.createMBeanServer();

   // Pass null as the host name to tell JMXServiceURL to default to InetAddress.getLocalHost().getHostName()
   JMXServiceURL url = new JMXServiceURL("soap", null, 8080, "/jmxconnector");

   // Create and start the connector server
   // Jetty will listen on port 8080
   JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
   connectorServer.start();

   System.out.println("Server up and running " + connectorServer);
}
 
Example 7
Source File: IIOPURLTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    JMXServiceURL inputAddr =
        new JMXServiceURL("service:jmx:iiop://");
    JMXConnectorServer s;
    try {
        s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
    } catch (java.net.MalformedURLException x) {
        try {
            Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
            throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
        } catch (ClassNotFoundException expected) { }
        System.out.println("IIOP protocol not supported, test skipped");
        return;
    }
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    mbs.registerMBean(s, new ObjectName("a:b=c"));
    s.start();
    JMXServiceURL outputAddr = s.getAddress();
    if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
        throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +
                                   outputAddr);
    }
    System.out.println("IIOP URL path looks OK: " + outputAddr);
    JMXConnector c = JMXConnectorFactory.connect(outputAddr);
    System.out.println("Successfully got default domain: " +
                       c.getMBeanServerConnection().getDefaultDomain());
    c.close();
    s.stop();
}
 
Example 8
Source File: DaemonRMIExporterTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 9
Source File: MapNullValuesTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 10
Source File: MultiThreadDeadLockTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    print("Create the MBean server");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();

    print("Initialize environment map");
    HashMap env = new HashMap();

    print("Specify a client socket factory to control socket creation.");
    env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE,
            clientFactory);

    print("Specify a server idle timeout to make a server close an idle connection.");
    env.put("jmx.remote.x.server.connection.timeout", serverTimeout);

    print("Disable client heartbeat.");
    env.put("jmx.remote.x.client.connection.check.period", 0);

    env.put("jmx.remote.x.notification.fetch.timeout", serverTimeout);

    print("Create an RMI server");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer server =
            JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
    server.start();

    url = server.getAddress();

    print("Create jmx client on "+url);
    StateMachine.setState(CREATE_SOCKET); // allow to create client socket
    client = JMXConnectorFactory.connect(url, env);
    Thread.sleep(100);

    totoName = new ObjectName("default:name=toto");
    mbs.registerMBean(toto, totoName);
    print("Register the mbean: " + totoName);

    print("Add listener to toto MBean");
    client.getMBeanServerConnection().addNotificationListener(
            totoName, myListener, null, null);
    Thread.sleep(10);

    print("send notif, listener will block the fetcher");
    toto.sendNotif();
    Thread.sleep(100);

    StateMachine.setState(NO_OP);

    print("Sleep 3 times of server idle timeout: "+serverTimeout+
            ", the sever should close the idle connection.");
    Thread.sleep(serverTimeout*3);

    print("start the user thread to call mbean method, it will get IOexception" +
            " and start the reconnection, the socket factory will block the" +
            " socket creation.");
    UserThread ut = new UserThread();
    ut.start();
    Thread.sleep(10);

    print("Free the listener, the fetcher will get IO and makes " +
            "a deadlock if the bug is not fixed.");
    StateMachine.setState(FREE_LISTENER);
    Thread.sleep(100);

    print("Allow to create new socket for the reconnection");
    StateMachine.setState(CREATE_SOCKET);

    print("Check whether the user thread gets free to call the mbean.");
    if (!ut.waitDone(5000)) {
        throw new RuntimeException("Possible deadlock!");
    }

    print("Remove the listener.");
    client.getMBeanServerConnection().removeNotificationListener(
            totoName, myListener, null, null);
    Thread.sleep(serverTimeout*3);

    print("\nWell passed, bye!");

    client.close();
    Thread.sleep(10);
    server.stop();
}
 
Example 11
Source File: EmptyDomainNotificationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

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

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

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        synchronized(li) {
            while (li.received < 1) {
                li.wait();
            }
        }

        if (li.received != 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
Example 12
Source File: RMIConnectorInternalMapTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println("---RMIConnectorInternalMapTest 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 rmbscMapField = RMIConnector.class.getDeclaredField("rmbscMap");
        rmbscMapField.setAccessible(true);
        Map<Subject, WeakReference<MBeanServerConnection>> map =
                (Map<Subject, WeakReference<MBeanServerConnection>>) rmbscMapField.get(connectorClient);
        if (map != null && !map.isEmpty()) { // failed
            throw new RuntimeException("RMIConnector's rmbscMap must be empty at the initial time.");
        }

        Subject delegationSubject =
                new Subject(true,
                Collections.singleton(new JMXPrincipal("delegate")),
                Collections.EMPTY_SET,
                Collections.EMPTY_SET);
        MBeanServerConnection mbsc1 =
                connectorClient.getMBeanServerConnection(delegationSubject);
        MBeanServerConnection mbsc2 =
                connectorClient.getMBeanServerConnection(delegationSubject);

        if (mbsc1 == null) {
            throw new RuntimeException("Got null connection.");
        }
        if (mbsc1 != mbsc2) {
            throw new RuntimeException("Not got same connection with a same subject.");
        }

        map = (Map<Subject, WeakReference<MBeanServerConnection>>) rmbscMapField.get(connectorClient);
        if (map == null || map.isEmpty()) { // failed
            throw new RuntimeException("RMIConnector's rmbscMap has wrong size "
                    + "after creating a delegated connection.");
        }

        delegationSubject = null;
        mbsc1 = null;
        mbsc2 = null;

        int i = 0;
        while (!map.isEmpty() && i++ < 60) {
            System.gc();
            Thread.sleep(100);
        }
        System.out.println("---GC times: " + i);

        if (!map.isEmpty()) {
            throw new RuntimeException("Failed to clean RMIConnector's rmbscMap");
        } else {
            System.out.println("---RMIConnectorInternalMapTest: PASSED!");
        }
    } finally {
        try {
            connectorClient.close();
            connectorServer.stop();
        } catch (Exception e) {
        }
    }
}
 
Example 13
Source File: EmptyDomainNotificationTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

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

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

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        final long stopTime = System.currentTimeMillis() + 2000;
        synchronized(li) {
            long toWait = stopTime - System.currentTimeMillis();

            while (li.received < 1 && toWait > 0) {
                li.wait(toWait);

                toWait = stopTime - System.currentTimeMillis();
            }
        }

        if (li.received < 1) {
            throw new RuntimeException("No notif received!");
        } else if (li.received > 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
Example 14
Source File: RMIConnectorInternalMapTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println("---RMIConnectorInternalMapTest 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 rmbscMapField = RMIConnector.class.getDeclaredField("rmbscMap");
        rmbscMapField.setAccessible(true);
        Map<Subject, WeakReference<MBeanServerConnection>> map =
                (Map<Subject, WeakReference<MBeanServerConnection>>) rmbscMapField.get(connectorClient);
        if (map != null && !map.isEmpty()) { // failed
            throw new RuntimeException("RMIConnector's rmbscMap must be empty at the initial time.");
        }

        Subject delegationSubject =
                new Subject(true,
                Collections.singleton(new JMXPrincipal("delegate")),
                Collections.EMPTY_SET,
                Collections.EMPTY_SET);
        MBeanServerConnection mbsc1 =
                connectorClient.getMBeanServerConnection(delegationSubject);
        MBeanServerConnection mbsc2 =
                connectorClient.getMBeanServerConnection(delegationSubject);

        if (mbsc1 == null) {
            throw new RuntimeException("Got null connection.");
        }
        if (mbsc1 != mbsc2) {
            throw new RuntimeException("Not got same connection with a same subject.");
        }

        map = (Map<Subject, WeakReference<MBeanServerConnection>>) rmbscMapField.get(connectorClient);
        if (map == null || map.isEmpty()) { // failed
            throw new RuntimeException("RMIConnector's rmbscMap has wrong size "
                    + "after creating a delegated connection.");
        }

        delegationSubject = null;
        mbsc1 = null;
        mbsc2 = null;

        int i = 0;
        while (!map.isEmpty() && i++ < 60) {
            System.gc();
            Thread.sleep(100);
        }
        System.out.println("---GC times: " + i);

        if (!map.isEmpty()) {
            throw new RuntimeException("Failed to clean RMIConnector's rmbscMap");
        } else {
            System.out.println("---RMIConnectorInternalMapTest: PASSED!");
        }
    } finally {
        try {
            connectorClient.close();
            connectorServer.stop();
        } catch (Exception e) {
        }
    }
}
 
Example 15
Source File: RMIConnectorNullSubjectConnTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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) {
        }
    }
}
 
Example 16
Source File: MapNullValuesTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 17
Source File: MBSFPreStartPostStartTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Run test
 */
public int runTest(boolean setBeforeStart) throws Exception {

    echo("=-=-= MBSFPreStartPostStartTest: Set MBSF " +
         (setBeforeStart ? "before" : "after") +
         " starting the connector server =-=-=");

    JMXConnectorServer server = null;
    JMXConnector client = null;

    // Create a new MBeanServer
    //
    final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

    try {
        // Create the JMXServiceURL
        //
        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        // Create a JMXConnectorServer
        //
        server = JMXConnectorServerFactory.newJMXConnectorServer(url,
                                                                 null,
                                                                 mbs);

        // Create MBeanServerForwarder
        //
        MBeanServerForwarder mbsf =
            MBSFInvocationHandler.newProxyInstance();

        // Set MBeanServerForwarder before start()
        //
        if (setBeforeStart)
            server.setMBeanServerForwarder(mbsf);

        // Start the JMXConnectorServer
        //
        server.start();

        // Set MBeanServerForwarder after start()
        //
        if (!setBeforeStart)
            server.setMBeanServerForwarder(mbsf);

        // Create a JMXConnector
        //
        client = server.toJMXConnector(null);

        // Connect to the connector server
        //
        client.connect(null);

        // Get non-secure MBeanServerConnection
        //
        final MBeanServerConnection mbsc =
            client.getMBeanServerConnection();

        // Run method
        //
        mbsc.getDefaultDomain();

        // Check flag in MBeanServerForwarder
        //
        MBSFInvocationHandler mbsfih =
            (MBSFInvocationHandler) Proxy.getInvocationHandler(mbsf);
        if (mbsfih.getFlag() == true) {
            echo("OK: Did go into MBeanServerForwarder!");
        } else {
            echo("KO: Didn't go into MBeanServerForwarder!");
            return 1;
        }
    } catch (Exception e) {
        echo("Failed to perform operation: " + e);
        return 1;
    } finally {
        // Close the connection
        //
        if (client != null)
            client.close();

        // Stop the connector server
        //
        if (server != null)
            server.stop();

        // Release the MBeanServer
        //
        if (mbs != null)
            MBeanServerFactory.releaseMBeanServer(mbs);
    }

    return 0;
}
 
Example 18
Source File: RMIExporterTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {

        try {
            // Instantiate the MBean server
            //
            System.out.println("Create the MBean server");
            MBeanServer mbs = MBeanServerFactory.createMBeanServer();

            // Initialize environment map to be passed to the connector server
            //
            System.out.println("Initialize environment map");
            HashMap env = new HashMap();
            CustomRMIExporter exporter = new CustomRMIExporter();
            env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);

            // Create an RMI connector server
            //
            System.out.println("Create an RMI connector server");
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
            JMXConnectorServer cs =
                JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
            cs.start();

            // Create an RMI connector client
            //
            System.out.println("Create an RMI connector client");
            JMXConnector cc =
                JMXConnectorFactory.connect(cs.getAddress(), null);

            // Close RMI connector client
            //
            System.out.println("Close the RMI connector client");
            cc.close();

            // Stop RMI connector server
            //
            System.out.println("Stop the RMI connector server");
            cs.stop();

            // Check if remote objects were exported/unexported successfully
            //
            int errorCount = 0;

            if (exporter.rmiServerExported) {
                System.out.println("RMIServer exported OK!");
            } else {
                System.out.println("RMIServer exported KO!");
                errorCount++;
            }

            if (exporter.rmiServerUnexported) {
                System.out.println("RMIServer unexported OK!");
            } else {
                System.out.println("RMIServer unexported KO!");
                errorCount++;
            }

            if (exporter.rmiConnectionExported) {
                System.out.println("RMIConnection exported OK!");
            } else {
                System.out.println("RMIConnection exported KO!");
                errorCount++;
            }

            if (exporter.rmiConnectionUnexported) {
                System.out.println("RMIConnection unexported OK!");
            } else {
                System.out.println("RMIConnection unexported KO!");
                errorCount++;
            }

            System.out.println("Bye! Bye!");

            if (errorCount > 0) {
                System.out.println("RMIExporterTest FAILED!");
                System.exit(1);
            } else {
                System.out.println("RMIExporterTest PASSED!");
            }
        } catch (Exception e) {
            System.out.println("Unexpected exception caught = " + e);
            e.printStackTrace();
            System.exit(1);
        }
    }
 
Example 19
Source File: RMIExporterTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {

        try {
            // Instantiate the MBean server
            //
            System.out.println("Create the MBean server");
            MBeanServer mbs = MBeanServerFactory.createMBeanServer();

            // Initialize environment map to be passed to the connector server
            //
            System.out.println("Initialize environment map");
            HashMap env = new HashMap();
            CustomRMIExporter exporter = new CustomRMIExporter();
            env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);

            // Create an RMI connector server
            //
            System.out.println("Create an RMI connector server");
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
            JMXConnectorServer cs =
                JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
            cs.start();

            // Create an RMI connector client
            //
            System.out.println("Create an RMI connector client");
            JMXConnector cc =
                JMXConnectorFactory.connect(cs.getAddress(), null);

            // Close RMI connector client
            //
            System.out.println("Close the RMI connector client");
            cc.close();

            // Stop RMI connector server
            //
            System.out.println("Stop the RMI connector server");
            cs.stop();

            // Check if remote objects were exported/unexported successfully
            //
            int errorCount = 0;

            if (exporter.rmiServerExported) {
                System.out.println("RMIServer exported OK!");
            } else {
                System.out.println("RMIServer exported KO!");
                errorCount++;
            }

            if (exporter.rmiServerUnexported) {
                System.out.println("RMIServer unexported OK!");
            } else {
                System.out.println("RMIServer unexported KO!");
                errorCount++;
            }

            if (exporter.rmiConnectionExported) {
                System.out.println("RMIConnection exported OK!");
            } else {
                System.out.println("RMIConnection exported KO!");
                errorCount++;
            }

            if (exporter.rmiConnectionUnexported) {
                System.out.println("RMIConnection unexported OK!");
            } else {
                System.out.println("RMIConnection unexported KO!");
                errorCount++;
            }

            System.out.println("Bye! Bye!");

            if (errorCount > 0) {
                System.out.println("RMIExporterTest FAILED!");
                System.exit(1);
            } else {
                System.out.println("RMIExporterTest PASSED!");
            }
        } catch (Exception e) {
            System.out.println("Unexpected exception caught = " + e);
            e.printStackTrace();
            System.exit(1);
        }
    }
 
Example 20
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);
    }
}