3ce4c990f6530a5fa9be58eead8a8835564f083a
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / NetconfClientSessionImpl.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.nettyutil.handler.ssh.client;
9
10 import com.google.common.annotations.Beta;
11 import io.netty.channel.ChannelHandlerContext;
12 import java.io.IOException;
13 import org.opendaylight.netconf.shaded.sshd.client.ClientFactoryManager;
14 import org.opendaylight.netconf.shaded.sshd.client.SshClient;
15 import org.opendaylight.netconf.shaded.sshd.client.session.ClientSessionImpl;
16 import org.opendaylight.netconf.shaded.sshd.common.Factory;
17 import org.opendaylight.netconf.shaded.sshd.common.io.IoSession;
18 import org.opendaylight.netconf.shaded.sshd.common.session.ConnectionService;
19
20 /**
21  * A {@link ClientSessionImpl} which additionally allows creation of NETCONF subsystem channel, which is routed to
22  * a particular {@link ChannelHandlerContext}.
23  */
24 @Beta
25 public class NetconfClientSessionImpl extends ClientSessionImpl implements NettyAwareClientSession {
26     public static final Factory<SshClient> DEFAULT_NETCONF_SSH_CLIENT_FACTORY = SshClient::new;
27
28     public NetconfClientSessionImpl(final ClientFactoryManager client, final IoSession ioSession) throws Exception {
29         super(client, ioSession);
30     }
31
32     @Override
33     public NettyAwareChannelSubsystem createSubsystemChannel(final String subsystem, final ChannelHandlerContext ctx)
34             throws IOException {
35         final NettyAwareChannelSubsystem channel = new NettyAwareChannelSubsystem(subsystem, ctx);
36         final ConnectionService service = getConnectionService();
37         final int id = service.registerChannel(channel);
38         if (log.isDebugEnabled()) {
39             log.debug("createSubsystemChannel({})[{}] created id={}", this, channel.getSubsystem(), id);
40         }
41         return channel;
42     }
43 }