javax.management.NotificationListener Java Examples

The following examples show how to use javax.management.NotificationListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMBeanServerInterceptor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private NotificationListener getListenerWrapper(NotificationListener l,
                                                ObjectName name,
                                                DynamicMBean mbean,
                                                boolean create) {
    Object resource = getResource(mbean);
    ListenerWrapper wrapper = new ListenerWrapper(l, name, resource);
    synchronized (listenerWrappers) {
        WeakReference<ListenerWrapper> ref = listenerWrappers.get(wrapper);
        if (ref != null) {
            NotificationListener existing = ref.get();
            if (existing != null)
                return existing;
        }
        if (create) {
            ref = new WeakReference<ListenerWrapper>(wrapper);
            listenerWrappers.put(wrapper, ref);
            return wrapper;
        } else
            return null;
    }
}
 
Example #2
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void addNotificationListener(ObjectName name,
        NotificationListener listener,
        NotificationFilter filter,
        Object handback)
        throws InstanceNotFoundException,
        IOException {

    final boolean debug = logger.debugOn();

    if (debug)
        logger.debug("addNotificationListener" +
                "(ObjectName,NotificationListener,"+
                "NotificationFilter,Object)",
                "name=" + name
                + ", listener=" + listener
                + ", filter=" + filter
                + ", handback=" + handback);

    final Integer listenerID =
            addListenerWithSubject(name,
            new MarshalledObject<NotificationFilter>(filter),
            delegationSubject,true);
    rmiNotifClient.addNotificationListener(listenerID, name, listener,
            filter, handback,
            delegationSubject);
}
 
Example #3
Source File: DefaultMBeanServerInterceptor.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       ObjectName listener,
                                       NotificationFilter filter,
                                       Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {

    NotificationListener instance = getListener(listener);

    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "removeNotificationListener",
                "ObjectName = " + name + ", Listener = " + listener);
    }
    server.removeNotificationListener(name, instance, filter, handback);
}
 
Example #4
Source File: RequiredModelMBean.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes a listener for Notifications from the RequiredModelMBean.
 *
 * @param listener The listener name which was handling notifications
 *    emitted by the registered MBean.
 *    This method will remove all information related to this listener.
 *
 * @exception ListenerNotFoundException The listener is not registered
 *    in the MBean or is null.
 *
 * @see #addNotificationListener
 **/
public void removeNotificationListener(NotificationListener listener)
    throws ListenerNotFoundException {
    if (listener == null)
        throw new ListenerNotFoundException(
                  "Notification listener is null");

    final String mth="removeNotificationListener(NotificationListener)";
    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);
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(), mth, "Exit");
    }

}
 
Example #5
Source File: RMIConnector.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void addNotificationListener(ObjectName name,
        NotificationListener listener,
        NotificationFilter filter,
        Object handback)
        throws InstanceNotFoundException,
        IOException {

    final boolean debug = logger.debugOn();

    if (debug)
        logger.debug("addNotificationListener" +
                "(ObjectName,NotificationListener,"+
                "NotificationFilter,Object)",
                "name=" + name
                + ", listener=" + listener
                + ", filter=" + filter
                + ", handback=" + handback);

    final Integer listenerID =
            addListenerWithSubject(name,
            new MarshalledObject<NotificationFilter>(filter),
            delegationSubject,true);
    rmiNotifClient.addNotificationListener(listenerID, name, listener,
            filter, handback,
            delegationSubject);
}
 
Example #6
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: OldMBeanServerTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private NotificationListener wrappedListener(
        ObjectName name, Object userMBean, NotificationListener userListener)
throws InstanceNotFoundException {
    ListenerTable table = new ListenerTable();
    ListenerTable oldTable = listenerMap.putIfAbsent(name, table);
    if (oldTable != null)
        table = oldTable;
    NotificationListener identityListener =
            new IdentityListener(userListener);
    synchronized (table) {
        NotificationListener rewriteListener = null;
        WeakReference<NotificationListener> wr =
                table.get(identityListener);
        if (wr != null)
            rewriteListener = wr.get();
        if (rewriteListener == null) {
            rewriteListener = new RewriteListener(
                    name, userMBean, identityListener);
            wr = new WeakReference<NotificationListener>(rewriteListener);
            table.put(identityListener, wr);
        }
        return rewriteListener;
    }
}
 
