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 org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
16 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
17 import org.opendaylight.protocol.framework.AbstractDispatcher;
19 import java.net.InetSocketAddress;
21 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSession, NetconfServerSessionListener> {
23 private final ServerChannelInitializer initializer;
25 public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
26 EventLoopGroup workerGroup) {
27 super(bossGroup, workerGroup);
28 this.initializer = serverChannelInitializer;
31 public ChannelFuture createServer(InetSocketAddress address) {
33 return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
35 public void initializeChannel(final SocketChannel ch, final Promise<NetconfServerSession> promise) {
36 initializer.initialize(ch, promise);
41 public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
43 public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
45 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
48 public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
49 this.negotiatorFactory = negotiatorFactory;
54 protected void initializeMessageDecoder(SocketChannel ch) {
55 super.initializeMessageDecoder(ch);
56 ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
60 protected void initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
61 ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
62 negotiatorFactory.getSessionNegotiator(null, ch, promise));