1 23 package com.sun.appserv.management.util.jmx; 24 25 import java.io.IOException ; 26 27 import javax.management.ObjectName ; 28 import javax.management.Notification ; 29 import javax.management.NotificationListener ; 30 import javax.management.NotificationFilter ; 31 import javax.management.MBeanServerNotification ; 32 import javax.management.MBeanServerConnection ; 33 import javax.management.InstanceNotFoundException ; 34 import com.sun.appserv.management.base.AMXRootLogger; 35 36 48 public abstract class MBeanRegistrationListener extends NotificationListenerBase 49 { 50 private final ObjectName mRegUnregFilter; 51 private final String mDefaultDomain; 52 53 62 public 63 MBeanRegistrationListener( 64 final MBeanServerConnection conn, 65 final ObjectName constrain ) 66 throws InstanceNotFoundException , IOException 67 { 68 super( conn, 69 JMXUtil.getMBeanServerDelegateObjectName() ); 70 mRegUnregFilter = constrain; 71 72 mDefaultDomain = conn.getDefaultDomain(); 73 } 74 75 79 public 80 MBeanRegistrationListener( final MBeanServerConnection conn) 81 throws InstanceNotFoundException , IOException 82 { 83 this( conn, (ObjectName )null ); 84 } 85 86 protected abstract void mbeanRegistered( final ObjectName objectName ); 87 protected abstract void mbeanUnregistered( final ObjectName objectName ); 88 89 public void 90 handleNotification( final Notification notifIn, final Object handback) 91 { 92 if ( ! (notifIn instanceof MBeanServerNotification ) ) 93 { 94 throw new IllegalArgumentException ( notifIn.toString() ); 95 } 96 97 final MBeanServerNotification notif = (MBeanServerNotification )notifIn; 98 final ObjectName objectName = notif.getMBeanName(); 99 final String type = notif.getType(); 100 101 final boolean matchesFilter = (mRegUnregFilter == null) || 102 JMXUtil.matchesPattern( mDefaultDomain, mRegUnregFilter, objectName ); 103 104 if ( matchesFilter ) 105 { 106 if ( type.equals( MBeanServerNotification.REGISTRATION_NOTIFICATION ) ) 107 { 108 mbeanRegistered( objectName ); 109 } 110 else if ( type.equals( MBeanServerNotification.UNREGISTRATION_NOTIFICATION ) ) 111 { 112 mbeanUnregistered( objectName ); 113 } 114 } 115 } 116 } 117 118 119 120 121 | Popular Tags |