本文整理匯總了Java中javax.management.remote.JMXConnector.removeConnectionNotificationListener方法的典型用法代碼示例。如果您正苦於以下問題:Java JMXConnector.removeConnectionNotificationListener方法的具體用法?Java JMXConnector.removeConnectionNotificationListener怎麽用?Java JMXConnector.removeConnectionNotificationListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.remote.JMXConnector
的用法示例。
在下文中一共展示了JMXConnector.removeConnectionNotificationListener方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import javax.management.remote.JMXConnector; //導入方法依賴的package包/類
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();
}