a4fb71a17ddab6ded4e8d97a45ab007fcace98fd
[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 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         super();
28         this.negotiatorFactory = negotiatorFactory;
29         this.sessionListener = sessionListener;
30     }
31
32     public static ReverseSshChannelInitializer create(NetconfClientSessionNegotiatorFactory negotiatorFactory,
33                                                       NetconfClientSessionListener listener) {
34         return new ReverseSshChannelInitializer(negotiatorFactory, listener);
35     }
36
37     @Override
38     public NetconfClientSessionListener getSessionListener() {
39         return sessionListener;
40     }
41
42     @Override
43     protected void initializeSessionNegotiator(Channel ch, Promise<NetconfClientSession> promise) {
44         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
45                 negotiatorFactory.getSessionNegotiator(this, ch, promise));
46     }
47 }