Java Code Examples for javax.management.NotificationListener

The following are top voted examples for showing how to use javax.management.NotificationListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: RMIConnector.java   View source code 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 2
Project: Pogamut3   File: PogamutMBeanServer.java   View source code 6 votes vote down vote up
@Override
public synchronized void removeNotificationListener(ObjectName name,
		NotificationListener listener) throws InstanceNotFoundException,
		ListenerNotFoundException {		
	mbs.removeNotificationListener(name, listener);
	
	// TODO: slow implementation ... but fast one takes a lot of time to do :-)
	Iterator<Listener2> iter = listeners2.iterator();
	while(iter.hasNext()) {
		Listener2 l = iter.next();
		if (SafeEquals.equals(name, l.name) && SafeEquals.equals(listener, l.listener)) {
			listeners.remove(l);
			unregisteredListeners.remove(l);
			iter.remove();
		}
	}
}
 
Example 3
Project: OpenJSharp   File: RequiredModelMBean.java   View source code 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 4
Project: openjdk-jdk10   File: ClientNotifForwarder.java   View source code 6 votes vote down vote up
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 liId = getListenerId(name, listener,
            filter, handback);
    infoList.remove(liId);

    return liId;
}
 
Example 5
Project: jdk8u-jdk   File: ClientNotifForwarder.java   View source code 6 votes vote down vote up
public synchronized void addNotificationListener(Integer listenerID,
                                    ObjectName name,
                                    NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback,
                                    Subject delegationSubject)
        throws IOException, InstanceNotFoundException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
                     "Add the listener "+listener+" at "+name);
    }

    infoList.put(listenerID,
                 new ClientListenerInfo(listenerID,
                                        name,
                                        listener,
                                        filter,
                                        handback,
                                        delegationSubject));


    init(false);
}
 
Example 6
Project: jdk8u-jdk   File: ScanDirAgent.java   View source code 6 votes vote down vote up
/**
 * Creates a new instance of ScanDirAgent
 * You will need to call {@link #init()} later on in order to initialize
 * the application.
 * @see #main
 **/
public ScanDirAgent() {
    // Initialize the notification queue
    queue = new LinkedBlockingQueue<Notification>();

    // Creates the listener.
    listener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            try {
                // Just put the received notification in the queue.
                // It will be consumed later on by 'waitForClose()'
                //
                LOG.finer("Queuing received notification "+notification);
                queue.put(notification);
            } catch (InterruptedException ex) {
                // OK
            }
        }
    };
}
 
Example 7
Project: openjdk-jdk10   File: RequiredModelMBean.java   View source code 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");

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }

    if (generalBroadcaster == null)
        throw new ListenerNotFoundException(
              "No notification listeners registered");


    generalBroadcaster.removeNotificationListener(listener);
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }

}
 
Example 8
Project: tomcat7   File: BaseNotificationBroadcaster.java   View source code 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 {

    synchronized (entries) {
        Iterator<BaseNotificationBroadcasterEntry> items =
            entries.iterator();
        while (items.hasNext()) {
            BaseNotificationBroadcasterEntry item = items.next();
            if (item.listener == listener)
                items.remove();
        }
    }

}
 
Example 9
Project: tomcat7   File: BaseModelMBean.java   View source code 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 10
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   View source code 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 11
Project: tomcat7   File: ConnectionPool.java   View source code 6 votes vote down vote up
/**
 * Return true if the notification was sent successfully, false otherwise.
 * @param type
 * @param message
 * @return true if the notification succeeded
 */
public boolean notify(final String type, String message) {
    try {
        Notification n = new Notification(
                type,
                this,
                sequence.incrementAndGet(),
                System.currentTimeMillis(),
                "["+type+"] "+message);
        sendNotification(n);
        for (NotificationListener listener : listeners) {
            listener.handleNotification(n,this);
        }
        return true;
    }catch (Exception x) {
        if (log.isDebugEnabled()) {
            log.debug("Notify failed. Type="+type+"; Message="+message,x);
        }
        return false;
    }

}
 
