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 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<NetconfServerSession> promise) {
55 ch.pipeline().addLast("deserializerExHandler", new DeserializerExceptionHandler());
56 ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));