1 17 18 19 package org.apache.tomcat.util.modeler; 20 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 25 import javax.management.ListenerNotFoundException ; 26 import javax.management.MBeanNotificationInfo ; 27 import javax.management.Notification ; 28 import javax.management.NotificationBroadcaster ; 29 import javax.management.NotificationFilter ; 30 import javax.management.NotificationListener ; 31 32 33 42 43 public class BaseNotificationBroadcaster implements NotificationBroadcaster { 44 45 46 48 49 51 52 56 protected ArrayList entries = new ArrayList (); 57 58 59 61 62 73 public void addNotificationListener(NotificationListener listener, 74 NotificationFilter filter, 75 Object handback) 76 throws IllegalArgumentException { 77 78 synchronized (entries) { 79 80 if (filter instanceof BaseAttributeFilter) { 82 BaseAttributeFilter newFilter = (BaseAttributeFilter) filter; 83 Iterator items = entries.iterator(); 84 while (items.hasNext()) { 85 BaseNotificationBroadcasterEntry item = 86 (BaseNotificationBroadcasterEntry) items.next(); 87 if ((item.listener == listener) && 88 (item.filter != null) && 89 (item.filter instanceof BaseAttributeFilter) && 90 (item.handback == handback)) { 91 BaseAttributeFilter oldFilter = 92 (BaseAttributeFilter) item.filter; 93 String newNames[] = newFilter.getNames(); 94 String oldNames[] = oldFilter.getNames(); 95 if (newNames.length == 0) { 96 oldFilter.clear(); 97 } else { 98 if (oldNames.length != 0) { 99 for (int i = 0; i < newNames.length; i++) 100 oldFilter.addAttribute(newNames[i]); 101 } 102 } 103 return; 104 } 105 } 106 } 107 108 entries.add(new BaseNotificationBroadcasterEntry 110 (listener, filter, handback)); 111 } 112 113 } 114 115 116 120 public MBeanNotificationInfo [] getNotificationInfo() { 121 122 return (new MBeanNotificationInfo [0]); 123 124 } 125 126 127 136 public void removeNotificationListener(NotificationListener listener) 137 throws ListenerNotFoundException { 138 139 synchronized (entries) { 140 Iterator items = entries.iterator(); 141 while (items.hasNext()) { 142 BaseNotificationBroadcasterEntry item = 143 (BaseNotificationBroadcasterEntry) items.next(); 144 if (item.listener == listener) 145 items.remove(); 146 } 147 } 148 149 } 150 151 152 163 public void removeNotificationListener(NotificationListener listener, 164 Object handback) 165 throws ListenerNotFoundException { 166 167 removeNotificationListener(listener); 168 169 } 170 171 172 185 public void removeNotificationListener(NotificationListener listener, 186 NotificationFilter filter, 187 Object handback) 188 throws ListenerNotFoundException { 189 190 removeNotificationListener(listener); 191 192 } 193 194 195 200 public void sendNotification(Notification notification) { 201 202 synchronized (entries) { 203 Iterator items = entries.iterator(); 204 while (items.hasNext()) { 205 BaseNotificationBroadcasterEntry item = 206 (BaseNotificationBroadcasterEntry) items.next(); 207 if ((item.filter != null) && 208 (!item.filter.isNotificationEnabled(notification))) 209 continue; 210 item.listener.handleNotification(notification, item.handback); 211 } 212 } 213 214 } 215 216 217 219 NotificationListener hooks[][]=new NotificationListener [20][]; 222 int hookCount[]=new int[20]; 223 224 private synchronized void registerNotifications( FixedNotificationFilter filter ) { 225 String names[]=filter.getNames(); 226 Registry reg=Registry.getRegistry(); 227 for( int i=0; i<names.length; i++ ) { 228 int code=reg.getId(null, names[i]); 229 if( hooks.length < code ) { 230 throw new RuntimeException ( "Too many hooks " + code ); 232 } 233 NotificationListener listeners[]=hooks[code]; 234 if( listeners== null ) { 235 236 } 237 238 239 } 240 } 241 242 } 243 244 245 248 249 class BaseNotificationBroadcasterEntry { 250 251 public BaseNotificationBroadcasterEntry(NotificationListener listener, 252 NotificationFilter filter, 253 Object handback) { 254 this.listener = listener; 255 this.filter = filter; 256 this.handback = handback; 257 } 258 259 public NotificationFilter filter = null; 260 261 public Object handback = null; 262 263 public NotificationListener listener = null; 264 265 } 266 | Popular Tags |