NetconfSubsystem should be a ChannelDataReceiver 73/108373/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Oct 2023 15:12:42 +0000 (17:12 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 12 Oct 2023 20:42:49 +0000 (20:42 +0000)
We are tightly bound to our inner channel, do not allocate a separate
object just to shuffle bytes.

JIRA: NETCONF-1106
Change-Id: I2311170bdc6b1566be5062c1ea0ca38273187966
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
protocol/netconf-server/src/main/java/org/opendaylight/netconf/server/NetconfSubsystem.java

index 0c1b23a75594aeee76cb8b7fc3da638d54a66842..7e4cbbf5d123b0dd82629bf52fb0e7917768b74d 100644 (file)
@@ -33,7 +33,8 @@ import org.opendaylight.netconf.shaded.sshd.server.command.AsyncCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class NetconfSubsystem extends AbstractCommandSupport implements AsyncCommand, ChannelSessionAware {
+final class NetconfSubsystem extends AbstractCommandSupport
+        implements AsyncCommand, ChannelSessionAware, ChannelDataReceiver {
     private static final Logger LOG = LoggerFactory.getLogger(NetconfSubsystem.class);
 
     private final EmbeddedChannel innerChannel = new EmbeddedChannel();
@@ -120,18 +121,18 @@ final class NetconfSubsystem extends AbstractCommandSupport implements AsyncComm
          * NOTE: The channel data receiver require to be set within current method, so it could be handled
          * with subsequent logic of ChannelSession#prepareChannelCommand() where this method is executed from.
          */
-        channelSession.setDataReceiver(new ChannelDataReceiver() {
-            @Override
-            public int data(final ChannelSession channel, final byte[] buf, final int start, final int len) {
-                innerChannel.writeInbound(Unpooled.copiedBuffer(buf, start, len));
-                return len;
-            }
-
-            @Override
-            public void close() {
-                innerChannel.close();
-            }
-        });
+        channelSession.setDataReceiver(this);
+    }
+
+    @Override
+    public int data(final ChannelSession channel, final byte[] buf, final int start, final int len) {
+        innerChannel.writeInbound(Unpooled.copiedBuffer(buf, start, len));
+        return len;
+    }
+
+    @Override
+    public void close() {
+        innerChannel.close();
     }
 
     @Override