1 23 package com.sun.enterprise.admin.alert; 24 25 import java.util.logging.ErrorManager ; 26 27 import javax.management.NotificationListener ; 28 import javax.management.MBeanServerNotification ; 29 import javax.management.Notification ; 30 import javax.management.MBeanServer ; 31 32 import com.sun.enterprise.admin.server.core.AdminService; 33 34 35 import java.util.List ; 36 import java.util.Iterator ; 37 38 47 public class MBeanRegistrationEventListener implements NotificationListener { 48 private List alertSubscriptions; 50 51 private MBeanServer mbeanServer; 52 53 private static final String NAME_PROPERTY_KEY = "name"; 54 55 59 public MBeanRegistrationEventListener( List alertSubscriptions ) { 60 this.alertSubscriptions = alertSubscriptions; 61 mbeanServer = 62 AdminService.getAdminService().getAdminContext().getMBeanServer(); 63 } 64 65 66 72 public void handleNotification( Notification notification, 73 Object handBack ) 74 { 75 if( !notification.getType().equals( 76 MBeanServerNotification.REGISTRATION_NOTIFICATION ) ) 77 { 78 return; 80 } 81 try { 82 MBeanServerNotification mbeanServerNotification = 83 (MBeanServerNotification ) notification; 84 String registeredMbeanName = 85 mbeanServerNotification.getMBeanName().getKeyProperty( 86 NAME_PROPERTY_KEY ); 87 if( registeredMbeanName == null ) return; 90 Iterator iterator = alertSubscriptions.iterator( ); 91 while ( iterator.hasNext( ) ) { 92 AlertSubscriptionInfo subscription = 93 (AlertSubscriptionInfo)iterator.next(); 94 if( matches( subscription.getMonitorNames(), 95 registeredMbeanName )) 96 { 97 mbeanServer.addNotificationListener( 98 mbeanServerNotification.getMBeanName(), 99 subscription.getNotificationListener(), 100 subscription.getNotificationFilter(), null ); 101 } 102 } 103 } catch( Exception e ) { 104 new ErrorManager ().error( "Error In " + 105 " MBeanServerRegistrationEventListener ", e, 106 ErrorManager.GENERIC_FAILURE ); 107 } 108 } 109 110 114 private boolean matches( List monitorNames, String registeredMBeanName ) { 115 Iterator iterator = monitorNames.iterator( ); 116 while( iterator.hasNext( ) ) { 117 if( registeredMBeanName.equals( (String ) iterator.next() ) ) { 118 return true; 119 } 120 } 121 return false; 122 } 123 } 124 125 126 127 | Popular Tags |