本文整理汇总了Java中javax.management.MBeanServerConnection.removeNotificationListener方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.removeNotificationListener方法的具体用法?Java MBeanServerConnection.removeNotificationListener怎么用?Java MBeanServerConnection.removeNotificationListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.MBeanServerConnection
的用法示例。
在下文中一共展示了MBeanServerConnection.removeNotificationListener方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listenerOp
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void listenerOp(MBeanServerConnection mserver, NotificationListener listener, boolean adding)
throws Exception {
if (adding) {
mserver.addNotificationListener(delegateName, listener, null, null);
} else {
mserver.removeNotificationListener(delegateName, listener);
}
}
示例2: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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.");
}
示例3: test
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void test(String proto) throws Exception {
System.out.println("\n>>> Test for protocol " + proto);
JMXServiceURL url = new JMXServiceURL(proto, null, 0);
System.out.println(">>> Create a server: "+url);
JMXConnectorServer server = null;
try {
server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
} catch (MalformedURLException e) {
System.out.println("System does not recognize URL: " + url +
"; ignoring");
return;
}
server.start();
url = server.getAddress();
System.out.println(">>> Creating a client connectint to: "+url);
JMXConnector conn = JMXConnectorFactory.connect(url, null);
MBeanServerConnection client = conn.getMBeanServerConnection();
// add listener from the client side
Listener listener = new Listener();
client.addNotificationListener(emitter, listener, null, null);
// ask to send one not serializable notif
Object[] params = new Object[] {new Integer(1)};
String[] signatures = new String[] {"java.lang.Integer"};
client.invoke(emitter, "sendNotserializableNotifs", params, signatures);
// listener clean
client.removeNotificationListener(emitter, listener);
listener = new Listener();
client.addNotificationListener(emitter, listener, null, null);
//ask to send serializable notifs
params = new Object[] {new Integer(sentNotifs)};
client.invoke(emitter, "sendNotifications", params, signatures);
// waiting ...
synchronized (listener) {
while (listener.received() < sentNotifs) {
listener.wait(); // either pass or test timeout (killed by test harness)
}
}
// clean
client.removeNotificationListener(emitter, listener);
conn.close();
server.stop();
}
示例4: test
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void test() throws Exception {
// Create client
//
JMXConnector connector = JMXConnectorFactory.connect(url);
MBeanServerConnection client = connector.getMBeanServerConnection();
// Add listener at the client side
//
client.addNotificationListener(mbean, listener, null, null);
// Cleanup
//
receivedNotifs = 0;
// Ask to send notifs
//
Object[] params = new Object[] {new Integer(nb)};
String[] signatures = new String[] {"java.lang.Integer"};
client.invoke(mbean, "sendNotifications", params, signatures);
// Waiting...
//
synchronized (lock) {
for (int i = 0; i < 10; i++) {
if (receivedNotifs < nb) {
lock.wait(1000);
}
}
}
// Waiting again to ensure no more notifs
//
Thread.sleep(3000);
synchronized (lock) {
if (receivedNotifs != nb) {
throw new Exception("The client expected to receive " +
nb + " notifs, but got " + receivedNotifs);
}
}
// Remove listener
//
client.removeNotificationListener(mbean, listener);
connector.close();
}
示例5: test
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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);
}
}
示例6: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Policy.setPolicy(new NoRemovePolicy());
System.setSecurityManager(new SecurityManager());
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("foo:type=Sender");
mbs.registerMBean(new Sender(), name);
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(
url, null, mbs);
cs.start();
try {
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
SnoopListener listener = new SnoopListener();
mbsc.addNotificationListener(name, listener, null, null);
mbsc.invoke(name, "send", null, null);
if (!listener.waitForNotification(60))
throw new Exception("Did not receive expected notification");
try {
mbsc.removeNotificationListener(name, listener);
throw new Exception("RemoveNL did not get SecurityException");
} catch (SecurityException e) {
System.out.println("removeNL got expected exception: " + e);
}
mbsc.invoke(name, "send", null, null);
if (!listener.waitForNotification(60)) {
int listenerCount =
(Integer) mbsc.getAttribute(name, "ListenerCount");
System.out.println("Listener count: " + listenerCount);
if (listenerCount != 0)
throw new Exception("TEST FAILED");
/* We did not receive the notification, but the MBean still
* has a listener coming from the connector server, which
* means the connector server still thinks there is a
* listener. If we retained the listener after the failing
* removeNL that would be OK, and if the listener were
* dropped by both client and server that would be OK too,
* but the inconsistency is not OK.
*/
}
cc.close();
} finally {
cs.stop();
}
}
示例7: main
import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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.");
}