use of javax.management.ListenerNotFoundException in project geode by apache.
the class MemoryMonitorJUnitTest method testCriticalHeapThreshold.
@Test
public void testCriticalHeapThreshold() throws Exception {
final int toohigh = 101;
final int toolow = -1;
final float disabled = 0.0f;
final float justright = 92.5f;
final ResourceManager rm = this.cache.getResourceManager();
long usageThreshold = -1;
int once = 0;
for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
if (p.isUsageThresholdSupported() && HeapMemoryMonitor.isTenured(p)) {
usageThreshold = p.getUsageThreshold();
once++;
}
}
assertEquals("Expected only one pool to be assigned", 1, once);
// Default test, current default is disabled
assertEquals(rm.getCriticalHeapPercentage(), MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE, 0.01);
NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
try {
emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
assertTrue("Expected that the resource manager was not registered", false);
} catch (ListenerNotFoundException expected) {
}
try {
rm.setCriticalHeapPercentage(toohigh);
assertTrue("Expected illegal argument exception for value " + toohigh, false);
} catch (IllegalArgumentException toohi) {
}
try {
rm.setCriticalHeapPercentage(toolow);
assertTrue("Expected illegal argument exception for value " + toolow, false);
} catch (IllegalArgumentException toohi) {
}
rm.setCriticalHeapPercentage(justright);
emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
{
InternalResourceManager irm = InternalResourceManager.getInternalResourceManager(cache);
HeapMemoryMonitor hmm = irm.getHeapMonitor();
// Expect no exception for removal (it was installed during set)
hmm.stopMonitoring();
}
assertEquals(rm.getCriticalHeapPercentage(), justright, 0.01);
rm.setCriticalHeapPercentage(disabled);
assertEquals(rm.getCriticalHeapPercentage(), disabled, 0.01);
emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
try {
emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
assertTrue("Expected that the resource manager was not registered", false);
} catch (ListenerNotFoundException expected) {
}
// Assert the threshold was reset
for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
if (HeapMemoryMonitor.isTenured(p)) {
assertEquals(usageThreshold, p.getUsageThreshold());
}
}
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class ClientNotifForwarder method removeNotificationListener.
public synchronized Integer[] removeNotificationListener(ObjectName name, NotificationListener listener) throws ListenerNotFoundException, IOException {
beforeRemove();
if (logger.traceOn()) {
logger.trace("removeNotificationListener", "Remove the listener " + listener + " from " + name);
}
List<Integer> ids = new ArrayList<Integer>();
List<ClientListenerInfo> values = new ArrayList<ClientListenerInfo>(infoList.values());
for (int i = values.size() - 1; i >= 0; i--) {
ClientListenerInfo li = values.get(i);
if (li.sameAs(name, listener)) {
ids.add(li.getListenerID());
infoList.remove(li.getListenerID());
}
}
if (ids.isEmpty())
throw new ListenerNotFoundException("Listener not found");
return ids.toArray(new Integer[0]);
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class ClientNotifForwarder method removeNotificationListener.
public synchronized Integer removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException, IOException {
if (logger.traceOn()) {
logger.trace("removeNotificationListener", "Remove the listener " + listener + " from " + name);
}
beforeRemove();
Integer id = null;
List<ClientListenerInfo> values = new ArrayList<ClientListenerInfo>(infoList.values());
for (int i = values.size() - 1; i >= 0; i--) {
ClientListenerInfo li = values.get(i);
if (li.sameAs(name, listener, filter, handback)) {
id = li.getListenerID();
infoList.remove(id);
break;
}
}
if (id == null)
throw new ListenerNotFoundException("Listener not found");
return id;
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method removeNotificationListener.
private void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback, boolean removeAll) throws InstanceNotFoundException, ListenerNotFoundException {
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "removeNotificationListener", "ObjectName = " + name);
}
DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, null, name, "removeNotificationListener");
/* We could simplify the code by assigning broadcaster after
assigning listenerWrapper, but that would change the error
behavior when both the broadcaster and the listener are
erroneous. */
Class<? extends NotificationBroadcaster> reqClass = removeAll ? NotificationBroadcaster.class : NotificationEmitter.class;
NotificationBroadcaster broadcaster = getNotificationBroadcaster(name, instance, reqClass);
NotificationListener listenerWrapper = getListenerWrapper(listener, name, instance, false);
if (listenerWrapper == null)
throw new ListenerNotFoundException("Unknown listener");
if (removeAll)
broadcaster.removeNotificationListener(listenerWrapper);
else {
NotificationEmitter emitter = (NotificationEmitter) broadcaster;
emitter.removeNotificationListener(listenerWrapper, filter, handback);
}
}
use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.
the class RequiredModelMBean method removeAttributeChangeNotificationListener.
public void removeAttributeChangeNotificationListener(NotificationListener inlistener, String inAttributeName) throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
if (inlistener == null)
throw new ListenerNotFoundException("Notification listener is null");
final String mth = "removeAttributeChangeNotificationListener(" + "NotificationListener, String)";
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
}
if (attributeBroadcaster == null)
throw new ListenerNotFoundException("No attribute change notification listeners registered");
MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
boolean found = false;
if ((attrInfo != null) && (attrInfo.length > 0)) {
for (int i = 0; i < attrInfo.length; i++) {
if (attrInfo[i].getName().equals(inAttributeName)) {
found = true;
break;
}
}
}
if ((!found) && (inAttributeName != null)) {
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid attribute name"), "Exception occurred trying to remove " + "attribute change notification listener");
}
/* note: */
/* this may be a problem if the same listener is registered for
multiple attributes with multiple filters and/or handback
objects. It may remove all of them */
attributeBroadcaster.removeNotificationListener(inlistener);
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
}
}
Aggregations