Remove NotificationServiceHandler 68/96168/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 15:09:47 +0000 (17:09 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 13 May 2021 15:10:19 +0000 (17:10 +0200)
This is a useless indirection over DOMNotificationService, remove it,
making interactions tad easier to follow.

JIRA: NETCONF-773
Change-Id: I91f4da713f3ff66d0efa7cd3feeda6fc01a83fad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/NotificationServiceHandler.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java

index 4c05d56a5ffbdd37d79c91b4c691204db95402ee..cfaefa595977bb48409db4738ed8f05750d7c70d 100644 (file)
@@ -11,11 +11,11 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesNotifWrapper;
@@ -45,13 +45,13 @@ public class Rfc8040RestConfWiring {
             final TransactionChainHandler transactionChainHandler,
             final DOMDataBrokerHandler domDataBrokerHandler, @Reference final DOMRpcService rpcService,
             @Reference final DOMActionService actionService,
-            final NotificationServiceHandler notificationServiceHandler,
+            @Reference final DOMNotificationService notificationService,
             final SSEInitializer sseInit,
             final Configuration configuration,
             @Reference final DOMSchemaService domSchemaService) {
         servicesWrapper = ServicesWrapper.newInstance(schemaCtxHandler, domMountPointServiceHandler,
-            transactionChainHandler, domDataBrokerHandler, rpcService, actionService,
-            notificationServiceHandler, domSchemaService, configuration);
+            transactionChainHandler, domDataBrokerHandler, rpcService, actionService, notificationService,
+            domSchemaService, configuration);
         servicesNotifWrapper = ServicesNotifWrapper.newInstance(sseInit);
     }
 
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/NotificationServiceHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/NotificationServiceHandler.java
deleted file mode 100644 (file)
index ea5cd7b..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2016 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.restconf.nb.rfc8040.handlers;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.apache.aries.blueprint.annotation.service.Reference;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-
-// FIXME: remove this class
-@Singleton
-public class NotificationServiceHandler {
-    private final DOMNotificationService notificationService;
-
-    /**
-     * Set DOMNotificationService.
-     *
-     * @param notificationService
-     *             DOMNotificationService
-     */
-    @Inject
-    public NotificationServiceHandler(final @Reference DOMNotificationService notificationService) {
-        this.notificationService = notificationService;
-    }
-
-    public DOMNotificationService get() {
-        return this.notificationService;
-    }
-}
index 236a0172f9ec9f02466e12474f0422e067a144a7..616c6286bfec1fd03c2357fd472d07b723b20bec 100644 (file)
@@ -31,7 +31,6 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
@@ -67,7 +66,7 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      *
      * @param domDataBrokerHandler
      *             handler of {@link DOMDataBroker}
-     * @param notificationServiceHandler
+     * @param notificationService
      *             handler of {@link DOMNotificationService}
      * @param schemaHandler
      *             handler of {@link SchemaContext}
