下面列出了javax.management.MBeanServerConnection#addNotificationListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void doTestMBeanServerNotification_UNREGISTRATION_NOTIFICATION(MBeanServerConnection connection, boolean mustReceiveNotification) throws Exception {
final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only");
final CountDownLatch notificationEmitted = new CountDownLatch(1);
final AtomicReference<Notification> notification = new AtomicReference<>();
NotificationListener listener = new MbeanServerNotificationListener(notification, notificationEmitted, LEGACY_DOMAIN);
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
connection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
// add a management resource
connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});
// and remove it
connection.invoke(childObjectName, "remove", new Object[0], new String[0]);
if (mustReceiveNotification) {
Assert.assertTrue("Did not receive expected notification", notificationEmitted.await(1, TimeUnit.SECONDS));
Notification notif = notification.get();
Assert.assertNotNull(notif);
Assert.assertTrue(notif instanceof MBeanServerNotification);
MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notif;
Assert.assertEquals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION, mBeanServerNotification.getType());
Assert.assertEquals(childObjectName, mBeanServerNotification.getMBeanName());
} else {
Assert.assertFalse("Did receive unexpected notification", notificationEmitted.await(500, TimeUnit.MILLISECONDS));
}
connection.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
}
public static void main(String[] args) throws Exception
{
// This JMXServiceURL works only if the connector server is on the same host of
// the connector. If this is not the case, set the correct host name.
JMXServiceURL address = new JMXServiceURL("hessian", null, 8080, "/hessian");
// Connect a JSR 160 JMXConnector to the server side
JMXConnector connector = JMXConnectorFactory.connect(address);
// Retrieve an MBeanServerConnection that represent the MBeanServer
// the remote connector server is bound to
MBeanServerConnection connection = connector.getMBeanServerConnection();
// Call the server side as if it is a local MBeanServer
ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true);
MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy;
System.out.println(delegate.getImplementationVendor() + " is cool !");
// Register an MBean, and get notifications via the Hessian protocol
connection.addNotificationListener(delegateName, new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println("Got the following notification: " + notification);
}
}, null, null);
ObjectName timerName = ObjectName.getInstance("services:type=Timer");
connection.createMBean(Timer.class.getName(), timerName, null);
// Unregistering the MBean to get another notification
connection.unregisterMBean(timerName);
// Allow the unregistration notification to arrive before killing this JVM
Thread.sleep(1000);
connector.close();
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
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();
}
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();
}
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);
}
}
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.");
}
private static boolean notifyTest(JMXConnector client,
MBeanServerConnection mbsc)
throws Exception {
System.out.println("Send notifications including unknown ones");
result = new Result();
LostListener ll = new LostListener();
client.addConnectionNotificationListener(ll, null, null);
TestListener nl = new TestListener(ll);
mbsc.addNotificationListener(on, nl, new TestFilter(), null);
mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
// wait for the listeners to receive all their notifs
// or to fail
long deadline = System.currentTimeMillis() + 60000;
long remain;
while ((remain = deadline - System.currentTimeMillis()) >= 0) {
synchronized (result) {
if (result.failed
|| (result.knownCount >= NNOTIFS
&& result.lostCount >= NNOTIFS*2))
break;
result.wait(remain);
}
}
Thread.sleep(2); // allow any spurious extra notifs to arrive
if (result.failed) {
System.out.println("TEST FAILS: Notification strangeness");
return false;
} else if (result.knownCount == NNOTIFS
&& result.lostCount == NNOTIFS*2) {
System.out.println("Success: received known notifications and " +
"got NOTIFS_LOST for unknown and " +
"unserializable ones");
return true;
} else if (result.knownCount >= NNOTIFS
|| result.lostCount >= NNOTIFS*2) {
System.out.println("TEST FAILS: Received too many notifs: " +
"known=" + result.knownCount + "; lost=" + result.lostCount);
return false;
} else {
System.out.println("TEST FAILS: Timed out without receiving " +
"all notifs: known=" + result.knownCount +
"; lost=" + result.lostCount);
return false;
}
}
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();
}
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();
}
private static boolean notifyTest(JMXConnector client,
MBeanServerConnection mbsc)
throws Exception {
System.out.println("Send notifications including unknown ones");
result = new Result();
LostListener ll = new LostListener();
client.addConnectionNotificationListener(ll, null, null);
TestListener nl = new TestListener(ll);
mbsc.addNotificationListener(on, nl, new TestFilter(), null);
mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
// wait for the listeners to receive all their notifs
// or to fail
long deadline = System.currentTimeMillis() + 60000;
long remain;
while ((remain = deadline - System.currentTimeMillis()) >= 0) {
synchronized (result) {
if (result.failed
|| (result.knownCount >= NNOTIFS
&& result.lostCount >= NNOTIFS*2))
break;
result.wait(remain);
}
}
Thread.sleep(2); // allow any spurious extra notifs to arrive
if (result.failed) {
System.out.println("TEST FAILS: Notification strangeness");
return false;
} else if (result.knownCount == NNOTIFS
&& result.lostCount == NNOTIFS*2) {
System.out.println("Success: received known notifications and " +
"got NOTIFS_LOST for unknown and " +
"unserializable ones");
return true;
} else if (result.knownCount >= NNOTIFS
|| result.lostCount >= NNOTIFS*2) {
System.out.println("TEST FAILS: Received too many notifs: " +
"known=" + result.knownCount + "; lost=" + result.lostCount);
return false;
} else {
System.out.println("TEST FAILS: Timed out without receiving " +
"all notifs: known=" + result.knownCount +
"; lost=" + result.lostCount);
return false;
}
}
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();
}
private static boolean notifyTest(JMXConnector client,
MBeanServerConnection mbsc)
throws Exception {
System.out.println("Send notifications including unknown ones");
result = new Result();
LostListener ll = new LostListener();
client.addConnectionNotificationListener(ll, null, null);
TestListener nl = new TestListener(ll);
mbsc.addNotificationListener(on, nl, new TestFilter(), null);
mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
// wait for the listeners to receive all their notifs
// or to fail
long deadline = System.currentTimeMillis() + 60000;
long remain;
while ((remain = deadline - System.currentTimeMillis()) >= 0) {
synchronized (result) {
if (result.failed
|| (result.knownCount >= NNOTIFS
&& result.lostCount >= NNOTIFS*2))
break;
result.wait(remain);
}
}
Thread.sleep(2); // allow any spurious extra notifs to arrive
if (result.failed) {
System.out.println("TEST FAILS: Notification strangeness");
return false;
} else if (result.knownCount == NNOTIFS
&& result.lostCount == NNOTIFS*2) {
System.out.println("Success: received known notifications and " +
"got NOTIFS_LOST for unknown and " +
"unserializable ones");
return true;
} else if (result.knownCount >= NNOTIFS
|| result.lostCount >= NNOTIFS*2) {
System.out.println("TEST FAILS: Received too many notifs: " +
"known=" + result.knownCount + "; lost=" + result.lostCount);
return false;
} else {
System.out.println("TEST FAILS: Timed out without receiving " +
"all notifs: known=" + result.knownCount +
"; lost=" + result.lostCount);
return false;
}
}
private static boolean notifyTest(JMXConnector client,
MBeanServerConnection mbsc)
throws Exception {
System.out.println("Send notifications including unknown ones");
result = new Result();
LostListener ll = new LostListener();
client.addConnectionNotificationListener(ll, null, null);
TestListener nl = new TestListener(ll);
mbsc.addNotificationListener(on, nl, new TestFilter(), null);
mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
// wait for the listeners to receive all their notifs
// or to fail
long deadline = System.currentTimeMillis() + 60000;
long remain;
while ((remain = deadline - System.currentTimeMillis()) >= 0) {
synchronized (result) {
if (result.failed
|| (result.knownCount >= NNOTIFS
&& result.lostCount >= NNOTIFS*2))
break;
result.wait(remain);
}
}
Thread.sleep(2); // allow any spurious extra notifs to arrive
if (result.failed) {
System.out.println("TEST FAILS: Notification strangeness");
return false;
} else if (result.knownCount == NNOTIFS
&& result.lostCount == NNOTIFS*2) {
System.out.println("Success: received known notifications and " +
"got NOTIFS_LOST for unknown and " +
"unserializable ones");
return true;
} else if (result.knownCount >= NNOTIFS
|| result.lostCount >= NNOTIFS*2) {
System.out.println("TEST FAILS: Received too many notifs: " +
"known=" + result.knownCount + "; lost=" + result.lostCount);
return false;
} else {
System.out.println("TEST FAILS: Timed out without receiving " +
"all notifs: known=" + result.knownCount +
"; lost=" + result.lostCount);
return false;
}
}
private static boolean notifyTest(JMXConnector client,
MBeanServerConnection mbsc)
throws Exception {
System.out.println("Send notifications including unknown ones");
result = new Result();
LostListener ll = new LostListener();
client.addConnectionNotificationListener(ll, null, null);
TestListener nl = new TestListener(ll);
mbsc.addNotificationListener(on, nl, new TestFilter(), null);
mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
// wait for the listeners to receive all their notifs
// or to fail
long deadline = System.currentTimeMillis() + 60000;
long remain;
while ((remain = deadline - System.currentTimeMillis()) >= 0) {
synchronized (result) {
if (result.failed
|| (result.knownCount >= NNOTIFS
&& result.lostCount >= NNOTIFS*2))
break;
result.wait(remain);
}
}
Thread.sleep(2); // allow any spurious extra notifs to arrive
if (result.failed) {
System.out.println("TEST FAILS: Notification strangeness");
return false;
} else if (result.knownCount == NNOTIFS
&& result.lostCount == NNOTIFS*2) {
System.out.println("Success: received known notifications and " +
"got NOTIFS_LOST for unknown and " +
"unserializable ones");
return true;
} else if (result.knownCount >= NNOTIFS
|| result.lostCount >= NNOTIFS*2) {
System.out.println("TEST FAILS: Received too many notifs: " +
"known=" + result.knownCount + "; lost=" + result.lostCount);
return false;
} else {
System.out.println("TEST FAILS: Timed out without receiving " +
"all notifs: known=" + result.knownCount +
"; lost=" + result.lostCount);
return false;
}
}
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);
}
}