df39613f8a15ec05b7f52f0e08f4efe1c38bc13f
[netconf.git] / netconf / netconf-impl / src / main / java / org / opendaylight / netconf / impl / ServerChannelInitializer.java
1 /*
2  * Copyright (c) 2013 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.impl;
9
10 import io.netty.channel.Channel;
11 import io.netty.util.concurrent.Promise;
12 import org.opendaylight.netconf.impl.util.DeserializerExceptionHandler;
13 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
14
15 public class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
16
17     public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
18
19     private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
20
21
22     public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
23         this.negotiatorFactory = negotiatorFactory;
24
25     }
26
27     @Override
28     protected void initializeMessageDecoder(Channel ch) {
29         super.initializeMessageDecoder(ch);
30         ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
31     }
32
33     @Override
34     protected void initializeSessionNegotiator(Channel ch, Promise<NetconfServerSession> promise) {
35         ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
36                 negotiatorFactory.getSessionNegotiator(null, ch, promise));
37     }
38 }