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();
}
}