2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.nettyutil.handler.ssh.client;
10 import io.netty.buffer.Unpooled;
11 import io.netty.channel.ChannelHandlerContext;
12 import java.io.IOException;
13 import org.opendaylight.netconf.shaded.sshd.client.channel.ChannelSubsystem;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Abstract base class for {@link ChannelSubsystem}s backed by a Netty {@link ChannelHandlerContext}.
20 abstract class NettyChannelSubsystem extends ChannelSubsystem {
21 private static final Logger LOG = LoggerFactory.getLogger(NettyChannelSubsystem.class);
23 NettyChannelSubsystem(final String subsystem) {
28 public final void close() {
33 protected final void doWriteExtendedData(final byte[] data, final int off, final long len) throws IOException {
34 // If we're already closing, ignore incoming data
39 LOG.debug("Discarding {} bytes of extended data", len);
41 getLocalWindow().release(len);
46 protected final void doWriteData(final byte[] data, final int off, final long len) throws IOException {
47 // If we're already closing, ignore incoming data
52 // TODO: consider using context's allocator for heap buffer here
53 final int reqLen = (int) len;
54 context().fireChannelRead(Unpooled.copiedBuffer(data, off, reqLen));
56 getLocalWindow().release(reqLen);
60 abstract ChannelHandlerContext context();