1 22 package org.jboss.mx.util; 23 24 import java.io.Serializable ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Vector ; 28 29 import javax.management.Notification ; 30 import javax.management.NotificationFilter ; 31 32 import org.jboss.util.collection.CollectionsFactory; 33 34 54 public class JBossNotificationFilterSupport 55 implements NotificationFilter , Serializable 56 { 57 59 private static final long serialVersionUID = 6442164418782871672L; 60 61 63 66 private List enabledTypes; 67 68 70 72 77 public JBossNotificationFilterSupport() 78 { 79 enabledTypes = CollectionsFactory.createCopyOnWriteList(); 80 } 81 82 84 87 public void disableAllTypes() 88 { 89 synchronized(this) 90 { 91 enabledTypes.clear(); 92 } 93 } 94 95 100 public void disableType(String type) 101 { 102 synchronized(this) 103 { 104 enabledTypes.remove(type); 106 } 107 } 108 109 115 public void enableType(String type) throws IllegalArgumentException 116 { 117 if (type == null) 118 { 119 throw new IllegalArgumentException ("null notification type"); 120 } 121 synchronized(this) 122 { 123 if (enabledTypes.contains(type) == false) 124 { 125 enabledTypes.add(type); 126 } 127 } 128 } 129 130 138 public Vector getEnabledTypes() 139 { 140 return new Vector (enabledTypes); 141 } 142 143 146 public String toString() 147 { 148 StringBuffer sb = new StringBuffer (100); 149 150 sb.append(getClass().getName()).append(':'); 151 sb.append(" enabledTypes=").append(getEnabledTypes()); 152 153 return sb.toString(); 154 } 155 156 158 165 public boolean isNotificationEnabled(Notification notification) 166 { 167 if (notification == null) 168 { 169 throw new IllegalArgumentException ("null notification"); 170 } 171 String notificationType = notification.getType(); 173 for (Iterator i = enabledTypes.iterator(); i.hasNext(); ) 174 { 175 String type = (String )i.next(); 176 if (notificationType.startsWith(type)) 177 { 178 return true; 179 } 180 } 181 return false; 182 } 183 184 186 } 187 | Popular Tags |