81f2d00b9724222973af2bea2ce6f39f788cdcc5
[netconf.git] / netconf / 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 NetconfSshClient sshClient;
20
21     SshClientChannelInitializer(final AuthenticationHandler authHandler,
22             final NetconfClientSessionNegotiatorFactory negotiatorFactory,
23             final NetconfClientSessionListener sessionListener, @Nullable final NetconfSshClient sshClient) {
24         super(negotiatorFactory, sessionListener);
25         authenticationHandler = authHandler;
26         this.sshClient = sshClient;
27     }
28
29     SshClientChannelInitializer(final AuthenticationHandler authHandler,
30             final NetconfClientSessionNegotiatorFactory negotiatorFactory,
31             final NetconfClientSessionListener sessionListener) {
32         this(authHandler, negotiatorFactory, sessionListener, null);
33     }
34
35     @Override
36     public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
37         // ssh handler has to be the first handler in pipeline
38         ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise, sshClient));
39         super.initialize(ch, promise);
40     }
41 }