jdk/src/java.management/share/classes/com/sun/jmx/remote/internal/ClientNotifForwarder.java
changeset 45060 adbeae0f677e
parent 43503 bc7f8619ab70
equal deleted inserted replaced
44981:30e75693ae99 45060:adbeae0f677e
   186 
   186 
   187         init(false);
   187         init(false);
   188     }
   188     }
   189 
   189 
   190     public synchronized Integer[]
   190     public synchronized Integer[]
   191         removeNotificationListener(ObjectName name,
   191     getListenerIds(ObjectName name,
   192                                    NotificationListener listener)
   192                    NotificationListener listener)
   193         throws ListenerNotFoundException, IOException {
   193             throws ListenerNotFoundException, IOException {
   194 
       
   195         beforeRemove();
       
   196 
       
   197         if (logger.traceOn()) {
       
   198             logger.trace("removeNotificationListener",
       
   199                          "Remove the listener "+listener+" from "+name);
       
   200         }
       
   201 
   194 
   202         List<Integer> ids = new ArrayList<Integer>();
   195         List<Integer> ids = new ArrayList<Integer>();
   203         List<ClientListenerInfo> values =
   196         List<ClientListenerInfo> values =
   204                 new ArrayList<ClientListenerInfo>(infoList.values());
   197                 new ArrayList<ClientListenerInfo>(infoList.values());
   205         for (int i=values.size()-1; i>=0; i--) {
   198         for (int i=values.size()-1; i>=0; i--) {
   206             ClientListenerInfo li = values.get(i);
   199             ClientListenerInfo li = values.get(i);
   207 
   200 
   208             if (li.sameAs(name, listener)) {
   201             if (li.sameAs(name, listener)) {
   209                 ids.add(li.getListenerID());
   202                 ids.add(li.getListenerID());
   210 
       
   211                 infoList.remove(li.getListenerID());
       
   212             }
   203             }
   213         }
   204         }
   214 
   205 
   215         if (ids.isEmpty())
   206         if (ids.isEmpty())
   216             throw new ListenerNotFoundException("Listener not found");
   207             throw new ListenerNotFoundException("Listener not found");
   217 
   208 
   218         return ids.toArray(new Integer[0]);
   209         return ids.toArray(new Integer[0]);
       
   210     }
       
   211 
       
   212     public synchronized Integer
       
   213     getListenerId(ObjectName name,
       
   214                    NotificationListener listener,
       
   215                    NotificationFilter filter,
       
   216                    Object handback)
       
   217             throws ListenerNotFoundException, IOException {
       
   218 
       
   219         Integer id = null;
       
   220 
       
   221         List<ClientListenerInfo> values =
       
   222                 new ArrayList<ClientListenerInfo>(infoList.values());
       
   223         for (int i=values.size()-1; i>=0; i--) {
       
   224             ClientListenerInfo li = values.get(i);
       
   225             if (li.sameAs(name, listener, filter, handback)) {
       
   226                 id=li.getListenerID();
       
   227                 break;
       
   228             }
       
   229         }
       
   230 
       
   231         if (id == null)
       
   232             throw new ListenerNotFoundException("Listener not found");
       
   233 
       
   234         return id;
       
   235     }
       
   236 
       
   237     public synchronized Integer[]
       
   238         removeNotificationListener(ObjectName name,
       
   239                                    NotificationListener listener)
       
   240         throws ListenerNotFoundException, IOException {
       
   241 
       
   242         beforeRemove();
       
   243 
       
   244         if (logger.traceOn()) {
       
   245             logger.trace("removeNotificationListener",
       
   246                          "Remove the listener "+listener+" from "+name);
       
   247         }
       
   248         Integer[] liIds = getListenerIds(name, listener);
       
   249         for (int i = 0; i < liIds.length; i++) {
       
   250             infoList.remove(liIds[i]);
       
   251         }
       
   252 
       
   253         return liIds;
   219     }
   254     }
   220 
   255 
   221     public synchronized Integer
   256     public synchronized Integer
   222         removeNotificationListener(ObjectName name,
   257         removeNotificationListener(ObjectName name,
   223                                    NotificationListener listener,
   258                                    NotificationListener listener,
   229             logger.trace("removeNotificationListener",
   264             logger.trace("removeNotificationListener",
   230                          "Remove the listener "+listener+" from "+name);
   265                          "Remove the listener "+listener+" from "+name);
   231         }
   266         }
   232 
   267 
   233         beforeRemove();
   268         beforeRemove();
   234 
   269         Integer liId = getListenerId(name, listener,
   235         Integer id = null;
   270                 filter, handback);
   236 
   271         infoList.remove(liId);
   237         List<ClientListenerInfo> values =
   272 
   238                 new ArrayList<ClientListenerInfo>(infoList.values());
   273         return liId;
   239         for (int i=values.size()-1; i>=0; i--) {
       
   240             ClientListenerInfo li = values.get(i);
       
   241             if (li.sameAs(name, listener, filter, handback)) {
       
   242                 id=li.getListenerID();
       
   243 
       
   244                 infoList.remove(id);
       
   245 
       
   246                 break;
       
   247             }
       
   248         }
       
   249 
       
   250         if (id == null)
       
   251             throw new ListenerNotFoundException("Listener not found");
       
   252 
       
   253         return id;
       
   254     }
   274     }
   255 
   275 
   256     public synchronized Integer[] removeNotificationListener(ObjectName name) {
   276     public synchronized Integer[] removeNotificationListener(ObjectName name) {
   257         if (logger.traceOn()) {
   277         if (logger.traceOn()) {
   258             logger.trace("removeNotificationListener",
   278             logger.trace("removeNotificationListener",