Example 12
Project: OpenJSharp   File: ClientNotifForwarder.java   View source code 6 votes vote down vote up
public synchronized void addNotificationListener(Integer listenerID,
                                    ObjectName name,
                                    NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback,
                                    Subject delegationSubject)
        throws IOException, InstanceNotFoundException {

    if (logger.traceOn()) {
        logger.trace("addNotificationListener",
                     "Add the listener "+listener+" at "+name);
    }

    infoList.put(listenerID,
                 new ClientListenerInfo(listenerID,
                                        name,
                                        listener,
                                        filter,
                                        handback,
                                        delegationSubject));


    init(false);
}
 
Example 13
Project: jdk8u-jdk   File: ArrayNotificationBuffer.java   View source code 6 votes vote down vote up
private void addNotificationListener(final ObjectName name,
                                     final NotificationListener listener,
                                     final NotificationFilter filter,
                                     final Object handback)
        throws Exception {
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
            public Void run() throws InstanceNotFoundException {
                mBeanServer.addNotificationListener(name,
                                                    listener,
                                                    filter,
                                                    handback);
                return null;
            }
        });
    } catch (Exception e) {
        throw extractException(e);
    }
}
 
Example 14
Project: lazycat   File: BaseModelMBean.java   View source code 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 15
Project: apache-tomcat-7.0.73-with-comment   File: BaseModelMBean.java   View source code 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 16
Project: jdk8u-jdk   File: RMIConnector.java   View source code 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 17
Project: OpenJSharp   File: NotificationEmitterSupport.java   View source code 6 votes vote down vote up
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;
    }
}
 
Example 18
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   View source code 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 19
Project: jdk8u-jdk   File: ConcurrentModificationTest.java   View source code 6 votes vote down vote up
private static void listenerOp(MBeanServerConnection mserver, NotificationListener listener, boolean adding)
        throws Exception {
    if (adding) {
        mserver.addNotificationListener(delegateName, listener, null, null);
    } else {
        mserver.removeNotificationListener(delegateName, listener);
    }
}
 
Example 20
Project: openjdk-jdk10   File: RequiredModelMBean.java   View source code 6 votes vote down vote up
public void removeNotificationListener(NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
    throws ListenerNotFoundException {

    if (listener == null)
        throw new ListenerNotFoundException(
                  "Notification listener is null");

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }

    if (generalBroadcaster == null)
        throw new ListenerNotFoundException(
              "No notification listeners registered");


    generalBroadcaster.removeNotificationListener(listener,filter,
                                                  handback);

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }

}
 
Example 21
Project: jdk8u-jdk   File: RequiredModelMBean.java   View source code 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 22
Project: jdk8u-jdk   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
RewriteListener(
        ObjectName name, Object userMBean,
        NotificationListener userListener) {
    this.name = name;
    this.userMBean = userMBean;
    this.userListener = userListener;
}
 
Example 23
Project: Pogamut3   File: PogamutMBeanServer.java   View source code 5 votes vote down vote up
public Listener2(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) {
	this.name = name;
	this.listener = listener;
	this.filter = filter;
	this.handback = handback;
	HashCode hc = new HashCode();
	hc.add(name);
	hc.add(listener);
	hc.add(filter);
	hc.add(handback);
	this.hashCode = hc.getHash();
}
 
Example 24
Project: Pogamut3   File: PogamutMBeanServer.java   View source code 5 votes vote down vote up
@Override
public synchronized void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
		Object handback) throws InstanceNotFoundException {		
	mbs.addNotificationListener(name, listener, filter, handback);
	Listener2 l = new Listener2(name, listener, filter, handback);
	listeners.add(l);
	listeners2.add(l);
}
 