@@ -77,9 +76,9 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
      *             configuration for restconf {@link Configuration}}
      */
     public RestconfStreamsSubscriptionServiceImpl(final DOMDataBrokerHandler domDataBrokerHandler,
-            final NotificationServiceHandler notificationServiceHandler, final SchemaContextHandler schemaHandler,
+            final DOMNotificationService notificationService, final SchemaContextHandler schemaHandler,
             final TransactionChainHandler transactionChainHandler, final Configuration configuration) {
-        this.handlersHolder = new HandlersHolder(domDataBrokerHandler, notificationServiceHandler,
+        this.handlersHolder = new HandlersHolder(domDataBrokerHandler, notificationService,
                 transactionChainHandler, schemaHandler);
         streamUtils = configuration.isUseSSE() ? SubscribeToStreamUtil.serverSentEvents()
                 : SubscribeToStreamUtil.webSockets();
@@ -142,18 +141,18 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
     /**
      * Holder of all handlers for notifications.
      */
+    // FIXME: why do we even need this class?!
     public static final class HandlersHolder {
-
         private final DOMDataBrokerHandler domDataBrokerHandler;
-        private final NotificationServiceHandler notificationServiceHandler;
+        private final DOMNotificationService notificationService;
         private final TransactionChainHandler transactionChainHandler;
         private final SchemaContextHandler schemaHandler;
 
         private HandlersHolder(final DOMDataBrokerHandler domDataBrokerHandler,
-                final NotificationServiceHandler notificationServiceHandler,
+                final DOMNotificationService notificationService,
                 final TransactionChainHandler transactionChainHandler, final SchemaContextHandler schemaHandler) {
             this.domDataBrokerHandler = domDataBrokerHandler;
-            this.notificationServiceHandler = notificationServiceHandler;
+            this.notificationService = notificationService;
             this.transactionChainHandler = transactionChainHandler;
             this.schemaHandler = schemaHandler;
         }
@@ -168,12 +167,12 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
         }
 
         /**
-         * Get {@link NotificationServiceHandler}.
+         * Get {@link DOMNotificationService}.
          *
-         * @return the notificationServiceHandler
+         * @return the notificationService
          */
-        public NotificationServiceHandler getNotificationServiceHandler() {
-            return this.notificationServiceHandler;
+        public DOMNotificationService getNotificationServiceHandler() {
+            return this.notificationService;
         }
 
         /**
index d1496e1ab201900d45e9ea70fcb38d080000f558..ff02c54e42f6d9cf444715a64e70fc4c3f53b36a 100644 (file)
@@ -23,13 +23,13 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.util.DataChangeScope;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.HandlersHolder;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl.NotificationQueryParams;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.ResolveEnumUtil;
@@ -281,15 +281,16 @@ abstract class SubscribeToStreamUtil {
         listener.setRegistration(registration);
     }
 
+    // FIXME: this method should be in NotificationListenerAdapter
     private static void registerToListenNotification(final NotificationListenerAdapter listener,
-            final NotificationServiceHandler notificationServiceHandler) {
+            final DOMNotificationService notificationService) {
         if (listener.isListening()) {
             return;
         }
 
         final Absolute path = listener.getSchemaPath();
         final ListenerRegistration<DOMNotificationListener> registration =
-                notificationServiceHandler.get().registerNotificationListener(listener, path);
+                notificationService.registerNotificationListener(listener, path);
         listener.setRegistration(registration);
     }
 
index 174297f41bec68056945f495afde5f6ca777ba4c..456923d609d252ed0ad1f2895bde4fbb342fda1f 100644 (file)
@@ -11,6 +11,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
@@ -20,7 +21,6 @@ import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfDataService;
@@ -73,7 +73,7 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe
             final DOMMountPointServiceHandler domMountPointServiceHandler,
             final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
             final DOMRpcService rpcService, final DOMActionService actionService,
-            final NotificationServiceHandler notificationServiceHandler, final DOMSchemaService domSchemaService,
+            final DOMNotificationService notificationService, final DOMSchemaService domSchemaService,
             final Configuration configuration) {
         RestconfOperationsService restconfOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler,
             domMountPointServiceHandler);
@@ -82,7 +82,7 @@ public final class ServicesWrapper implements BaseServicesWrapper, TransactionSe
         RestconfSchemaService restconfSchemaService = new RestconfSchemaServiceImpl(schemaCtxHandler,
             domMountPointServiceHandler, yangTextSourceProvider);
         RestconfStreamsSubscriptionService restconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(
-            domDataBrokerHandler, notificationServiceHandler, schemaCtxHandler, transactionChainHandler,
+            domDataBrokerHandler, notificationService, schemaCtxHandler, transactionChainHandler,
             configuration);
         RestconfDataService restconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler,
             domMountPointServiceHandler, restconfSubscrService, actionService, configuration);
index 70d855f565256c2100f270e8fe3e80603408d1af..340716b36ce63d1971a3056c924fa5e07684dd83 100644 (file)
@@ -40,6 +40,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
@@ -47,7 +48,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.util.SimpleUriInfo;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
@@ -71,7 +71,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Mock
     private UriInfo uriInfo;
     @Mock
-    private NotificationServiceHandler notificationServiceHandler;
+    private DOMNotificationService notificationService;
 
     private Configuration configurationWs;
     private Configuration configurationSse;
@@ -120,7 +120,6 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     }
 
     private static class LocalUriInfo extends SimpleUriInfo {
-
         LocalUriInfo() {
             super("/");
         }
@@ -157,7 +156,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationServiceHandler,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationSse);
         final NormalizedNodeContext response = streamsSubscriptionService
                 .subscribeToStream(
@@ -177,7 +176,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationServiceHandler,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationWs);
         final NormalizedNodeContext response = streamsSubscriptionService
                 .subscribeToStream(
@@ -190,21 +189,18 @@ public class RestconfStreamsSubscriptionServiceImplTest {
 
     @Test(expected = RestconfDocumentedException.class)
     public void testSubscribeToStreamMissingDatastoreInPath() {
-        final UriBuilder uriBuilder = UriBuilder.fromUri(URI);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationServiceHandler,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", this.uriInfo);
     }
 
     @Test(expected = RestconfDocumentedException.class)
     public void testSubscribeToStreamMissingScopeInPath() {
-        final UriBuilder uriBuilder = UriBuilder.fromUri(URI);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationServiceHandler,
+                new RestconfStreamsSubscriptionServiceImpl(this.dataBrokerHandler, this.notificationService,
                         this.schemaHandler, this.transactionHandler, configurationWs);
         streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL",
                 this.uriInfo);
     }
-
 }