java类javax.management.NotificationListener的实例源码

RMIConnector.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
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);
}
PogamutMBeanServer.java 文件源码 项目:Pogamut3 阅读 19 收藏 0 点赞 0 评论 0
@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();
        }
    }
}
RequiredModelMBean.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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");
    }

}
ClientNotifForwarder.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
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;
}
ClientNotifForwarder.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
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);
}
ScanDirAgent.java 文件源码 项目:jdk8u-jdk 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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
            }
        }
    };
}
RequiredModelMBean.java 文件源码 项目:openjdk-jdk10 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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");
    }

}
BaseNotificationBroadcaster.java 文件源码 项目:tomcat7 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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();
        }
    }

}
BaseModelMBean.java 文件源码 项目:tomcat7 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);

}
DefaultMBeanServerInterceptor.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
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);
}
ConnectionPool.java 文件源码 项目:tomcat7 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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;
    }

}
ClientNotifForwarder.java 文件源码 项目:OpenJSharp 阅读 29 收藏 0 点赞 0 评论 0
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);
}
ArrayNotificationBuffer.java 文件源码 项目:jdk8u-jdk 阅读 27 收藏 0 点赞 0 评论 0
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);
    }
}
BaseModelMBean.java 文件源码 项目:lazycat 阅读 17 收藏 0 点赞 0 评论 0
/**
 * 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);

}
BaseModelMBean.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 16 收藏 0 点赞 0 评论 0
/**
 * 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);

}
RMIConnector.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
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);
}
NotificationEmitterSupport.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
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;
    }
}
DefaultMBeanServerInterceptor.java 文件源码 项目:OpenJSharp 阅读 27 收藏 0 点赞 0 评论 0
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);
}
ConcurrentModificationTest.java 文件源码 项目:jdk8u-jdk 阅读 17 收藏 0 点赞 0 评论 0
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);
    }
}
RequiredModelMBean.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
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");
    }

}
RequiredModelMBean.java 文件源码 项目:jdk8u-jdk 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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");
    }

}
OldMBeanServerTest.java 文件源码 项目:jdk8u-jdk 阅读 29 收藏 0 点赞 0 评论 0
RewriteListener(
        ObjectName name, Object userMBean,
        NotificationListener userListener) {
    this.name = name;
    this.userMBean = userMBean;
    this.userListener = userListener;
}
PogamutMBeanServer.java 文件源码 项目:Pogamut3 阅读 30 收藏 0 点赞 0 评论 0
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();
}
PogamutMBeanServer.java 文件源码 项目:Pogamut3 阅读 25 收藏 0 点赞 0 评论 0
@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);
}
SnmpMibTable.java 文件源码 项目:jdk8u-jdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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) ;
            }
        }
    }
}
SnmpMibTable.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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) ;
}
OldMBeanServerTest.java 文件源码 项目:openjdk-jdk10 阅读 39 收藏 0 点赞 0 评论 0
public void removeNotificationListener(
        ObjectName name, NotificationListener listener)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationBroadcaster userMBean =
            (NotificationBroadcaster) getUserMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener);
}
RMIConnector.java 文件源码 项目:jdk8u-jdk 阅读 28 收藏 0 点赞 0 评论 0
public void
        addConnectionNotificationListener(NotificationListener listener,
        NotificationFilter filter,
        Object handback) {
    if (listener == null)
        throw new NullPointerException("listener");
    connectionBroadcaster.addNotificationListener(listener, filter,
            handback);
}
BaseModelMBean.java 文件源码 项目:lazycat 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
}
MBeanServerAccessController.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
}


问题


面经


文章

微信
公众号

扫码关注公众号