Cleanup warnings in restconf-broker NotificationService 02/5502/4
authorRobert Varga <rovarga@cisco.com>
Fri, 28 Feb 2014 13:27:51 +0000 (14:27 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 9 Mar 2014 18:52:02 +0000 (19:52 +0100)
The registration map is not needed and the executor is not used, so
remove them. Also reuse AbstractListenerRegistration in place of a
custom-coded class.

Change-Id: Ia4060370faa03fb85d9a90471938501a583072d3
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-restconf-broker/src/main/java/org/opendaylight/controller/sal/restconf/broker/impl/NotificationServiceImpl.java

index 617ec4f..c08f329 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.sal.restconf.broker.impl;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
 
 import org.opendaylight.controller.sal.binding.api.NotificationListener;
 import org.opendaylight.controller.sal.binding.api.NotificationService;
@@ -18,78 +17,46 @@ import org.opendaylight.controller.sal.restconf.broker.listeners.RemoteNotificat
 import org.opendaylight.controller.sal.restconf.broker.tools.RemoteStreamTools;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.QName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.remote.rev140114.SalRemoteService;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
 import org.opendaylight.yangtools.restconf.client.api.event.EventStreamInfo;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
-
 public class NotificationServiceImpl implements NotificationService {
     private final SalRemoteService salRemoteService;
     private final RestconfClientContext restconfClientContext;
 
-    private final Multimap<Class<? extends Notification>,NotificationListener<? extends Object>> listeners;
-    private ExecutorService _executor;
-
     public NotificationServiceImpl(RestconfClientContext restconfClienetContext){
         this.restconfClientContext = restconfClienetContext;
         this.salRemoteService = this.restconfClientContext.getRpcServiceContext(SalRemoteService.class).getRpcService();
-
-        HashMultimap<Class<? extends Notification>,NotificationListener<? extends Object>> _create = HashMultimap.<Class<? extends Notification>, NotificationListener<? extends Object>>create();
-        SetMultimap<Class<? extends Notification>,NotificationListener<? extends Object>> _synchronizedSetMultimap = Multimaps.<Class<? extends Notification>, NotificationListener<? extends Object>>synchronizedSetMultimap(_create);
-        this.listeners = _synchronizedSetMultimap;
-
-    }
-    public ExecutorService getExecutor() {
-        return this._executor;
-    }
-
-    public void setExecutor(final ExecutorService executor) {
-        this._executor = executor;
     }
 
     @Override
-    public <T extends Notification> Registration<NotificationListener<T>> registerNotificationListener(Class<T> notificationType, NotificationListener<T> listener) {
+    public <T extends Notification> ListenerRegistration<NotificationListener<T>> registerNotificationListener(Class<T> notificationType, NotificationListener<T> listener) {
         //TODO implementation using sal-remote
         List<QName> notifications = new ArrayList<QName>();
         notifications.add(new QName(notificationType.toString()));
         String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, notifications);
         final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
         RemoteNotificationListener remoteNotificationListener = new RemoteNotificationListener(listener);
-        ListenerRegistration<?> listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(remoteNotificationListener);
-        return new SalNotificationRegistration<T>(listenerRegistration);
+
+        final ListenerRegistration<?> listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName)))
+                .registerNotificationListener(remoteNotificationListener);
+
+        return new AbstractListenerRegistration<NotificationListener<T>>(listener) {
+            @Override
+            protected void removeRegistration() {
+                listenerRegistration.close();
+            }
+        };
     }
 
     @Override
-    public Registration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
+    public ListenerRegistration<org.opendaylight.yangtools.yang.binding.NotificationListener> registerNotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener listener) {
         //TODO implementation using sal-remote
         String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, null);
         final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
         return restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName))).registerNotificationListener(listener);
     }
-
-    private class SalNotificationRegistration<T extends Notification> implements Registration<NotificationListener<T>>{
-        private final Registration<?> registration;
-
-        public SalNotificationRegistration(ListenerRegistration<?> listenerRegistration){
-            this.registration = listenerRegistration;
-        }
-
-        @Override
-        public NotificationListener<T> getInstance() {
-            return this.getInstance();
-        }
-
-        @Override
-        public void close() throws Exception {
-            this.registration.close();
-        }
-    }
-
-
 }