Add workaround for SSH connection issue related to SSHD-1028
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / NetconfSshClient.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 org.opendaylight.netconf.nettyutil.handler.ssh.sshd1028.NetconfNio2ServiceFactoryFactory;
12 import org.opendaylight.netconf.shaded.sshd.client.SshClient;
13 import org.opendaylight.netconf.shaded.sshd.common.Factory;
14 import org.opendaylight.netconf.shaded.sshd.common.io.IoConnector;
15
16
17 /**
18  * An extension to {@link SshClient} which uses {@link NetconfSessionFactory} to create sessions (leading towards
19  * {@link NetconfClientSessionImpl}.
20  */
21 @Beta
22 public class NetconfSshClient extends SshClient {
23     public static final Factory<SshClient> DEFAULT_NETCONF_SSH_CLIENT_FACTORY = NetconfSshClient::new;
24     private final NetconfNio2ServiceFactoryFactory nio2ServiceFactoryFactory;
25
26     public NetconfSshClient() {
27         this.nio2ServiceFactoryFactory = new NetconfNio2ServiceFactoryFactory();
28     }
29
30     @Override
31     protected NetconfSessionFactory createSessionFactory() {
32         return new NetconfSessionFactory(this);
33     }
34
35     @Override
36     protected IoConnector createConnector() {
37         setIoServiceFactoryFactory(nio2ServiceFactoryFactory);
38         return getIoServiceFactory().createConnector(getSessionFactory());
39     }
40 }