Remove NotificationRegistration 81/105681/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Apr 2023 20:04:46 +0000 (22:04 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Apr 2023 22:02:19 +0000 (00:02 +0200)
Migrate the final two users of NotificationRegistration to plain
Registration and remove NotificationRegistration. On the implementation
side we also unify notification handling, so that the underlying
contract is implemented by a base class and individual specializations
just pass down required inputs.

Change-Id: I677ced2b1553de6fdc7ffe59646e2c220fbd27b6
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java
netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/BaseNotificationPublisherRegistration.java
netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NotificationRegistration.java [deleted file]
netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/YangLibraryPublisherRegistration.java

index 99d00f5b269a9f2135000a7cd52c616d1df5ac71..08911f47ba55d63ba63b26981c3c2023a439f87d 100644 (file)
@@ -257,75 +257,72 @@ public final class NetconfNotificationManager implements NetconfNotificationColl
         }
     }
 
-    private static class BaseNotificationPublisherReg implements BaseNotificationPublisherRegistration {
-        static final Absolute CAPABILITY_CHANGE_SCHEMA_PATH = Absolute.of(NetconfCapabilityChange.QNAME);
-        static final Absolute SESSION_START_PATH = Absolute.of(NetconfSessionStart.QNAME);
-        static final Absolute SESSION_END_PATH = Absolute.of(NetconfSessionEnd.QNAME);
-
-        private final NotificationPublisherRegistration baseRegistration;
+    private abstract static class AbstractTransformedRegistration implements Registration {
+        private final NotificationPublisherRegistration delegate;
         private final NotificationsTransformUtil transformUtil;
 
-        BaseNotificationPublisherReg(final NotificationsTransformUtil transformUtil,
-                final NotificationPublisherRegistration baseRegistration) {
+        AbstractTransformedRegistration(final NotificationsTransformUtil transformUtil,
+                final NotificationPublisherRegistration delegate) {
             this.transformUtil = requireNonNull(transformUtil);
-            this.baseRegistration = baseRegistration;
+            this.delegate = requireNonNull(delegate);
         }
 
         @Override
-        public void close() {
-            baseRegistration.close();
+        public final void close() {
+            delegate.close();
         }
 
-        private NotificationMessage serializeNotification(final Notification<?> notification, final Absolute path) {
-            return transformUtil.transform(notification, path);
+        final void publishNotification(final Notification<?> notification, final Absolute path) {
+            delegate.onNotification(BASE_STREAM_NAME, transformUtil.transform(notification, path));
+        }
+    }
+
+    private static class BaseNotificationPublisherReg extends AbstractTransformedRegistration
+            implements BaseNotificationPublisherRegistration {
+        private static final Absolute CAPABILITY_CHANGE_SCHEMA_PATH = Absolute.of(NetconfCapabilityChange.QNAME);
+        private static final Absolute SESSION_START_PATH = Absolute.of(NetconfSessionStart.QNAME);
+        private static final Absolute SESSION_END_PATH = Absolute.of(NetconfSessionEnd.QNAME);
+
+        BaseNotificationPublisherReg(final NotificationsTransformUtil transformUtil,
+                final NotificationPublisherRegistration delegate) {
+            super(transformUtil, delegate);
         }
 
         @Override
         public void onCapabilityChanged(final NetconfCapabilityChange capabilityChange) {
-            baseRegistration.onNotification(BASE_STREAM_NAME,
-                    serializeNotification(capabilityChange, CAPABILITY_CHANGE_SCHEMA_PATH));
+            publishNotification(capabilityChange, CAPABILITY_CHANGE_SCHEMA_PATH);
         }
 
         @Override
         public void onSessionStarted(final NetconfSessionStart start) {
-            baseRegistration.onNotification(BASE_STREAM_NAME, serializeNotification(start, SESSION_START_PATH));
+            publishNotification(start, SESSION_START_PATH);
         }
 
         @Override
         public void onSessionEnded(final NetconfSessionEnd end) {
-            baseRegistration.onNotification(BASE_STREAM_NAME, serializeNotification(end, SESSION_END_PATH));
+            publishNotification(end, SESSION_END_PATH);
         }
     }
 
-    private static class YangLibraryPublisherReg implements YangLibraryPublisherRegistration {
-        static final Absolute YANG_LIBRARY_CHANGE_PATH = Absolute.of(YangLibraryChange.QNAME);
-        static final Absolute YANG_LIBRARY_UPDATE_PATH = Absolute.of(YangLibraryUpdate.QNAME);
-
-        private final NotificationPublisherRegistration baseRegistration;
-        private final NotificationsTransformUtil transformUtil;
+    private static class YangLibraryPublisherReg extends AbstractTransformedRegistration
+            implements YangLibraryPublisherRegistration {
+        private static final Absolute YANG_LIBRARY_CHANGE_PATH = Absolute.of(YangLibraryChange.QNAME);
+        private static final Absolute YANG_LIBRARY_UPDATE_PATH = Absolute.of(YangLibraryUpdate.QNAME);
 
         YangLibraryPublisherReg(final NotificationsTransformUtil transformUtil,
-                final NotificationPublisherRegistration baseRegistration) {
-            this.transformUtil = requireNonNull(transformUtil);
-            this.baseRegistration = baseRegistration;
+                final NotificationPublisherRegistration delegate) {
+            super(transformUtil, delegate);
         }
 
         @Override
         @Deprecated
         public void onYangLibraryChange(final YangLibraryChange yangLibraryChange) {
-            baseRegistration.onNotification(BASE_STREAM_NAME,
-                transformUtil.transform(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH));
+            publishNotification(yangLibraryChange, YANG_LIBRARY_CHANGE_PATH);
         }
 
         @Override
         public void onYangLibraryUpdate(final YangLibraryUpdate yangLibraryUpdate) {
-            baseRegistration.onNotification(BASE_STREAM_NAME,
-                    transformUtil.transform(yangLibraryUpdate, YANG_LIBRARY_UPDATE_PATH));
-        }
-
-        @Override
-        public void close() {
-            baseRegistration.close();
+            publishNotification(yangLibraryUpdate, YANG_LIBRARY_UPDATE_PATH);
         }
     }
 
index f8d8152dae9766e990a0cbb63d8e1606c0ef6673..dfe94ef4e299f7df09c23d4b632daf0638c38fc4 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.netconf.notifications;
 
+import org.opendaylight.yangtools.concepts.Registration;
+
 /**
- * Registration for base notification publisher. This registration allows for publishing of base netconf notifications
- * using generated classes
+ * Registration for base notification publisher. This registration allows for publishing of base NETCONF notifications
+ * using generated classes.
  */
-public interface BaseNotificationPublisherRegistration
-        extends NotificationRegistration, BaseNetconfNotificationListener {
+public interface BaseNotificationPublisherRegistration extends Registration, BaseNetconfNotificationListener {
 
 }
diff --git a/netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NotificationRegistration.java b/netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NotificationRegistration.java
deleted file mode 100644 (file)
index b3f26dc..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.notifications;
-
-/**
- * Generic registration, used as a base for other registration types.
- */
-public interface NotificationRegistration extends AutoCloseable {
-
-    // Overriden close does not throw any kind of checked exception
-
-    /**
-     * Close the registration.
-     */
-    @Override
-    void close();
-}
index 9c69490233ebe0cb1b18e703a4a905b989450896..63c04cb25b1f0367ec23da1d948fce66a1106e28 100644 (file)
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.netconf.notifications;
 
+import org.opendaylight.yangtools.concepts.Registration;
+
 /**
  * Registration for yang-library publisher. This registration allows for publishing of YANG library notification using
- * generated classes
+ * generated classes.
  */
-public interface YangLibraryPublisherRegistration extends NotificationRegistration, YangLibraryNotificationListener {
+public interface YangLibraryPublisherRegistration extends Registration, YangLibraryNotificationListener {
 
 }