FileDocCategorySizeDatePackage
MBeanRegistrationEventListener.javaAPI DocGlassfish v2 API5737Fri May 04 22:33:16 BST 2007com.sun.enterprise.admin.alert

MBeanRegistrationEventListener

public class MBeanRegistrationEventListener extends Object implements NotificationListener
Class MBeanRegistrationEventListener listens to MBeanRegistered event. The main purpose of this class is to introspect the 'name' element in objectName of the MBean (or Monitor) registered and check to see if it matches with any of the names listed for alert-subscription. If it matches then the listener will be subscribed with the MBean.
AUTHOR:
Hemanth Puttaswamy

Fields Summary
private List
alertSubscriptions
private MBeanServer
mbeanServer
private static final String
NAME_PROPERTY_KEY
Constructors Summary
public MBeanRegistrationEventListener(List alertSubscriptions)
Constructor which accepts a list of AlertSubscriptions based on domain.xml entries.

 
                    
         
        this.alertSubscriptions = alertSubscriptions;
        mbeanServer = 
            AdminService.getAdminService().getAdminContext().getMBeanServer();
    
Methods Summary
public voidhandleNotification(javax.management.Notification notification, java.lang.Object handBack)
If the event type is REGISTRATION_NOTIFICATION and if the 'name' element in registered MBean's ObjectName matches one of names in the alert subscriptions then we will add the Notification Listener and the Filter to the MBean.

        if( !notification.getType().equals( 
            MBeanServerNotification.REGISTRATION_NOTIFICATION  ) )
        {
            // We are only interested in Registration event
            return;
        }
        try {
            MBeanServerNotification mbeanServerNotification =
                (MBeanServerNotification) notification;
            String registeredMbeanName =
                mbeanServerNotification.getMBeanName().getKeyProperty( 
                    NAME_PROPERTY_KEY );
            // Registered ObjectName doesn't have the 'name' key value. So,
            // no action needs to be taken.
            if( registeredMbeanName == null ) return;
            Iterator iterator = alertSubscriptions.iterator( );
            while ( iterator.hasNext( ) ) {
                AlertSubscriptionInfo subscription = 
                    (AlertSubscriptionInfo)iterator.next();
                if( matches( subscription.getMonitorNames(), 
                    registeredMbeanName ))
                {    
                    mbeanServer.addNotificationListener( 
                        mbeanServerNotification.getMBeanName(), 
                            subscription.getNotificationListener(),
                            subscription.getNotificationFilter(), null );
                }
            }
        } catch( Exception e ) {
             new ErrorManager().error( "Error In " +
                  " MBeanServerRegistrationEventListener  ", e,
                  ErrorManager.GENERIC_FAILURE );
        }
    
private booleanmatches(java.util.List monitorNames, java.lang.String registeredMBeanName)
A simple utility method to check to see if the registeredMBeanName matches with one of the monitorNames for alert subscription.

        Iterator iterator = monitorNames.iterator( );
        while( iterator.hasNext( ) ) {
            if( registeredMBeanName.equals( (String) iterator.next() ) ) {
                return true;
            }
        }
        return false;