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.api.NetconfSession;
17 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
18 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
19 import org.opendaylight.protocol.framework.AbstractDispatcher;
21 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, 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 // TODO test create server with same address twice
32 public ChannelFuture createServer(InetSocketAddress address) {
34 return super.createServer(address, new PipelineInitializer<NetconfSession>() {
36 public void initializeChannel(final SocketChannel ch, final Promise<NetconfSession> promise) {
37 initializer.initialize(ch, promise);
42 public static class ServerChannelInitializer extends AbstractChannelInitializer {
44 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
45 private final NetconfServerSessionListenerFactory listenerFactory;
47 public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
48 NetconfServerSessionListenerFactory listenerFactory) {
49 this.negotiatorFactory = negotiatorFactory;
50 this.listenerFactory = listenerFactory;
54 protected void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise) {
55 ch.pipeline().addLast("deserializerExHandler", new DeserializerExceptionHandler());
56 ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));