Search in sources :

Example 26 with JMXServiceURL

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

the class MXBeanWeirdParamTest method run.

public void run(Map<String, Object> args) throws Exception {
    System.out.println("MXBeanWeirdParamTest::run: Start");
    int errorCount = 0;
    try {
        // Initialise the server side
        JMXServiceURL urlToUse = createServerSide();
        // Run client side
        errorCount = runClientSide(urlToUse.toString());
        if (errorCount == 0) {
            System.out.println("MXBeanWeirdParamTest::run: Done without any error");
        } else {
            System.out.println("MXBeanWeirdParamTest::run: Done with " + errorCount + " error(s)");
            throw new RuntimeException("errorCount = " + errorCount);
        }
        cs.stop();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL)

Example 27 with JMXServiceURL

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

the class MultiThreadDeadLockTest method main.

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);
    // allow to create client socket
    StateMachine.setState(CREATE_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();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) MBeanServer(javax.management.MBeanServer) JMXConnectorServer(javax.management.remote.JMXConnectorServer) ObjectName(javax.management.ObjectName)

Example 28 with JMXServiceURL

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

the class IIOPURLTest method main.

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();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) JMXConnectorServer(javax.management.remote.JMXConnectorServer) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 29 with JMXServiceURL

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

the class IdleTimeoutTest method test.

private static boolean test(String proto, int opCount, int liCount) throws Exception {
    System.out.println("Idle timeout test for protocol " + proto);
    ObjectName delegateName = ObjectName.getInstance("JMImplementation:" + "type=MBeanServerDelegate");
    MBeanServer mbs = MBeanServerFactory.createMBeanServer();
    JMXServiceURL url = new JMXServiceURL("service:jmx:" + proto + "://");
    final long timeout = getIdleTimeout(mbs, url);
    System.out.println("Timeout for " + proto + " is: " + timeout + " ms");
    Map idleMap = new HashMap();
    idleMap.put(EnvHelp.SERVER_CONNECTION_TIMEOUT, new Long(timeout));
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, idleMap, mbs);
    final int[] listenerCount = new int[1];
    final NotificationListener[] countListeners = new NotificationListener[liCount];
    int i;
    for (i = 0; i < countListeners.length; i++) {
        countListeners[i] = new NotificationCounter(listenerCount, "Listener" + i);
    }
    server.start();
    try {
        url = server.getAddress();
        final long firstTime = System.currentTimeMillis();
        JMXConnector client = JMXConnectorFactory.connect(url);
        long elapsed, startIdle = 0;
        try {
            String connId = client.getConnectionId();
            MBeanServerConnection conn = client.getMBeanServerConnection();
            elapsed = System.currentTimeMillis() - firstTime;
            System.out.println("Idle Time: " + elapsed + "ms");
            for (i = 0; i < countListeners.length; i++) {
                System.out.println("add " + countListeners[i] + ": starting at " + elapsed + "ms");
                conn.addNotificationListener(delegateName, countListeners[i], null, null);
            }
            System.out.println("connId=" + connId);
            for (i = 0; i < opCount; i++) {
                elapsed = System.currentTimeMillis() - firstTime;
                System.out.println("Operation[" + (i + 1) + "]: starting at " + elapsed + "ms");
                final String name = "d:type=mlet,instance=" + i;
                mbs.createMBean("javax.management.loading.MLet", new ObjectName(name));
                if (i == (opCount - 1))
                    startIdle = System.currentTimeMillis();
                Thread.sleep(2);
            }
            // Wait for notifs to arrive before doing removeNListener
            long startTime = System.currentTimeMillis();
            long deadline = startTime + 10000;
            System.out.println("Waiting for notifs: starting at " + (startTime - firstTime) + "ms");
            final int expectedCount = opCount * countListeners.length;
            while (System.currentTimeMillis() < deadline) {
                synchronized (listenerCount) {
                    if (listenerCount[0] >= expectedCount)
                        break;
                    listenerCount.wait();
                }
            }
            long elapsedWait = System.currentTimeMillis() - startTime;
            System.out.println("Waited " + elapsedWait + "ms for notifs to arrive");
            if (listenerCount[0] != expectedCount) {
                System.out.println("Did not get expected " + expectedCount + " notifications: " + listenerCount[0]);
                return false;
            }
            elapsed = System.currentTimeMillis() - firstTime;
            System.out.println("idle time since last operation: " + (elapsed + firstTime - startIdle) + "ms");
            System.out.println("Requesting conn id at: " + elapsed + "ms");
            final String cid = client.getConnectionId();
            elapsed = System.currentTimeMillis() - firstTime;
            System.out.println("Got conn id <" + cid + "> at: " + elapsed + "ms");
            if (!connId.equals(cid)) {
                System.out.println("Client id changed: <" + connId + "> -> <" + cid + ">");
                return false;
            }
            List ids = Arrays.asList(server.getConnectionIds());
            if (!ids.contains(connId)) {
                System.out.println("Server ids don't contain our id: " + ids + " - " + connId);
                return false;
            }
            for (i = 0; i < countListeners.length; i++) {
                System.out.println("Removing notification listener: " + countListeners[i]);
                conn.removeNotificationListener(delegateName, countListeners[i]);
            }
            System.out.println("Waiting for id list to drop ours");
            // pass or timed out by test harness - see 8025204
            do {
                Thread.sleep(100);
                ids = Arrays.asList(server.getConnectionIds());
            } while (ids.contains(connId));
            conn.getDefaultDomain();
            if (connId.equals(client.getConnectionId())) {
                System.out.println("Client id did not change: <" + connId + ">: idle timeout did not happen?");
                return false;
            } else {
                System.out.println("Client id changed as expected: <" + connId + "> -> <" + client.getConnectionId() + ">");
            }
        } finally {
            client.close();
            System.out.println("Connection id list on server after " + "client close: " + Arrays.asList(server.getConnectionIds()));
        }
    } finally {
        server.stop();
    }
    System.out.println("*** ------------------------------------------");
    System.out.println("*** Test passed for " + proto);
    System.out.println("*** ------------------------------------------");
    return true;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) ObjectName(javax.management.ObjectName) JMXConnectorServer(javax.management.remote.JMXConnectorServer) JMXConnector(javax.management.remote.JMXConnector) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) MBeanServerConnection(javax.management.MBeanServerConnection) MBeanServer(javax.management.MBeanServer) NotificationListener(javax.management.NotificationListener)

