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