BUG-625: migrate InventoryAndReadAdapter
[controller.git] / opendaylight / netconf / netconf-client / src / main / java / org / opendaylight / controller / netconf / client / TcpClientChannelInitializer.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.controller.netconf.client;
9
10 import io.netty.channel.socket.SocketChannel;
11 import io.netty.util.concurrent.Promise;
12 import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer;
13 import org.opendaylight.protocol.framework.SessionListenerFactory;
14
15 class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
16
17     private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
18     private final NetconfClientSessionListener sessionListener;
19
20     TcpClientChannelInitializer(final NetconfClientSessionNegotiatorFactory negotiatorFactory,
21                                 final NetconfClientSessionListener sessionListener) {
22         this.negotiatorFactory = negotiatorFactory;
23         this.sessionListener = sessionListener;
24     }
25
26     @Override
27     public void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
28         super.initialize(ch, promise);
29     }
30
31     @Override
32     protected void initializeSessionNegotiator(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
33         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
34                 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
35                     @Override
36                     public NetconfClientSessionListener getSessionListener() {
37                         return sessionListener;
38                     }
39                 }, ch, promise));
40     }
41 }