Example 30 with JMXServiceURL

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

the class ConnectionListenerNullTest method test.

public static int test(String... urls) {
    int errCount = 0;
    for (int i = 0; i < urls.length; i++) {
        try {
            final JMXServiceURL url = new JMXServiceURL(urls[i]);
            final JMXConnector c = JMXConnectorFactory.newJMXConnector(url, (Map<String, String>) null);
            final NotificationListener nl = null;
            final NotificationFilter nf = null;
            final Object h = null;
            System.out.println("Testing " + c.getClass().getName());
            try {
                System.out.println("addConnectionNotificationListener(null,null,null)");
                c.addConnectionNotificationListener(nl, nf, h);
                throw new AssertionError("No exception raised");
            } catch (NullPointerException npe) {
            // OK.
            }
            final NotificationListener listener = new NotificationListener() {

                public void handleNotification(Notification notification, Object handback) {
                }
            };
            c.addConnectionNotificationListener(listener, nf, h);
            try {
                System.out.println("removeConnectionNotificationListener(null)");
                c.removeConnectionNotificationListener(nl);
                throw new AssertionError("No exception raised");
            } catch (NullPointerException npe) {
            // OK.
            }
            try {
                System.out.println("removeConnectionNotificationListener(null,null,null)");
                c.removeConnectionNotificationListener(nl, nf, h);
                throw new AssertionError("No exception raised");
            } catch (NullPointerException npe) {
            // OK.
            }
            c.removeConnectionNotificationListener(listener);
            System.out.println(c.getClass().getName() + " successfully tested.");
        } catch (Exception x) {
            System.err.println("Unexpected exception for " + urls[i] + ": " + x);
            x.printStackTrace();
            errCount++;
        } catch (AssertionError e) {
            System.err.println("Unexpected assertion error for " + urls[i] + ": " + e);
            e.printStackTrace();
            errCount++;
        }
    }
    return errCount;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification) NotificationListener(javax.management.NotificationListener)

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