use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method removeNotificationListener.
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException {
if (listener == null)
throw new ListenerNotFoundException("Notification listener is null");
final String mth = "removeNotificationListener(" + "NotificationListener, NotificationFilter, Object)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
}
if (generalBroadcaster == null)
throw new ListenerNotFoundException("No notification listeners registered");
generalBroadcaster.removeNotificationListener(listener, filter, handback);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
}
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class NotificationEmitterSupport method removeNotificationListener.
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
synchronized (listenerLock) {
List<ListenerInfo> newList = new ArrayList<>(listenerList);
/* We scan the list of listeners in reverse order because
in forward order we would have to repeat the loop with
the same index after a remove. */
for (int i = newList.size() - 1; i >= 0; i--) {
ListenerInfo li = newList.get(i);
if (li.listener == listener)
newList.remove(i);
}
if (newList.size() == listenerList.size())
throw new ListenerNotFoundException("Listener not registered");
listenerList = newList;
}
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class DeadListenerTest method main.
public static void main(String[] args) throws Exception {
final ObjectName delegateName = MBeanServerDelegate.DELEGATE_NAME;
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Noddy mbean = new Noddy();
ObjectName name = new ObjectName("d:k=v");
mbs.registerMBean(mbean, name);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
SnoopRMIServerImpl rmiServer = new SnoopRMIServerImpl();
RMIConnectorServer cs = new RMIConnectorServer(url, null, rmiServer, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
assertTrue("No connections in new connector server", rmiServer.connections.isEmpty());
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
assertTrue("One connection on server after client connect", rmiServer.connections.size() == 1);
RMIConnectionImpl connection = rmiServer.connections.get(0);
Method getServerNotifFwdM = RMIConnectionImpl.class.getDeclaredMethod("getServerNotifFwd");
getServerNotifFwdM.setAccessible(true);
ServerNotifForwarder serverNotifForwarder = (ServerNotifForwarder) getServerNotifFwdM.invoke(connection);
Field listenerMapF = ServerNotifForwarder.class.getDeclaredField("listenerMap");
listenerMapF.setAccessible(true);
@SuppressWarnings("unchecked") Map<ObjectName, Set<?>> listenerMap = (Map<ObjectName, Set<?>>) listenerMapF.get(serverNotifForwarder);
assertTrue("Server listenerMap initially empty", mapWithoutKey(listenerMap, delegateName).isEmpty());
final AtomicInteger count1Val = new AtomicInteger();
CountListener count1 = new CountListener(count1Val);
mbsc.addNotificationListener(name, count1, null, null);
WeakReference<CountListener> count1Ref = new WeakReference<>(count1);
count1 = null;
final AtomicInteger count2Val = new AtomicInteger();
CountListener count2 = new CountListener(count2Val);
NotificationFilterSupport dummyFilter = new NotificationFilterSupport();
dummyFilter.enableType("");
mbsc.addNotificationListener(name, count2, dummyFilter, "noddy");
WeakReference<CountListener> count2Ref = new WeakReference<>(count2);
count2 = null;
assertTrue("One entry in listenerMap for two listeners on same MBean", mapWithoutKey(listenerMap, delegateName).size() == 1);
Set<?> set = listenerMap.get(name);
assertTrue("Set in listenerMap for MBean has two elements", set != null && set.size() == 2);
assertTrue("Initial value of count1 == 0", count1Val.get() == 0);
assertTrue("Initial value of count2 == 0", count2Val.get() == 0);
Notification notif = new Notification("type", name, 0);
mbean.sendNotification(notif);
// Make sure notifs are working normally.
long deadline = System.currentTimeMillis() + 2000;
while ((count1Val.get() != 1 || count2Val.get() != 1) && System.currentTimeMillis() < deadline) {
Thread.sleep(10);
}
assertTrue("New value of count1 == 1", count1Val.get() == 1);
assertTrue("Initial value of count2 == 1", count2Val.get() == 1);
// Make sure that removing a nonexistent listener from an existent MBean produces ListenerNotFoundException
CountListener count3 = new CountListener();
try {
mbsc.removeNotificationListener(name, count3);
assertTrue("Remove of nonexistent listener succeeded but should not have", false);
} catch (ListenerNotFoundException e) {
// OK: expected
}
// Make sure that removing a nonexistent listener from a nonexistent MBean produces ListenerNotFoundException
ObjectName nonexistent = new ObjectName("foo:bar=baz");
assertTrue("Nonexistent is nonexistent", !mbs.isRegistered(nonexistent));
try {
mbsc.removeNotificationListener(nonexistent, count3);
assertTrue("Remove of listener from nonexistent MBean succeeded but should not have", false);
} catch (ListenerNotFoundException e) {
// OK: expected
}
// Now unregister our MBean, and check that notifs it sends no longer go anywhere.
mbs.unregisterMBean(name);
mbean.sendNotification(notif);
Thread.sleep(200);
assertTrue("New value of count1 == 1", count1Val.get() == 1);
assertTrue("Initial value of count2 == 1", count2Val.get() == 1);
// wait for the listener cleanup to take place upon processing notifications
// waiting max. 5 secs
int countdown = 50;
while (countdown-- > 0 && (count1Ref.get() != null || count2Ref.get() != null)) {
System.gc();
Thread.sleep(100);
System.gc();
}
// listener has been removed or the wait has timed out
assertTrue("count1 notification listener has not been cleaned up", count1Ref.get() == null);
assertTrue("count2 notification listener has not been cleaned up", count2Ref.get() == null);
// Check that there is no trace of the listeners any more in ServerNotifForwarder.listenerMap.
// THIS DEPENDS ON JMX IMPLEMENTATION DETAILS.
// If the JMX implementation changes, the code here may have to change too.
Set<?> setForUnreg = listenerMap.get(name);
assertTrue("No trace of unregistered MBean: " + setForUnreg, setForUnreg == null);
}
use of javax.management.ListenerNotFoundException in project geode by apache.
the class HeapMemoryMonitor method stopMonitoring.
/**
* Stops all three mechanisms from monitoring heap usage.
*/
@Override
public void stopMonitoring() {
synchronized (this) {
if (!this.started) {
return;
}
// Stop the poller
this.resourceManager.stopExecutor(this.pollerExecutor);
// Stop the JVM threshold listener
NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
try {
emitter.removeNotificationListener(this, null, null);
this.cache.getLoggerI18n().fine("Removed Memory MXBean notification listener" + this);
} catch (ListenerNotFoundException ignore) {
logger.debug("This instance '{}' was not registered as a Memory MXBean listener", this);
}
// Stop the stats listener
final GemFireStatSampler sampler = this.cache.getInternalDistributedSystem().getStatSampler();
if (sampler != null) {
sampler.removeLocalStatListener(this.statListener);
}
this.started = false;
}
}
use of javax.management.ListenerNotFoundException in project geode by apache.
the class DistributedSystemBridge method removeMemberFromSystem.
/**
* Removed the proxy from the map.
*
* @param objectName name of the proxy to be removed.
* @param proxy actual reference to the proxy object
* @return whether all proxies have been removed or not. In this case it will always be false.
* Kept it for consistency for MBeanAggregator.
*/
public boolean removeMemberFromSystem(ObjectName objectName, MemberMXBean proxy, FederationComponent oldState) {
if (thisMemberName.equals(objectName)) {
ObjectName distrObjectName = MBeanJMXAdapter.getDistributedSystemName();
service.unregisterMBean(distrObjectName);
}
if (mapOfMembers != null) {
mapOfMembers.remove(objectName);
memberSetSize = mapOfMembers.values().size();
if (mapOfMembers.values().size() == 0) {
memberSetSize = 0;
return true;
}
}
updateMember(objectName, null, oldState);
try {
mbeanServer.removeNotificationListener(objectName, distListener);
} catch (ListenerNotFoundException e) {
logger.info(LocalizedMessage.create(ManagementStrings.LISTENER_NOT_FOUND_FOR_0, objectName));
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
} catch (InstanceNotFoundException e) {
logger.info(LocalizedMessage.create(ManagementStrings.INSTANCE_NOT_FOUND, objectName));
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
}
return false;
}
Aggregations