Remove a FindBugs suppression
[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.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
13 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
14 import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
15
16 final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
17
18     private final AuthenticationHandler authenticationHandler;
19     private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
20     private final NetconfClientSessionListener sessionListener;
21
22     SshClientChannelInitializer(final AuthenticationHandler authHandler,
23                                 final NetconfClientSessionNegotiatorFactory negotiatorFactory,
24                                 final NetconfClientSessionListener sessionListener) {
25         this.authenticationHandler = authHandler;
26         this.negotiatorFactory = negotiatorFactory;
27         this.sessionListener = sessionListener;
28     }
29
30     @Override
31     public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
32         // ssh handler has to be the first handler in pipeline
33         ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
34         super.initialize(ch, promise);
35     }
36
37     @Override
38     protected void initializeSessionNegotiator(final Channel ch,
39                                                final Promise<NetconfClientSession> promise) {
40         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
41                 negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
42     }
43 }