Example #8
Source File: BaseModelMBean.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Remove a notification event listener from this MBean.
 *
 * @param listener The listener to be removed (any and all registrations
 *  for this listener will be eliminated)
 *
 * @exception ListenerNotFoundException if this listener is not
 *  registered in the MBean
 */
@Override
public void removeNotificationListener(NotificationListener listener)
    throws ListenerNotFoundException {

    if (listener == null)
        throw new IllegalArgumentException("Listener is null");

    if (generalBroadcaster != null) {
        generalBroadcaster.removeNotificationListener(listener);
    }

    if (attributeBroadcaster != null) {
        attributeBroadcaster.removeNotificationListener(listener);
    }
 }
 
Example #9
Source File: OldMBeanServerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private NotificationListener wrappedListener(
        ObjectName name, Object userMBean, NotificationListener userListener)
throws InstanceNotFoundException {
    ListenerTable table = new ListenerTable();
    ListenerTable oldTable = listenerMap.putIfAbsent(name, table);
    if (oldTable != null)
        table = oldTable;
    NotificationListener identityListener =
            new IdentityListener(userListener);
    synchronized (table) {
        NotificationListener rewriteListener = null;
        WeakReference<NotificationListener> wr =
                table.get(identityListener);
        if (wr != null)
            rewriteListener = wr.get();
        if (rewriteListener == null) {
            rewriteListener = new RewriteListener(
                    name, userMBean, identityListener);
            wr = new WeakReference<NotificationListener>(rewriteListener);
            table.put(identityListener, wr);
        }
        return rewriteListener;
    }
}
 
Example #10
Source File: BaseModelMBean.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Add an attribute change notification event listener to this MBean.
 *
 * @param listener Listener that will receive event notifications
 * @param name Name of the attribute of interest, or <code>null</code>
 *  to indicate interest in all attributes
 * @param handback Handback object to be sent along with event
 *  notifications
 *
 * @exception IllegalArgumentException if the listener parameter is null
 */
@Override
public void addAttributeChangeNotificationListener
    (NotificationListener listener, String name, Object handback)
    throws IllegalArgumentException {

    if (listener == null)
        throw new IllegalArgumentException("Listener is null");
    if (attributeBroadcaster == null)
        attributeBroadcaster = new BaseNotificationBroadcaster();

    if( log.isDebugEnabled() )
        log.debug("addAttributeNotificationListener " + listener);

    BaseAttributeFilter filter = new BaseAttributeFilter(name);
    attributeBroadcaster.addNotificationListener
        (listener, filter, handback);

}
 
Example #11
Source File: BaseModelMBean.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Remove a notification event listener from this MBean.
 *
 * @param listener The listener to be removed (any and all registrations
 *  for this listener will be eliminated)
 *
 * @exception ListenerNotFoundException if this listener is not
 *  registered in the MBean
 */
@Override
public void removeNotificationListener(NotificationListener listener)
    throws ListenerNotFoundException {

    if (listener == null)
        throw new IllegalArgumentException("Listener is null");

    if (generalBroadcaster != null) {
        generalBroadcaster.removeNotificationListener(listener);
    }

    if (attributeBroadcaster != null) {
        attributeBroadcaster.removeNotificationListener(listener);
    }
 }
 
Example #12
Source File: SnmpMibTable.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Enable to remove an SNMP entry listener from this
 * <CODE>SnmpMibTable</CODE>.
 *
 * @param listener The listener object which will handle the
 *    notifications emitted by the registered MBean.
 *    This method will remove all the information related to this
 *    listener.
 *
 * @exception ListenerNotFoundException The listener is not registered
 *    in the MBean.
 */
@Override
public synchronized void
    removeNotificationListener(NotificationListener listener)
    throws ListenerNotFoundException {

    // looking for listener in handbackTable
    //
    java.util.Vector<?> handbackList = handbackTable.get(listener) ;
    if ( handbackList == null ) {
        throw new ListenerNotFoundException("listener");
    }

    // If handback is null, remove the listener entry
    //
    handbackTable.remove(listener) ;
    filterTable.remove(listener) ;
}
 
