public void addServerNotificationListener ( RESTRequest request , ServerNotificationRegistration serverNotificationRegistration , JSONConverter converter ) { NotificationTargetInformation nti = toNotificationTargetInformation ( request , serverNotificationRegistration . objectName . getCanonicalName ( ) ) ; //Fetch the filter/handback objects NotificationFilter filter = ( NotificationFilter ) getObject ( serverNotificationRegistration . filterID , serverNotificationRegistration . filter , converter ) ; Object handback = getObject ( serverNotificationRegistration . handbackID , serverNotificationRegistration . handback , converter ) ; // Check whether the producer of the notification is local or remote. if ( nti . getRoutingInformation ( ) == null ) { //Add to the MBeanServer MBeanServerHelper . addServerNotification ( serverNotificationRegistration . objectName , serverNotificationRegistration . listener , filter , handback , converter ) ; } else { // Add the notification listener to the Target-Client Manager through EventAdmin MBeanRoutedNotificationHelper helper = MBeanRoutedNotificationHelper . getMBeanRoutedNotificationHelper ( ) ; helper . addRoutedServerNotificationListener ( nti , serverNotificationRegistration . listener , filter , handback , converter ) ; } //Make the local ServerNotification ServerNotification serverNotification = new ServerNotification ( ) ; serverNotification . listener = serverNotificationRegistration . listener ; serverNotification . filter = serverNotificationRegistration . filterID ; serverNotification . handback = serverNotificationRegistration . handbackID ; //See if there's a list already List < ServerNotification > list = serverNotifications . get ( nti ) ; if ( list == null ) { list = Collections . synchronizedList ( new ArrayList < ServerNotification > ( ) ) ; List < ServerNotification > mapList = serverNotifications . putIfAbsent ( nti , list ) ; if ( mapList != null ) { list = mapList ; } } //Add the new notification into the list list . add ( serverNotification ) ; }
Add the server notification to our internal list so we can cleanup afterwards