Example 25
Project: jdk8u-jdk   File: SnmpMibTable.java   View source code 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 26
Project: jdk8u-jdk   File: SnmpMibTable.java   View source code 5 votes vote down vote up
/**
 * Enable to add an SNMP entry listener to this
 * <CODE>SnmpMibTable</CODE>.
 *
 * <p>
 * @param listener The listener object which will handle the
 *    notifications emitted by the registered MBean.
 *
 * @param filter The filter object. If filter is null, no filtering
 *    will be performed before handling notifications.
 *
 * @param handback The context to be sent to the listener when a
 *    notification is emitted.
 *
 * @exception IllegalArgumentException Listener parameter is null.
 */
@Override
public synchronized void
    addNotificationListener(NotificationListener listener,
                            NotificationFilter filter, Object handback)  {

    // Check listener
    //
    if (listener == null) {
        throw new java.lang.IllegalArgumentException
            ("Listener can't be null") ;
    }

    // looking for listener in handbackTable
    //
    Vector<Object> handbackList = handbackTable.get(listener) ;
    Vector<NotificationFilter> filterList = filterTable.get(listener) ;
    if ( handbackList == null ) {
        handbackList = new Vector<>() ;
        filterList = new Vector<>() ;
        handbackTable.put(listener, handbackList) ;
        filterTable.put(listener, filterList) ;
    }

    // Add the handback and the filter
    //
    handbackList.addElement(handback) ;
    filterList.addElement(filter) ;
}
 
Example 27
Project: openjdk-jdk10   File: OldMBeanServerTest.java   View source code 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 28
Project: jdk8u-jdk   File: RMIConnector.java   View source code 5 votes vote down vote up
public void
        addConnectionNotificationListener(NotificationListener listener,
        NotificationFilter filter,
        Object handback) {
    if (listener == null)
        throw new NullPointerException("listener");
    connectionBroadcaster.addNotificationListener(listener, filter,
            handback);
}
 
Example 29
Project: lazycat   File: BaseModelMBean.java   View source code 5 votes vote down vote up
/**
 * Add a notification event listener to this MBean.
 *
 * @param listener
 *            Listener that will receive event notifications
 * @param filter
 *            Filter object used to filter event notifications actually
 *            delivered, or <code>null</code> for no filtering
 * @param handback
 *            Handback object to be sent along with event notifications
 *
 * @exception IllegalArgumentException
 *                if the listener parameter is null
 */
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
		throws IllegalArgumentException {

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

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

	if (generalBroadcaster == null)
		generalBroadcaster = new BaseNotificationBroadcaster();
	generalBroadcaster.addNotificationListener(listener, filter, handback);

	// We'll send the attribute change notifications to all listeners ( who
	// care )
	// The normal filtering can be used.
	// The problem is that there is no other way to add attribute change
	// listeners
	// to a model mbean ( AFAIK ). I suppose the spec should be fixed.
	if (attributeBroadcaster == null)
		attributeBroadcaster = new BaseNotificationBroadcaster();

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

	attributeBroadcaster.addNotificationListener(listener, filter, handback);
}
 
