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