1 17 18 19 package org.apache.tomcat.util.modeler; 20 21 22 import java.util.HashSet ; 23 24 import javax.management.AttributeChangeNotification ; 25 import javax.management.Notification ; 26 import javax.management.NotificationFilter ; 27 28 29 38 39 public class BaseAttributeFilter implements NotificationFilter { 40 41 42 44 45 52 public BaseAttributeFilter(String name) { 53 54 super(); 55 if (name != null) 56 addAttribute(name); 57 58 } 59 60 61 63 64 68 private HashSet names = new HashSet (); 69 70 71 73 74 79 public void addAttribute(String name) { 80 81 synchronized (names) { 82 names.add(name); 83 } 84 85 } 86 87 88 92 public void clear() { 93 94 synchronized (names) { 95 names.clear(); 96 } 97 98 } 99 100 101 106 public String [] getNames() { 107 108 synchronized (names) { 109 return ((String []) names.toArray(new String [names.size()])); 110 } 111 112 } 113 114 115 125 public boolean isNotificationEnabled(Notification notification) { 126 127 if (notification == null) 128 return (false); 129 if (!(notification instanceof AttributeChangeNotification )) 130 return (false); 131 AttributeChangeNotification acn = 132 (AttributeChangeNotification ) notification; 133 if (!AttributeChangeNotification.ATTRIBUTE_CHANGE.equals(acn.getType())) 134 return (false); 135 synchronized (names) { 136 if (names.size() < 1) 137 return (true); 138 else 139 return (names.contains(acn.getAttributeName())); 140 } 141 142 } 143 144 145 151 public void removeAttribute(String name) { 152 153 synchronized (names) { 154 names.remove(name); 155 } 156 157 } 158 159 160 } 161 | Popular Tags |