use of javax.management.ListenerNotFoundException in project felix by apache.
the class ClientInvoker method removeNotificationListener.
public void removeNotificationListener(ObjectName observed, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
Integer id = notificationHandler.getNotificationListener(new NotificationTuple(observed, listener, filter, handback));
if (id == null)
throw new ListenerNotFoundException("Could not find listener " + listener + " with filter " + filter + " and handback " + handback);
Integer[] ids = new Integer[] { id };
connection.removeNotificationListeners(observed, ids, delegate);
notificationHandler.removeNotificationListeners(ids);
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method getListener.
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException {
// ----------------
// Get listener object
// ----------------
DynamicMBean instance;
try {
instance = getMBean(listener);
} catch (InstanceNotFoundException e) {
throw EnvHelp.initCause(new ListenerNotFoundException(e.getMessage()), e);
}
Object resource = getResource(instance);
if (!(resource instanceof NotificationListener)) {
final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName());
final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName();
throw new RuntimeOperationsException(exc, msg);
}
return (NotificationListener) resource;
}
use of javax.management.ListenerNotFoundException in project openj9 by eclipse.
the class TestManagementFactory method testExtMemoryMXBeanProxyNotificationEmitterRemoveListeners.
/**
* For IBM extensions on the MemoryMXBean
*/
@Test
public void testExtMemoryMXBeanProxyNotificationEmitterRemoveListeners() {
try {
com.ibm.lang.management.MemoryMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=Memory", com.ibm.lang.management.MemoryMXBean.class);
MemoryMXBean stdProxy = proxy;
AssertJUnit.assertNotNull(stdProxy);
AssertJUnit.assertTrue(proxy instanceof NotificationEmitter);
NotificationEmitter proxyEmitter = (NotificationEmitter) proxy;
MyTestListener listener = new MyTestListener();
proxyEmitter.addNotificationListener(listener, null, null);
// Fire off a notification and ensure that the listener receives it.
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Marcel", mu, 42);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
((MemoryMXBeanImpl) ManagementFactory.getMemoryMXBean()).sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Verify that the handback is as expected.
AssertJUnit.assertNull(listener.getHandback());
// Verify the user data of the notification.
Notification n = listener.getNotification();
AssertJUnit.assertNotNull(n);
verifyMemoryNotificationUserData(n.getUserData());
// Remove the listener
proxyEmitter.removeNotificationListener(listener);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
((MemoryMXBeanImpl) ManagementFactory.getMemoryMXBean()).sendNotification(notification);
AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
// ListenerNotFoundException being thrown.
try {
proxyEmitter.removeNotificationListener(listener);
Assert.fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
logger.debug("ListenerNotFoundException occurred, as expected: " + e.getMessage());
}
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
} catch (ListenerNotFoundException e) {
Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Assert.fail("Unexpected IOException : " + e.getMessage());
e.printStackTrace();
}
}
use of javax.management.ListenerNotFoundException in project openj9 by eclipse.
the class TestManagementFactory method testMemoryMXBeanProxyNotificationEmitterRemoveListeners.
@Test
public void testMemoryMXBeanProxyNotificationEmitterRemoveListeners() {
try {
MemoryMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=Memory", MemoryMXBean.class);
AssertJUnit.assertNotNull(proxy);
AssertJUnit.assertTrue(proxy instanceof NotificationEmitter);
NotificationEmitter proxyEmitter = (NotificationEmitter) proxy;
MyTestListener listener = new MyTestListener();
proxyEmitter.addNotificationListener(listener, null, null);
// Fire off a notification and ensure that the listener receives it.
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Marcel", mu, 42);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
((MemoryMXBeanImpl) ManagementFactory.getMemoryMXBean()).sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Verify that the handback is as expected.
AssertJUnit.assertNull(listener.getHandback());
// Verify the user data of the notification.
Notification n = listener.getNotification();
AssertJUnit.assertNotNull(n);
verifyMemoryNotificationUserData(n.getUserData());
// Remove the listener
proxyEmitter.removeNotificationListener(listener);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
((MemoryMXBeanImpl) ManagementFactory.getMemoryMXBean()).sendNotification(notification);
AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
// ListenerNotFoundException being thrown.
try {
proxyEmitter.removeNotificationListener(listener);
Assert.fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
logger.debug("ListenerNotFoundException occurred, as expected: " + e.getMessage());
}
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
} catch (ListenerNotFoundException e) {
Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Assert.fail("Unexpected IOException : " + e.getMessage());
e.printStackTrace();
}
}
use of javax.management.ListenerNotFoundException in project openj9 by eclipse.
the class MyTestListener method testRemoveNotificationListenerNotificationListenerNotificationFilterObject.
// -----------------------------------------------------------------
// Notification implementation tests follow ....
// -----------------------------------------------------------------
/*
* Class under test for void
* removeNotificationListener(NotificationListener, NotificationFilter,
* Object)
*/
@Test
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject() {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
MyTestListener listener = new MyTestListener();
mb.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
try {
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
mb.sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Remove the listener
mb.removeNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
mb.sendNotification(notification);
AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
// ListenerNotFoundException being thrown.
try {
mb.removeNotificationListener(listener, filter, null);
Assert.fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
}
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
} catch (ListenerNotFoundException e) {
Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
e.printStackTrace();
}
}
Aggregations