Search in sources :

Example 1 with ListenerNotFoundException

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());
        }
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) ListenerNotFoundException(javax.management.ListenerNotFoundException) ResourceManager(org.apache.geode.cache.control.ResourceManager) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ListenerNotFoundException

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]);
}
Also used : ArrayList(java.util.ArrayList) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Example 3 with ListenerNotFoundException

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;
}
Also used : ArrayList(java.util.ArrayList) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Example 4 with ListenerNotFoundException

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);
    }
}
Also used : DynamicMBean(javax.management.DynamicMBean) NotificationEmitter(javax.management.NotificationEmitter) NotificationBroadcaster(javax.management.NotificationBroadcaster) ListenerNotFoundException(javax.management.ListenerNotFoundException) NotificationListener(javax.management.NotificationListener)

Example 5 with ListenerNotFoundException

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");
    }
}
Also used : ListenerNotFoundException(javax.management.ListenerNotFoundException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

ListenerNotFoundException (javax.management.ListenerNotFoundException)34 ObjectName (javax.management.ObjectName)13 Notification (javax.management.Notification)11 NotificationEmitter (javax.management.NotificationEmitter)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)8 CompositeData (javax.management.openmbean.CompositeData)8 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)5 NotificationFilterSupport (javax.management.NotificationFilterSupport)5 MemoryNotificationInfo (java.lang.management.MemoryNotificationInfo)4 MemoryUsage (java.lang.management.MemoryUsage)4 MBeanException (javax.management.MBeanException)4 NotificationListener (javax.management.NotificationListener)4 ReflectionException (javax.management.ReflectionException)4 MemoryMXBean (java.lang.management.MemoryMXBean)3 ArrayList (java.util.ArrayList)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 IntrospectionException (javax.management.IntrospectionException)3 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)2