NetconfOperationRouter should not expose close() 09/105709/4
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Apr 2023 15:42:22 +0000 (17:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Apr 2023 16:43:55 +0000 (18:43 +0200)
The close() method is a component contract, it should not be part of the
functional definition. This fixes a warning around the possibility of an
InterrupatedException.

JIRA: NETCONF-945
Change-Id: Ic26e9fe1d56b8aff6493ce6537196f525022a5f3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionListener.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfServerSessionNegotiatorFactory.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/osgi/NetconfOperationRouter.java
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/osgi/NetconfOperationRouterImpl.java
protocol/netconf-server/src/test/java/org/opendaylight/netconf/server/NetconfServerSessionListenerTest.java

index 96609b26dbb8c1801f03b7db012f60eaae59116d..1a3ad542bb18a99164153c5e4bad1cdd01f4bf88 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.server;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
 import org.opendaylight.netconf.api.DocumentedException;
@@ -19,7 +21,7 @@ import org.opendaylight.netconf.api.monitoring.SessionEvent;
 import org.opendaylight.netconf.api.monitoring.SessionListener;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.server.osgi.NetconfOperationRouter;
+import org.opendaylight.netconf.server.osgi.NetconfOperationRouterImpl;
 import org.opendaylight.netconf.util.messages.SubtreeFilter;
 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.ErrorTag;
@@ -34,13 +36,12 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
     private static final Logger LOG = LoggerFactory.getLogger(NetconfServerSessionListener.class);
 
     private final SessionListener monitoringSessionListener;
-    private final NetconfOperationRouter operationRouter;
+    private final NetconfOperationRouterImpl operationRouter;
     private final AutoCloseable onSessionDownCloseable;
 
-    public NetconfServerSessionListener(final NetconfOperationRouter operationRouter,
-                                        final NetconfMonitoringService monitoringService,
-                                        final AutoCloseable onSessionDownCloseable) {
-        this.operationRouter = operationRouter;
+    NetconfServerSessionListener(final NetconfOperationRouterImpl operationRouter,
+            final NetconfMonitoringService monitoringService, final AutoCloseable onSessionDownCloseable) {
+        this.operationRouter = requireNonNull(operationRouter);
         monitoringSessionListener = monitoringService.getSessionListener();
         this.onSessionDownCloseable = onSessionDownCloseable;
     }
index 06be5b3c324a6ddef2b1732c716124480336954e..74e803be29cd7e455317aae004b67c6c24b4be04 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.netconf.nettyutil.AbstractNetconfSessionNegotiator;
 import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiatorFactory;
-import org.opendaylight.netconf.server.osgi.NetconfOperationRouter;
 import org.opendaylight.netconf.server.osgi.NetconfOperationRouterImpl;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
@@ -116,11 +115,10 @@ public class NetconfServerSessionNegotiatorFactory
 
     private NetconfServerSessionListener getListener(final String netconfSessionIdForReporting,
                                                      final SocketAddress socketAddress) {
-        final NetconfOperationService service = getOperationServiceForAddress(netconfSessionIdForReporting,
-                socketAddress);
-        final NetconfOperationRouter operationRouter =
-                new NetconfOperationRouterImpl(service, monitoringService, netconfSessionIdForReporting);
-        return new NetconfServerSessionListener(operationRouter, monitoringService, service);
+        final var service = getOperationServiceForAddress(netconfSessionIdForReporting, socketAddress);
+        return new NetconfServerSessionListener(
+            new NetconfOperationRouterImpl(service, monitoringService, netconfSessionIdForReporting), monitoringService,
+            service);
     }
 
     protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting,
index 91ec67b107000222f214d2590deb61acd097b0e5..c76d7104956818cd91aa57599a77c0c68d08d1b9 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.server.NetconfServerSession;
 import org.w3c.dom.Document;
 
-public interface NetconfOperationRouter extends AutoCloseable {
+public interface NetconfOperationRouter {
 
     Document onNetconfMessage(Document message, NetconfServerSession session) throws DocumentedException;
 }
index 9ba53977c5539cc151135da67eb600d65e0dbb42..3a2cf07efdf29e76c07ae7aa51f7b9b5dd6a2121 100644 (file)
@@ -37,14 +37,15 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
-public class NetconfOperationRouterImpl implements NetconfOperationRouter {
+// Non-final for testing
+public class NetconfOperationRouterImpl implements NetconfOperationRouter, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfOperationRouterImpl.class);
 
     private final NetconfOperationService netconfOperationServiceSnapshot;
     private final Collection<NetconfOperation> allNetconfOperations;
 
     public NetconfOperationRouterImpl(final NetconfOperationService netconfOperationServiceSnapshot,
-                                      final NetconfMonitoringService netconfMonitoringService, final String sessionId) {
+            final NetconfMonitoringService netconfMonitoringService, final String sessionId) {
         this.netconfOperationServiceSnapshot = requireNonNull(netconfOperationServiceSnapshot);
 
         final Set<NetconfOperation> ops = new HashSet<>();
@@ -59,8 +60,8 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public Document onNetconfMessage(final Document message, final NetconfServerSession session) throws
-            DocumentedException {
+    public Document onNetconfMessage(final Document message, final NetconfServerSession session)
+            throws DocumentedException {
         requireNonNull(allNetconfOperations, "Operation router was not initialized properly");
 
         final NetconfOperationExecution netconfOperationExecution;
index e6b62f6d7c6d1d496a75bbccd656749b6dd14f85..b8d37a1e991d642150eca7acf8d1901334d27b05 100644 (file)
@@ -33,13 +33,13 @@ import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.netconf.api.monitoring.SessionEvent;
 import org.opendaylight.netconf.api.monitoring.SessionListener;
 import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.netconf.server.osgi.NetconfOperationRouter;
+import org.opendaylight.netconf.server.osgi.NetconfOperationRouterImpl;
 import org.w3c.dom.Document;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class NetconfServerSessionListenerTest {
     @Mock
-    private NetconfOperationRouter router;
+    private NetconfOperationRouterImpl router;
     @Mock
     private NetconfMonitoringService monitoring;
     @Mock