Java Code Examples for javax.management.remote.JMXConnector#removeConnectionNotificationListener()

The following examples show how to use javax.management.remote.JMXConnector#removeConnectionNotificationListener() . 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: JMConnManager.java    From jmonitor with GNU General Public License v2.0 5 votes vote down vote up
private static void disconnect(String app) {
    try {
        JMConnBean jmConnBean = conns.remove(app);
        JSONObject quit = new JSONObject();
        quit.put("type", "quit");
        quit.put("app", app);
        JMEevntCenter.getInstance().send(quit);
        JMXConnector conn = jmConnBean.getConnector();
        conn.removeConnectionNotificationListener(INSTANCE);
        conn.close();
    } catch (Exception e) {
        log.error("disconnect error:" + e);
    }
}
 
Example 2
Source File: NotifReconnectDeadlockTest.java    From dragonwell8_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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 3
Source File: NotifReconnectDeadlockTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 4
Source File: NotifReconnectDeadlockTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 5
Source File: NotifReconnectDeadlockTest.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 {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 6
Source File: NotifReconnectDeadlockTest.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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 7
Source File: NotifReconnectDeadlockTest.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 {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 8
Source File: NotifReconnectDeadlockTest.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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 9
Source File: NotifReconnectDeadlockTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 10
Source File: NotifReconnectDeadlockTest.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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 11
Source File: NotifReconnectDeadlockTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 12
Source File: NotifReconnectDeadlockTest.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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 13
Source File: NotifReconnectDeadlockTest.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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}
 
Example 14
Source File: NotifReconnectDeadlockTest.java    From jdk8u-dev-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(
       ">>> Tests reconnection done by a fetching notif thread.");

    ObjectName oname = new ObjectName ("Default:name=NotificationEmitter");
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    Map env = new HashMap(2);
    env.put("jmx.remote.x.server.connection.timeout", new Long(serverTimeout));
    env.put("jmx.remote.x.client.connection.check.period", new Long(Long.MAX_VALUE));

    final MBeanServer mbs = MBeanServerFactory.newMBeanServer();

    mbs.registerMBean(new NotificationEmitter(), oname);
    JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(
                                                                           url,
                                                                           env,
                                                                           mbs);
    server.start();

    JMXServiceURL addr = server.getAddress();
    JMXConnector client = JMXConnectorFactory.connect(addr, env);

    Thread.sleep(100); // let pass the first client open notif if there is
    client.getMBeanServerConnection().addNotificationListener(oname,
                                                              listener,
                                                              null,
                                                              null);

    client.addConnectionNotificationListener(listener, null, null);

    // max test time: 2 minutes
    final long end = System.currentTimeMillis()+120000;

    synchronized(lock) {
        while(clientState == null && System.currentTimeMillis() < end) {
            mbs.invoke(oname, "sendNotifications",
                       new Object[] {new Notification("MyType", "", 0)},
                       new String[] {"javax.management.Notification"});

            try {
                lock.wait(10);
            } catch (Exception e) {}
        }
    }

    if (clientState == null) {
        throw new RuntimeException(
              "No reconnection happened, need to reconfigure the test.");
    } else if (JMXConnectionNotification.FAILED.equals(clientState) ||
               JMXConnectionNotification.CLOSED.equals(clientState)) {
        throw new RuntimeException("Failed to reconnect.");
    }

    System.out.println(">>> Passed!");

    client.removeConnectionNotificationListener(listener);
    client.close();
    server.stop();
}