Clean up NetconfClientSessionImpl
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / NettyPipelineAwareChannelSubsystem.java
index d02e585b1e43dee29b8c659dab57f773ed459a64..c4af65987a3e6ab0449b0f4edee14153bc874a51 100644 (file)
@@ -9,55 +9,24 @@ package org.opendaylight.netconf.nettyutil.handler.ssh.client;
 
 import static java.util.Objects.requireNonNull;
 
-import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelPipeline;
-import java.io.IOException;
-import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
- * A {@link ChannelSubsystem} for subsystem which routes incoming data to a particular {@link ChannelPipeline}.
+ * A {@link AbstractNettyChannelSubsystem} for subsystem which routes incoming data to a particular
+ * {@link ChannelPipeline}.
  */
-public class NettyPipelineAwareChannelSubsystem extends ChannelSubsystem {
-    private static final Logger LOG = LoggerFactory.getLogger(NettyPipelineAwareChannelSubsystem.class);
-
+// Non-final for testing
+public non-sealed class NettyPipelineAwareChannelSubsystem extends AbstractNettyChannelSubsystem {
     private final ChannelPipeline pipeline;
 
-    public NettyPipelineAwareChannelSubsystem(final String subsystem, final ChannelPipeline pipeline) {
+    NettyPipelineAwareChannelSubsystem(final String subsystem, final ChannelPipeline pipeline) {
         super(subsystem);
         this.pipeline = requireNonNull(pipeline);
     }
 
     @Override
-    protected void doWriteData(final byte[] data, final int off, final long len) throws IOException {
-        // If we're already closing, ignore incoming data
-        if (isClosing()) {
-            return;
-        }
-        // TODO: consider using context's allocator for heap buffer here
-        final int reqLen = (int) len;
-        pipeline.firstContext().fireChannelRead(Unpooled.copiedBuffer(data, off, reqLen));
-        if (reqLen > 0) {
-            getLocalWindow().release(reqLen);
-        }
-    }
-
-    @Override
-    protected void doWriteExtendedData(final byte[] data, final int off, final long len) throws IOException {
-        // If we're already closing, ignore incoming data
-        if (isClosing()) {
-            return;
-        }
-
-        LOG.debug("Discarding {} bytes of extended data", len);
-        if (len > 0) {
-            getLocalWindow().release(len);
-        }
-    }
-
-    @Override
-    public void close() {
-        super.close(false);
+    final ChannelHandlerContext context() {
+        return pipeline.firstContext();
     }
 }