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