Search in sources :

Example 6 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 7 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 8 with ListenerNotFoundException

use of javax.management.ListenerNotFoundException in project intellij-community by JetBrains.

the class PerformanceWatcher method watchCodeCache.

private void watchCodeCache(final MemoryPoolMXBean bean) {
    final long threshold = bean.getUsage().getMax() - 5 * 1024 * 1024;
    if (!bean.isUsageThresholdSupported() || threshold <= 0)
        return;
    bean.setUsageThreshold(threshold);
    final NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    emitter.addNotificationListener(new NotificationListener() {

        @Override
        public void handleNotification(Notification n, Object hb) {
            if (bean.getUsage().getUsed() > threshold) {
                LOG.info("Code Cache is almost full");
                dumpThreads("codeCacheFull", true);
                try {
                    emitter.removeNotificationListener(this);
                } catch (ListenerNotFoundException e) {
                    LOG.error(e);
                }
            }
        }
    }, null, null);
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) ListenerNotFoundException(javax.management.ListenerNotFoundException) Notification(javax.management.Notification) NotificationListener(javax.management.NotificationListener)

Example 9 with ListenerNotFoundException

use of javax.management.ListenerNotFoundException in project jdk8u_jdk by JetBrains.

the class ServerNotifForwarder method removeNotificationListener.

public void removeNotificationListener(ObjectName name, Integer listenerID) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
    if (logger.traceOn()) {
        logger.trace("removeNotificationListener", "Remove the listener " + listenerID + " from " + name);
    }
    checkState();
    if (name != null && !name.isPattern()) {
        if (!mbeanServer.isRegistered(name)) {
            throw new InstanceNotFoundException("The MBean " + name + " is not registered.");
        }
    }
    synchronized (listenerMap) {
        // Tread carefully because if set.size() == 1 it may be a
        // Collections.singleton, which is unmodifiable.
        Set<IdAndFilter> set = listenerMap.get(name);
        IdAndFilter idaf = new IdAndFilter(listenerID, null);
        if (set == null || !set.contains(idaf))
            throw new ListenerNotFoundException("Listener not found");
        if (set.size() == 1)
            listenerMap.remove(name);
        else
            set.remove(idaf);
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Example 10 with ListenerNotFoundException

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;
}
Also used : DynamicMBean(javax.management.DynamicMBean) JMRuntimeException(javax.management.JMRuntimeException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ListenerNotFoundException(javax.management.ListenerNotFoundException) NamedObject(com.sun.jmx.mbeanserver.NamedObject) NotificationListener(javax.management.NotificationListener) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Aggregations

ListenerNotFoundException (javax.management.ListenerNotFoundException)16 NotificationEmitter (javax.management.NotificationEmitter)4 NotificationListener (javax.management.NotificationListener)4 ObjectName (javax.management.ObjectName)4 ArrayList (java.util.ArrayList)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 Notification (javax.management.Notification)3 DynamicMBean (javax.management.DynamicMBean)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 Test (org.junit.Test)2 NamedObject (com.sun.jmx.mbeanserver.NamedObject)1 ServerNotifForwarder (com.sun.jmx.remote.internal.ServerNotifForwarder)1 Component (java.awt.Component)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 WeakReference (java.lang.ref.WeakReference)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1