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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and 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 {

    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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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 41
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 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 42
Project: lams   File: BaseNotificationBroadcaster.java   Source Code and License 5 votes vote down vote up
public BaseNotificationBroadcasterEntry(NotificationListener listener,
                                        NotificationFilter filter,
                                        Object handback) {
    this.listener = listener;
    this.filter = filter;
    this.handback = handback;
}
 
Example 43
Project: lams   File: BaseModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Remove an attribute change notification event listener from
 * this MBean.
 *
 * @param listener The listener to be removed
 * @param name The attribute name for which no more events are required
 *
 *
 * @exception ListenerNotFoundException if this listener is not
 *  registered in the MBean
 */
public void removeAttributeChangeNotificationListener
    (NotificationListener listener, String name)
    throws ListenerNotFoundException {

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

    // FIXME - currently this removes *all* notifications for this listener
    attributeBroadcaster.removeNotificationListener(listener);

}
 
Example 44
Project: lams   File: BaseModelMBean.java   Source Code and License 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
 */
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 45
Project: openjdk-jdk10   File: DiagnosticCommandImpl.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized void addNotificationListener(NotificationListener listener,
        NotificationFilter filter,
        Object handback) {
    boolean before = hasListeners();
    super.addNotificationListener(listener, filter, handback);
    boolean after = hasListeners();
    if (!before && after) {
        setNotificationEnabled(true);
    }
}
 
Example 46
Project: jdk8u-jdk   File: CommunicatorServer.java   Source Code and License 5 votes vote down vote up
/**
 * Removes the specified listener from this CommunicatorServer.
 * Note that if the listener has been registered with different
 * handback objects or notification filters, all entries corresponding
 * to the listener will be removed.
 *
 * @param listener The listener object to be removed.
 *
 * @exception ListenerNotFoundException The listener is not registered.
 */
@Override
public void removeNotificationListener(NotificationListener listener)
    throws ListenerNotFoundException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag,
            "removeNotificationListener","Removing listener "+ listener);
    }
    notifBroadcaster.removeNotificationListener(listener);
}
 
Example 47
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 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 48
Project: jdk8u-jdk   File: RMIConnector.java   Source Code and License 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 49
Project: OpenJSharp   File: ClientNotifForwarder.java   Source Code and License 5 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 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;
}
 
Example 50
Project: OpenJSharp   File: NotificationEmitterSupport.java   Source Code and License 5 votes vote down vote up
public ListenerInfo(NotificationListener listener,
                    NotificationFilter filter,
                    Object handback) {
    this.listener = listener;
    this.filter = filter;
    this.handback = handback;
}
 
Example 51
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 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 52
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, ObjectName listener)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationListener nl =
            (NotificationListener) getUserMBean(listener);
    removeNotificationListener(name, nl);
}
 
Example 53
Project: hashsdn-controller   File: ConfigPersisterNotificationHandler.java   Source Code and License 5 votes vote down vote up
private static void registerAsJMXListener(final MBeanServerConnection mBeanServerConnection, final NotificationListener listener) {
    LOG.trace("Called registerAsJMXListener");
    try {
        mBeanServerConnection.addNotificationListener(ConfigJMXNotification.OBJECT_NAME, listener, null, null);
    } catch (InstanceNotFoundException | IOException e) {
        throw new IllegalStateException("Cannot register as JMX listener to netconf", e);
    }
}
 
Example 54
Project: jdk8u-jdk   File: RMIConnector.java   Source Code and License 5 votes vote down vote up
public void
        removeConnectionNotificationListener(NotificationListener listener,
        NotificationFilter filter,
        Object handback)
        throws ListenerNotFoundException {
    if (listener == null)
        throw new NullPointerException("listener");
    connectionBroadcaster.removeNotificationListener(listener, filter,
            handback);
}
 
Example 55
Project: OpenJSharp   File: JmxMBeanServer.java   Source Code and License 5 votes vote down vote up
public void removeNotificationListener(ObjectName name,
                                       NotificationListener listener)
        throws InstanceNotFoundException, ListenerNotFoundException {

    mbsInterceptor.removeNotificationListener(cloneObjectName(name),
                                              listener);
}
 
Example 56
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License 4 votes vote down vote up
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
    nbs.removeNotificationListener(listener);
}
 
Example 57
Project: jdk8u-jdk   File: Basic.java   Source Code and License 4 votes vote down vote up
public void removeNotificationListener(NotificationListener listener)
        throws ListenerNotFoundException {
    broadcaster.removeNotificationListener(listener);
}
 
Example 58
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 4 votes vote down vote up
private synchronized void innerAddNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
		Object handback) throws InstanceNotFoundException {		
	mbs.addNotificationListener(name, listener, filter, handback);		
}
 
Example 59
Project: jdk8u-jdk   File: ConcurrentModificationTest.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println(">>> test on Concurrent Modification.");

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            if (e instanceof ConcurrentModificationException) {
                uncaughtException = e;
            }
        }
    });

    delegateName = new ObjectName("JMImplementation:type=MBeanServerDelegate");
    for (int i=0; i<number; i++) {
        timerNames[i] = new ObjectName("MBean:name=Timer"+i);
        listeners[i] = new NotificationListener() {
            @Override
            public void handleNotification(Notification notification, Object handback) {
                // nothing
            }
        };
    }
    String errors = "";

    for (int i = 0; i < protocols.length; i++) {
        uncaughtException = null;
        System.out.println(">>> Test for protocol " + protocols[i]);
        test(protocols[i]);
        if (uncaughtException != null) {
            if ("".equals(errors)) {
                errors = "Failed to " + protocols[i] + ": "+uncaughtException;
            } else {
                errors = errors+", failed to " + protocols[i] + ": "+uncaughtException;
            }
            System.out.println(">>> FAILED for protocol " + protocols[i]);
        } else {
            System.out.println(">>> PASSED for protocol " + protocols[i]);
        }
    }

    if ("".equals(errors)) {
        System.out.println("All Passed!");
    } else {
        System.out.println("!!!!!! Failed.");

        throw new RuntimeException(errors);
    }
}
 
Example 60
Project: hashsdn-controller   File: ConfigPersisterNotificationHandler.java   Source Code and License 4 votes vote down vote up
public ConfigPersisterNotificationHandler(final MBeanServerConnection mBeanServerConnection, final NotificationListener notificationListener) {
    this.mBeanServerConnection = mBeanServerConnection;
    this.listener = notificationListener;
    registerAsJMXListener(mBeanServerConnection, listener);
}