Fix some sonar/checkstyle issues
[netconf.git] / netconf / callhome-protocol / src / main / java / org / opendaylight / netconf / callhome / protocol / ReverseSshChannelInitializer.java
1 /*
2  * Copyright (c) 2016 Brocade Communication Systems 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
9 package org.opendaylight.netconf.callhome.protocol;
10
11 import io.netty.channel.Channel;
12 import io.netty.util.concurrent.Promise;
13 import org.opendaylight.netconf.client.NetconfClientSession;
14 import org.opendaylight.netconf.client.NetconfClientSessionListener;
15 import org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory;
16 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
17 import org.opendaylight.protocol.framework.SessionListenerFactory;
18
19 final class ReverseSshChannelInitializer extends AbstractChannelInitializer<NetconfClientSession>
20         implements SessionListenerFactory<NetconfClientSessionListener> {
21
22     private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
23     private final NetconfClientSessionListener sessionListener;
24
25     private ReverseSshChannelInitializer(NetconfClientSessionNegotiatorFactory negotiatorFactory,
26                                          NetconfClientSessionListener sessionListener) {
27         this.negotiatorFactory = negotiatorFactory;
28         this.sessionListener = sessionListener;
29     }
30
31     public static ReverseSshChannelInitializer create(NetconfClientSessionNegotiatorFactory negotiatorFactory,
32                                                       NetconfClientSessionListener listener) {
33         return new ReverseSshChannelInitializer(negotiatorFactory, listener);
34     }
35
36     @Override
37     public NetconfClientSessionListener getSessionListener() {
38         return sessionListener;
39     }
40
41     @Override
42     protected void initializeSessionNegotiator(Channel ch, Promise<NetconfClientSession> promise) {
43         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
44                 negotiatorFactory.getSessionNegotiator(this, ch, promise));
45     }
46 }