1 23 24 29 package com.sun.appserv.management.util.jmx; 30 31 import java.util.List ; 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.Collections ; 35 36 import javax.management.NotificationListener ; 37 import javax.management.NotificationFilter ; 38 39 40 42 public class NotificationListenerTracking 43 { 44 private final List <NotificationListenerInfo> mInfos; 46 47 public 48 NotificationListenerTracking( boolean synchronize ) 49 { 50 final List <NotificationListenerInfo> infos = 51 new ArrayList <NotificationListenerInfo>(); 52 53 mInfos = synchronize ? Collections.synchronizedList( infos ) : infos; 54 } 55 56 public void 57 addNotificationListener( 58 NotificationListener listener, 59 NotificationFilter filter, 60 Object handback ) 61 { 62 final NotificationListenerInfo info = 63 new NotificationListenerInfo( listener, filter, handback ); 64 65 mInfos.add( info ); 66 } 67 68 69 public int 70 getListenerCount() 71 { 72 return mInfos.size(); 73 } 74 75 private final boolean 76 listenersEqual( 77 final NotificationListener listener1, 78 final NotificationListener listener2) 79 { 80 return( listener1 == listener2 ); 81 } 82 83 private final boolean 84 handbacksEqual( 85 final Object handback1, 86 final Object handback2) 87 { 88 return( handback1 == handback2 ); 89 } 90 91 99 public List <NotificationListenerInfo> 100 removeNotificationListener( final NotificationListener listener ) 101 { 102 final Iterator iter = mInfos.iterator(); 103 104 final List <NotificationListenerInfo> results = new ArrayList <NotificationListenerInfo>(); 105 106 while( iter.hasNext() ) 107 { 108 final NotificationListenerInfo info = 109 (NotificationListenerInfo)iter.next(); 110 111 if ( listenersEqual( listener, info.getListener() ) ) 112 { 113 iter.remove(); 114 results.add( info ); 115 } 116 } 117 118 return( results ); 119 } 120 121 129 public NotificationListenerInfo 130 removeNotificationListener( 131 final NotificationListener listener, 132 final NotificationFilter filter, 133 final Object handback ) 134 { 135 final Iterator iter = mInfos.iterator(); 136 NotificationListenerInfo result = null; 137 138 while( iter.hasNext() ) 139 { 140 final NotificationListenerInfo info = 141 (NotificationListenerInfo)iter.next(); 142 143 if ( listenersEqual( listener, info.getListener() ) && 144 handbacksEqual( handback, info.getHandback() ) ) 145 { 146 iter.remove(); 147 result = info; 148 break; 149 } 150 } 151 152 return( result ); 153 } 154 } 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | Popular Tags |