1 9 package org.jboss.mx.remoting.tracker; 10 11 import java.io.Serializable ; 12 import java.util.List ; 13 import javax.management.AttributeChangeNotification ; 14 import javax.management.InstanceNotFoundException ; 15 import javax.management.MBeanServer ; 16 import javax.management.MBeanServerFactory ; 17 import javax.management.MBeanServerNotification ; 18 import javax.management.Notification ; 19 import javax.management.NotificationFilter ; 20 import javax.management.ObjectName ; 21 22 28 public class MBeanTrackerFilter implements NotificationFilter , Serializable 29 { 30 static final long serialVersionUID = -4239778153506655691L; 31 protected final String classNames[]; 32 protected final String serverId; 33 protected final boolean wantNotifications; 34 35 public MBeanTrackerFilter(String serverId, String cn[], boolean wantNotifications) 36 { 37 this.serverId = serverId; 38 this.classNames = cn; 39 this.wantNotifications = wantNotifications; 40 } 41 42 public boolean isNotificationEnabled(Notification notification) 43 { 44 if(notification instanceof MBeanServerNotification ) 45 { 46 MBeanServerNotification n = (MBeanServerNotification ) notification; 47 ObjectName mbean = n.getMBeanName(); 48 List list = MBeanServerFactory.findMBeanServer(serverId); 50 if(list.isEmpty() == false) 51 { 52 MBeanServer server = (MBeanServer ) list.get(0); 53 if(notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) 54 { 55 if(classNames == null) 56 { 57 return true; 58 } 59 for(int c = 0; c < classNames.length; c++) 60 { 61 try 62 { 63 if(server.isInstanceOf(mbean, classNames[c])) 64 { 65 return true; 68 } 69 } 70 catch(Exception ex) 71 { 72 } 74 } 75 } 76 else if(notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) 77 { 78 return false == (mbean.getDomain().equals("mx.remoting") || 79 mbean.getDomain().equals("JMImplementation")); 80 } 81 } 82 83 } 84 else if(notification instanceof AttributeChangeNotification ) 85 { 86 AttributeChangeNotification ch = (AttributeChangeNotification ) notification; 88 if(ch.getAttributeName().equals("State") && 89 (ch.getAttributeType().equals(Integer.TYPE.getName()) || ch.getAttributeType().equals(Integer .class.getName()))) 90 { 91 return true; 92 } 93 } 94 if(wantNotifications) 95 { 96 Object src = notification.getSource(); 97 if(src instanceof ObjectName ) 98 { 99 ObjectName obj = (ObjectName ) src; 100 List list = MBeanServerFactory.findMBeanServer(serverId); 102 if(list.isEmpty() == false) 104 { 105 MBeanServer server = (MBeanServer ) list.get(0); 106 if(classNames == null) 107 { 108 return true; 109 } 110 for(int c = 0; c < classNames.length; c++) 111 { 112 try 113 { 114 if(server.isInstanceOf(obj, classNames[c])) 115 { 116 return true; 119 } 120 } 121 catch(InstanceNotFoundException inf) 122 { 123 return false; 124 } 125 catch(Exception ex) 126 { 127 ex.printStackTrace(); 128 } 129 } 130 } 131 } 132 } 133 return false; 134 } 135 136 } 137 138 | Popular Tags |