2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.netconf.impl;
11 import io.netty.channel.ChannelFuture;
12 import io.netty.channel.EventLoopGroup;
13 import io.netty.channel.socket.SocketChannel;
14 import io.netty.util.concurrent.Promise;
15 import java.net.InetSocketAddress;
16 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
17 import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer;
18 import org.opendaylight.protocol.framework.AbstractDispatcher;
20 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSession, NetconfServerSessionListener> {
22 private final ServerChannelInitializer initializer;
24 public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
25 EventLoopGroup workerGroup) {
26 super(bossGroup, workerGroup);
27 this.initializer = serverChannelInitializer;
30 public ChannelFuture createServer(InetSocketAddress address) {
32 return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
34 public void initializeChannel(final SocketChannel ch, final Promise<NetconfServerSession> promise) {
35 initializer.initialize(ch, promise);
40 public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
42 public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
44 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
47 public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
48 this.negotiatorFactory = negotiatorFactory;
53 protected void initializeMessageDecoder(SocketChannel ch) {
54 super.initializeMessageDecoder(ch);
55 ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
59 protected void initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
60 ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
61 negotiatorFactory.getSessionNegotiator(null, ch, promise));