FileDocCategorySizeDatePackage
BaseNotificationBroadcaster.javaAPI DocApache Tomcat 6.0.149177Fri Jul 20 04:20:36 BST 2007org.apache.tomcat.util.modeler

BaseNotificationBroadcaster

public class BaseNotificationBroadcaster extends Object implements NotificationBroadcaster

Implementation of NotificationBroadcaster for attribute change notifications. This class is used by BaseModelMBean to handle notifications of attribute change events to interested listeners.

author
Craig R. McClanahan
author
Costin Manolache

Fields Summary
protected ArrayList
entries
The set of registered BaseNotificationBroadcasterEntry entries.
NotificationListener[]
hooks
int[]
hookCount
Constructors Summary
Methods Summary
public voidaddNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
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 null for no filtering
param
handback Handback object to be sent along with event notifications
exception
IllegalArgumentException if the listener parameter is null



    // --------------------------------------------------------- Public Methods


                                                              
       
                                         
                                         
          

        synchronized (entries) {

            // Optimization to coalesce attribute name filters
            if (filter instanceof BaseAttributeFilter) {
                BaseAttributeFilter newFilter = (BaseAttributeFilter) filter;
                Iterator items = entries.iterator();
                while (items.hasNext()) {
                    BaseNotificationBroadcasterEntry item =
                        (BaseNotificationBroadcasterEntry) items.next();
                    if ((item.listener == listener) &&
                        (item.filter != null) &&
                        (item.filter instanceof BaseAttributeFilter) &&
                        (item.handback == handback)) {
                        BaseAttributeFilter oldFilter =
                            (BaseAttributeFilter) item.filter;
                        String newNames[] = newFilter.getNames();
                        String oldNames[] = oldFilter.getNames();
                        if (newNames.length == 0) {
                            oldFilter.clear();
                        } else {
                            if (oldNames.length != 0) {
                                for (int i = 0; i < newNames.length; i++)
                                    oldFilter.addAttribute(newNames[i]);
                            }
                        }
                        return;
                    }
                }
            }

            // General purpose addition of a new entry
            entries.add(new BaseNotificationBroadcasterEntry
                        (listener, filter, handback));
        }

    
public javax.management.MBeanNotificationInfo[]getNotificationInfo()
Return an MBeanNotificationInfo object describing the notifications sent by this MBean.


        return (new MBeanNotificationInfo[0]);

    
private synchronized voidregisterNotifications(FixedNotificationFilter filter)


           
        String names[]=filter.getNames();
        Registry reg=Registry.getRegistry();
        for( int i=0; i<names.length; i++ ) {
            int code=reg.getId(null, names[i]);
            if( hooks.length < code ) {
                // XXX reallocate
                throw new RuntimeException( "Too many hooks " + code );
            }
            NotificationListener listeners[]=hooks[code];
            if( listeners== null ) {

            }


        }
    
public voidremoveNotificationListener(javax.management.NotificationListener listener)
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


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

    
public voidremoveNotificationListener(javax.management.NotificationListener listener, java.lang.Object handback)
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)
param
handback Handback object to be sent along with event notifications
exception
ListenerNotFoundException if this listener is not registered in the MBean


        removeNotificationListener(listener);

    
public voidremoveNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
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)
param
filter Filter object used to filter event notifications actually delivered, or null for no filtering
param
handback Handback object to be sent along with event notifications
exception
ListenerNotFoundException if this listener is not registered in the MBean


        removeNotificationListener(listener);

    
public voidsendNotification(javax.management.Notification notification)
Send the specified notification to all interested listeners.

param
notification The notification to be sent


        synchronized (entries) {
            Iterator items = entries.iterator();
            while (items.hasNext()) {
                BaseNotificationBroadcasterEntry item =
                    (BaseNotificationBroadcasterEntry) items.next();
                if ((item.filter != null) &&
                    (!item.filter.isNotificationEnabled(notification)))
                    continue;
                item.listener.handleNotification(notification, item.handback);
            }
        }