Example #13
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       ObjectName listener,
                                       NotificationFilter filter,
                                       Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {

    NotificationListener instance = getListener(listener);

    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "removeNotificationListener",
                "ObjectName = " + name + ", Listener = " + listener);
    }
    server.removeNotificationListener(name, instance, filter, handback);
}
 
Example #14
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       ObjectName listener,
                                       NotificationFilter filter,
                                       Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {

    NotificationListener instance = getListener(listener);

    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "removeNotificationListener",
                "ObjectName = " + name + ", Listener = " + listener);
    }
    server.removeNotificationListener(name, instance, filter, handback);
}
 
Example #15
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    removeNotificationListener(name, listener, filter, handback, false);
}
 
Example #16
Source File: DefaultMBeanServerInterceptor.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListener(ObjectName name,
                                    NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
        throws InstanceNotFoundException {

    // ------------------------------
    // ------------------------------
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "addNotificationListener", "ObjectName = " + name);
    }

    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, null, name, "addNotificationListener");

    NotificationBroadcaster broadcaster =
            getNotificationBroadcaster(name, instance,
                                       NotificationBroadcaster.class);

    // ------------------
    // Check listener
    // ------------------
    if (listener == null) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Null listener"),"Null listener");
    }

    NotificationListener listenerWrapper =
        getListenerWrapper(listener, name, instance, true);
    broadcaster.addNotificationListener(listenerWrapper, filter, handback);
}
 
Example #17
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListener(ObjectName name,
                                    ObjectName listener,
                                    NotificationFilter filter,
                                    Object handback)
        throws InstanceNotFoundException {

    // ------------------------------
    // ------------------------------

    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance = getMBean(listener);
    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException(listener.getCanonicalName()),
            "The MBean " + listener.getCanonicalName() +
            "does not implement the NotificationListener interface") ;
    }

    // ----------------
    // Add a listener on an MBean
    // ----------------
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "addNotificationListener",
                "ObjectName = " + name + ", Listener = " + listener);
    }
    server.addNotificationListener(name,(NotificationListener) resource,
                                   filter, handback) ;
}
 
Example #18
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void removeNotificationListener(ObjectName name,
                                        NotificationListener listener,
                                        NotificationFilter filter,
                                        Object handback,
                                        boolean removeAll)
        throws InstanceNotFoundException, ListenerNotFoundException {

    if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
        MBEANSERVER_LOGGER.log(Level.TRACE, "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);
    }
}
 
Example #19
Source File: RMIConnector.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void removeNotificationListener(ObjectName name,
        NotificationListener listener)
        throws InstanceNotFoundException,
        ListenerNotFoundException,
        IOException {

    final boolean debug = logger.debugOn();

    if (debug) logger.debug("removeNotificationListener"+
            "(ObjectName,NotificationListener)",
            "name=" + name
            + ", listener=" + listener);

    final Integer[] ret =
            rmiNotifClient.removeNotificationListener(name, listener);

    if (debug) logger.debug("removeNotificationListener",
            "listenerIDs=" + objects(ret));

    final ClassLoader old = pushDefaultClassLoader();

    try {
        connection.removeNotificationListeners(name,
                ret,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.removeNotificationListeners(name,
                ret,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }

}
 
Example #20
Source File: OldMBeanServerTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationEmitter userMBean =
            (NotificationEmitter) getMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener, filter, handback);
}
 
Example #21
Source File: OldMBeanServerTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, NotificationListener listener)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationBroadcaster userMBean =
            (NotificationBroadcaster) getUserMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener);
}
 
Example #22
Source File: SnmpMibTable.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Enable this <CODE>SnmpMibTable</CODE> to send a notification.
 *
 * <p>
 * @param notification The notification to send.
 */
