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.netconf.impl;
11 import io.netty.channel.Channel;
12 import io.netty.channel.ChannelFuture;
13 import io.netty.channel.EventLoopGroup;
14 import io.netty.channel.local.LocalAddress;
15 import io.netty.channel.local.LocalChannel;
16 import io.netty.channel.local.LocalServerChannel;
17 import io.netty.channel.socket.SocketChannel;
18 import io.netty.util.concurrent.Promise;
19 import java.net.InetSocketAddress;
20 import org.opendaylight.netconf.api.NetconfServerDispatcher;
21 import org.opendaylight.netconf.impl.util.DeserializerExceptionHandler;
22 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
23 import org.opendaylight.protocol.framework.AbstractDispatcher;
25 public class NetconfServerDispatcherImpl extends AbstractDispatcher<NetconfServerSession,
26 NetconfServerSessionListener> implements NetconfServerDispatcher {
28 private final ServerChannelInitializer initializer;
30 public NetconfServerDispatcherImpl(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
31 EventLoopGroup workerGroup) {
32 super(bossGroup, workerGroup);
33 this.initializer = serverChannelInitializer;
37 public ChannelFuture createServer(InetSocketAddress address) {
38 return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
40 public void initializeChannel(final SocketChannel ch, final Promise<NetconfServerSession> promise) {
41 initializer.initialize(ch, promise);
47 public ChannelFuture createLocalServer(LocalAddress address) {
48 return super.createServer(address, LocalServerChannel.class, new ChannelPipelineInitializer<LocalChannel,
49 NetconfServerSession>() {
51 public void initializeChannel(final LocalChannel ch, final Promise<NetconfServerSession> promise) {
52 initializer.initialize(ch, promise);
57 public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
59 public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
61 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
64 public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
65 this.negotiatorFactory = negotiatorFactory;
70 protected void initializeMessageDecoder(Channel ch) {
71 super.initializeMessageDecoder(ch);
72 ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
76 protected void initializeSessionNegotiator(Channel ch, Promise<NetconfServerSession> promise) {
77 ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
78 negotiatorFactory.getSessionNegotiator(null, ch, promise));