Move netconf-dom-api
[netconf.git] / protocol / netconf-client / src / main / java / org / opendaylight / netconf / client / SshClientChannelInitializer.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.client;
9
10 import io.netty.channel.Channel;
11 import io.netty.util.concurrent.Promise;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
14 import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
15 import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfSshClient;
16
17 final class SshClientChannelInitializer extends AbstractClientChannelInitializer {
18     private final AuthenticationHandler authenticationHandler;
19     private final @Nullable NetconfSshClient sshClient;
20     private final @Nullable String name;
21
22     SshClientChannelInitializer(final AuthenticationHandler authHandler,
23             final NetconfClientSessionNegotiatorFactory negotiatorFactory,
24             final NetconfClientSessionListener sessionListener, final @Nullable NetconfSshClient sshClient,
25             final @Nullable String name) {
26         super(negotiatorFactory, sessionListener);
27         authenticationHandler = authHandler;
28         this.sshClient = sshClient;
29         this.name = name;
30     }
31
32     SshClientChannelInitializer(final AuthenticationHandler authHandler,
33             final NetconfClientSessionNegotiatorFactory negotiatorFactory,
34             final NetconfClientSessionListener sessionListener) {
35         this(authHandler, negotiatorFactory, sessionListener, null, null);
36     }
37
38     @Override
39     public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
40         // ssh handler has to be the first handler in pipeline
41         var asyncHandler = AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise, sshClient, name);
42         ch.pipeline().addFirst(asyncHandler);
43         super.initialize(ch, promise);
44     }
45 }