private synchronized void sendNotification(Notification notification) {

    // loop on listener
    //
    for(java.util.Enumeration<NotificationListener> k = handbackTable.keys();
        k.hasMoreElements(); ) {

        NotificationListener listener = k.nextElement();

        // Get the associated handback list and the associated filter list
        //
        java.util.Vector<?> handbackList = handbackTable.get(listener) ;
        java.util.Vector<NotificationFilter> filterList =
            filterTable.get(listener) ;

        // loop on handback
        //
        java.util.Enumeration<NotificationFilter> f = filterList.elements();
        for(java.util.Enumeration<?> h = handbackList.elements();
            h.hasMoreElements(); ) {

            Object handback = h.nextElement();
            NotificationFilter filter = f.nextElement();

            if ((filter == null) ||
                 (filter.isNotificationEnabled(notification))) {

                listener.handleNotification(notification,handback) ;
            }
        }
    }
}
 
Example #23
Source File: OldMBeanServerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException {
    NotificationBroadcaster userMBean =
            (NotificationBroadcaster) getUserMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.addNotificationListener(wrappedListener, filter, handback);
}
 
Example #24
Source File: NotificationEmitterSupport.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListener(NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback) {

    if (listener == null) {
        throw new IllegalArgumentException ("Listener can't be null") ;
    }

    /* Adding a new listener takes O(n) time where n is the number
       of existing listeners.  If you have a very large number of
       listeners performance could degrade.  That's a fairly
       surprising configuration, and it is hard to avoid this
       behaviour while still retaining the property that the
       listenerList is not synchronized while notifications are
       being sent through it.  If this becomes a problem, a
       possible solution would be a multiple-readers single-writer
       setup, so any number of sendNotification() calls could run
       concurrently but they would exclude an
       add/removeNotificationListener.  A simpler but less
       efficient solution would be to clone the listener list
       every time a notification is sent.  */
    synchronized (listenerLock) {
        List<ListenerInfo> newList = new ArrayList<>(listenerList.size() + 1);
        newList.addAll(listenerList);
        newList.add(new ListenerInfo(listener, filter, handback));
        listenerList = newList;
    }
}
 
Example #25
Source File: OldMBeanServerTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationEmitter userMBean =
            (NotificationEmitter) getMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener, filter, handback);
}
 
Example #26
Source File: RMIConnector.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(ObjectName name,
        NotificationListener listener)
        throws InstanceNotFoundException,
        ListenerNotFoundException,
        IOException {

    final boolean debug = logger.debugOn();

    if (debug) logger.debug("removeNotificationListener"+
            "(ObjectName,NotificationListener)",
            "name=" + name
            + ", listener=" + listener);

    final Integer[] ret =
            rmiNotifClient.removeNotificationListener(name, listener);

    if (debug) logger.debug("removeNotificationListener",
            "listenerIDs=" + objects(ret));

    final ClassLoader old = pushDefaultClassLoader();

    try {
        connection.removeNotificationListeners(name,
                ret,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.removeNotificationListeners(name,
                ret,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }

}
 
Example #27
Source File: OldMBeanServerTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException {
    NotificationBroadcaster userMBean =
            (NotificationBroadcaster) getUserMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.addNotificationListener(wrappedListener, filter, handback);
}
 
Example #28
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void
        removeConnectionNotificationListener(NotificationListener listener)
        throws ListenerNotFoundException {
    if (listener == null)
        throw new NullPointerException("listener");
    connectionBroadcaster.removeNotificationListener(listener);
}
 
Example #29
Source File: ClientNotifForwarder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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]);
}
 
Example #30
Source File: DefaultMBeanServerInterceptor.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void addNotificationListener(ObjectName name,
                                    ObjectName listener,
                                    NotificationFilter filter,
                                    Object handback)
        throws InstanceNotFoundException {

    // ------------------------------
    // ------------------------------

    // ----------------
    // Get listener object
    // ----------------
    DynamicMBean instance = getMBean(listener);
    Object resource = getResource(instance);
    if (!(resource instanceof NotificationListener)) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException(listener.getCanonicalName()),
            "The MBean " + listener.getCanonicalName() +
            "does not implement the NotificationListener interface") ;
    }

    // ----------------
    // Add a listener on an MBean
    // ----------------
    if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
        MBEANSERVER_LOGGER.logp(Level.FINER,
                DefaultMBeanServerInterceptor.class.getName(),
                "addNotificationListener",
                "ObjectName = " + name + ", Listener = " + listener);
    }
    server.addNotificationListener(name,(NotificationListener) resource,
                                   filter, handback) ;
}