Make LoggingRemoteDevice a singleton 72/108472/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Oct 2023 08:52:48 +0000 (10:52 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Oct 2023 08:52:48 +0000 (10:52 +0200)
There is no point in creating multiple instances of this class, just
squash them to a single instance.

Change-Id: Icb501b176577e2c18df565a7d7aeda01e047ca09
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClient.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/StressClientCallable.java

index a9d0d38a4f4faa3cc7f9bccfe3b3a3dea6e27cf3..33dd64183952c47a6f5c348b294002d0ab796e70 100644 (file)
@@ -42,6 +42,24 @@ import org.xml.sax.SAXException;
 public final class StressClient {
     private static final Logger LOG = LoggerFactory.getLogger(StressClient.class);
 
+    static final RemoteDevice<NetconfDeviceCommunicator> LOGGING_REMOTE_DEVICE = new RemoteDevice<>() {
+        @Override
+        public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
+                final NetconfDeviceCommunicator netconfDeviceCommunicator) {
+            LOG.info("Session established");
+        }
+
+        @Override
+        public void onRemoteSessionDown() {
+            LOG.info("Session down");
+        }
+
+        @Override
+        public void onNotification(final NetconfMessage notification) {
+            LOG.info("Notification received: {}", notification);
+        }
+    };
+
     static final QName COMMIT_QNAME = QName.create(CommitInput.QNAME, "commit");
     public static final NetconfMessage COMMIT_MSG = new NetconfMessage(readString("""
         <rpc message-id="commit-batch" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
@@ -227,22 +245,4 @@ public final class StressClient {
         return params.legacyFraming ? ConfigurableClientDispatcher.createLegacy(nioGroup, nioGroup, timer)
             : ConfigurableClientDispatcher.createChunked(nioGroup, nioGroup, timer);
     }
-
-    static class LoggingRemoteDevice implements RemoteDevice<NetconfDeviceCommunicator> {
-        @Override
-        public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
-                                      final NetconfDeviceCommunicator netconfDeviceCommunicator) {
-            LOG.info("Session established");
-        }
-
-        @Override
-        public void onRemoteSessionDown() {
-            LOG.info("Session down");
-        }
-
-        @Override
-        public void onNotification(final NetconfMessage notification) {
-            LOG.info("Notification received: {}", notification);
-        }
-    }
 }
index 88b86cc1bf7ac5dda71928d5d8ba259111abaf6e..09dfe880ba19d13ba4034ed35892f7bceda7597b 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.netconf.client.NetconfClientSession;
 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder;
 import org.opendaylight.netconf.client.mdsal.NetconfDeviceCommunicator;
-import org.opendaylight.netconf.client.mdsal.api.RemoteDevice;
 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler;
 import org.slf4j.Logger;
@@ -70,11 +69,10 @@ public class StressClientCallable implements Callable<Boolean> {
         }
     }
 
-    private static NetconfDeviceCommunicator getSessionListener(
-            final InetSocketAddress inetAddress, final int messageLimit) {
-        final RemoteDevice<NetconfDeviceCommunicator> loggingRemoteDevice = new StressClient.LoggingRemoteDevice();
-        return new NetconfDeviceCommunicator(
-            new RemoteDeviceId("secure-test", inetAddress), loggingRemoteDevice, messageLimit);
+    private static NetconfDeviceCommunicator getSessionListener(final InetSocketAddress inetAddress,
+            final int messageLimit) {
+        return new NetconfDeviceCommunicator(new RemoteDeviceId("secure-test", inetAddress),
+            StressClient.LOGGING_REMOTE_DEVICE, messageLimit);
     }
 
     private static NetconfClientConfiguration getNetconfClientConfiguration(final Parameters params,