Example 30
Project: openjdk-jdk10   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public void addNotificationListener(ObjectName name,
                                    NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
    throws InstanceNotFoundException {
    checkRead();
    getMBeanServer().addNotificationListener(name, listener,
                                             filter, handback);
}
 
Example 31
Project: tomcat7   File: BaseNotificationBroadcaster.java   View source code 5 votes vote down vote up
public BaseNotificationBroadcasterEntry(NotificationListener listener,
                                        NotificationFilter filter,
                                        Object handback) {
    this.listener = listener;
    this.filter = filter;
    this.handback = handback;
}
 
Example 32
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   View source code 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 33
Project: openjdk-jdk10   File: OldMBeanServerTest.java   View source code 5 votes vote down vote up
public void addNotificationListener(
        ObjectName name, ObjectName listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException {
    NotificationListener nl =
            (NotificationListener) getUserMBean(listener);
    addNotificationListener(name, nl, filter, handback);
}
 
Example 34
Project: tomcat7   File: BaseModelMBean.java   View source code 5 votes vote down vote up
/**
 * Add a notification event listener to this MBean.
 *
 * @param listener Listener that will receive event notifications
 * @param filter Filter object used to filter event notifications
 *  actually delivered, or <code>null</code> for no filtering
 * @param handback Handback object to be sent along with event
 *  notifications
 *
 * @exception IllegalArgumentException if the listener parameter is null
 */
@Override
public void addNotificationListener(NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
    throws IllegalArgumentException {

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

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

    if (generalBroadcaster == null)
        generalBroadcaster = new BaseNotificationBroadcaster();
    generalBroadcaster.addNotificationListener
        (listener, filter, handback);

    // We'll send the attribute change notifications to all listeners ( who care )
    // The normal filtering can be used.
    // The problem is that there is no other way to add attribute change listeners
    // to a model mbean ( AFAIK ). I suppose the spec should be fixed.
    if (attributeBroadcaster == null)
        attributeBroadcaster = new BaseNotificationBroadcaster();

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

    attributeBroadcaster.addNotificationListener
            (listener, filter, handback);
}
 
Example 35
Project: jdk8u-jdk   File: ClientNotifForwarder.java   View source code 5 votes vote down vote up
void dispatchNotification(TargetedNotification tn,
                          Integer myListenerID,
                          Map<Integer, ClientListenerInfo> listeners) {
    final Notification notif = tn.getNotification();
    final Integer listenerID = tn.getListenerID();

    if (listenerID.equals(myListenerID)) return;
    final ClientListenerInfo li = listeners.get(listenerID);

    if (li == null) {
        logger.trace("NotifFetcher.dispatch",
                     "Listener ID not in map");
        return;
    }

    NotificationListener l = li.getListener();
    Object h = li.getHandback();
    try {
        l.handleNotification(notif, h);
    } catch (RuntimeException e) {
        final String msg =
            "Failed to forward a notification " +
            "to a listener";
        logger.trace("NotifFetcher-run", msg, e);
    }

}
 
Example 36
Project: jdk8u-jdk   File: GarbageCollectorImpl.java   View source code 5 votes vote down vote up
public synchronized void removeNotificationListener(NotificationListener listener,
                                                    NotificationFilter filter,
                                                    Object handback)
        throws ListenerNotFoundException
{
    boolean before = hasListeners();
    super.removeNotificationListener(listener,filter,handback);
    boolean after = hasListeners();
    if (before && !after) {
        setNotificationEnabled(this,false);
    }
}
 
Example 37
Project: jdk8u-jdk   File: MBeanServerAccessController.java   View source code 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener,
                                       NotificationFilter filter,
                                       Object handback)
    throws InstanceNotFoundException, ListenerNotFoundException {
    checkRead();
    getMBeanServer().removeNotificationListener(name, listener,
                                                filter, handback);
}
 
Example 38
Project: OpenJSharp   File: ClientListenerInfo.java   View source code 5 votes vote down vote up
public ClientListenerInfo(Integer listenerID,
                          ObjectName name,
                          NotificationListener listener,
                          NotificationFilter filter,
                          Object handback,
                          Subject delegationSubject) {
    this.listenerID = listenerID;
    this.name = name;
    this.listener = listener;
    this.filter = filter;
    this.handback = handback;
    this.delegationSubject = delegationSubject;
}
 
Example 39
Project: openjdk-jdk10   File: DiagnosticCommandImpl.java   View source code 5 votes vote down vote up
@Override
public synchronized void removeNotificationListener(NotificationListener listener,
        NotificationFilter filter,
        Object handback)
        throws ListenerNotFoundException {
    boolean before = hasListeners();
    super.removeNotificationListener(listener, filter, handback);
    boolean after = hasListeners();
    if (before && !after) {
        setNotificationEnabled(false);
    }
}
 
Example 40
Project: openjdk-jdk10   File: OldMBeanServerTest.java   View source code 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);
}