Reuse AbstractListenerRegistration 34/76734/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Oct 2018 09:32:51 +0000 (11:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 8 Oct 2018 09:32:51 +0000 (11:32 +0200)
Instead of brewing our own, non-idempotent implementation of
ListenerRegistration use AbstractListenerRegistration which takes
care of being idempotent and holding the listener instance.

Change-Id: I1525f5011c455a0f170d492f164cdeb3b7290b9b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceNotificationService.java

index e27a7b2ec241c25952fbbd2ecffa2aaad6bb15f8..44d088dc467b6aacf7d236f29a1a5720bf3fb982 100644 (file)
@@ -16,6 +16,7 @@ import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
@@ -48,18 +49,13 @@ public class NetconfDeviceNotificationService implements DOMNotificationService
             listeners.put(type, listener);
         }
 
-        return new ListenerRegistration<T>() {
+        return new AbstractListenerRegistration<T>(listener) {
             @Override
-            public void close() {
+            protected void removeRegistration() {
                 for (final SchemaPath type : types) {
                     listeners.remove(type, listener);
                 }
             }
-
-            @Override
-            public T getInstance() {
-                return listener;
-            }
         };
     }