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;
16 import java.net.InetSocketAddress;
18 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
19 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
20 import org.opendaylight.protocol.framework.AbstractDispatcher;
22 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSession, NetconfServerSessionListener> {
24 private final ServerChannelInitializer initializer;
26 public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
27 EventLoopGroup workerGroup) {
28 super(bossGroup, workerGroup);
29 this.initializer = serverChannelInitializer;
32 public ChannelFuture createServer(InetSocketAddress address) {
34 return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
36 public void initializeChannel(final SocketChannel ch, final Promise<NetconfServerSession> promise) {
37 initializer.initialize(ch, promise);
42 public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
44 public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
46 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
47 private final NetconfServerSessionListenerFactory listenerFactory;
49 public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
50 NetconfServerSessionListenerFactory listenerFactory) {
51 this.negotiatorFactory = negotiatorFactory;
52 this.listenerFactory = listenerFactory;
56 protected void initializeMessageDecoder(SocketChannel ch) {
57 super.initializeMessageDecoder(ch);
58 ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
62 protected void initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
63 ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));