Simplify HandlersHolder 03/108803/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 14:09:46 +0000 (15:09 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 14:10:11 +0000 (15:10 +0100)
This is a pure DTO, make it a record and update users.

JIRA: NETCONF-1102
Change-Id: I24276884f24165550fe0e69a5a0ea32488b04be9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImpl.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/SubscribeToStreamUtil.java

index 822862a2e0773c295127e0cbf032c9ec8f8dad37..24132cf3b9e46b25657c2ed4e154e3533b25a5e4 100644 (file)
@@ -13,6 +13,7 @@ import java.net.URI;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -74,7 +75,7 @@ public class RestconfStreamsSubscriptionServiceImpl implements RestconfStreamsSu
         return Response.ok()
             .location(location)
             .entity(new NormalizedNodePayload(
-                Inference.ofDataTreePath(handlersHolder.getDatabindProvider().currentContext().modelContext(),
+                Inference.ofDataTreePath(handlersHolder.databindProvider().currentContext().modelContext(),
                     Notifi.QNAME, LOCATION_QNAME),
                 ImmutableNodes.leafNode(LOCATION_NODEID, location.toString())))
             .build();
@@ -84,43 +85,15 @@ 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 DOMDataBroker dataBroker;
-        private final DOMNotificationService notificationService;
-        private final DatabindProvider databindProvider;
+    public record HandlersHolder(
+            @NonNull DOMDataBroker dataBroker,
+            @NonNull DOMNotificationService notificationService,
+            @NonNull DatabindProvider databindProvider) {
 
-        private HandlersHolder(final DOMDataBroker dataBroker, final DOMNotificationService notificationService,
-                final DatabindProvider databindProvider) {
-            this.dataBroker = dataBroker;
-            this.notificationService = notificationService;
-            this.databindProvider = databindProvider;
-        }
-
-        /**
-         * Get {@link DOMDataBroker}.
-         *
-         * @return the dataBroker
-         */
-        public DOMDataBroker getDataBroker() {
-            return dataBroker;
-        }
-
-        /**
-         * Get {@link DOMNotificationService}.
-         *
-         * @return the notificationService
-         */
-        public DOMNotificationService getNotificationServiceHandler() {
-            return notificationService;
-        }
-
-        /**
-         * Get {@link DatabindProvider}.
-         *
-         * @return the schemaHandler
-         */
-        public DatabindProvider getDatabindProvider() {
-            return databindProvider;
+        public HandlersHolder {
+            requireNonNull(dataBroker);
+            requireNonNull(notificationService);
+            requireNonNull(databindProvider);
         }
     }
 }
index 9a7e97bd19d9c5eaca529f5e534a49477f488edb..babdc4dc8bd90fbc8aa35f0de6f3dbc9a1057bb8 100644 (file)
@@ -131,9 +131,9 @@ public abstract class SubscribeToStreamUtil {
 
         final URI uri = prepareUriByStreamName(uriInfo, streamName);
         notificationListenerAdapter.setQueryParams(notificationQueryParams);
-        notificationListenerAdapter.listen(handlersHolder.getNotificationServiceHandler());
-        final DOMDataBroker dataBroker = handlersHolder.getDataBroker();
-        notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.getDatabindProvider());
+        notificationListenerAdapter.listen(handlersHolder.notificationService());
+        final DOMDataBroker dataBroker = handlersHolder.dataBroker();
+        notificationListenerAdapter.setCloseVars(dataBroker, handlersHolder.databindProvider());
         final MapEntryNode mapToStreams = RestconfStateStreams.notificationStreamEntry(streamName,
             notificationListenerAdapter.qnames(), notificationListenerAdapter.getStart(),
             notificationListenerAdapter.getOutputType(), uri);
@@ -166,8 +166,8 @@ public abstract class SubscribeToStreamUtil {
 
         listener.setQueryParams(notificationQueryParams);
 
-        final var dataBroker = handlersHolder.getDataBroker();
-        final var schemaHandler = handlersHolder.getDatabindProvider();
+        final var dataBroker = handlersHolder.dataBroker();
+        final var schemaHandler = handlersHolder.databindProvider();
         listener.setCloseVars(dataBroker, schemaHandler);
         listener.listen(dataBroker);