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
8 package org.opendaylight.netconf.impl;
10 import io.netty.channel.Channel;
11 import io.netty.channel.ChannelFuture;
12 import io.netty.channel.EventLoopGroup;
13 import io.netty.channel.local.LocalAddress;
14 import io.netty.channel.local.LocalServerChannel;
15 import io.netty.util.concurrent.Promise;
16 import java.net.InetSocketAddress;
17 import org.opendaylight.netconf.api.NetconfServerDispatcher;
18 import org.opendaylight.netconf.impl.util.DeserializerExceptionHandler;
19 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
20 import org.opendaylight.netconf.nettyutil.AbstractNetconfDispatcher;
22 public class NetconfServerDispatcherImpl extends AbstractNetconfDispatcher<NetconfServerSession,
23 NetconfServerSessionListener> implements NetconfServerDispatcher {
25 private final ServerChannelInitializer initializer;
27 public NetconfServerDispatcherImpl(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
28 EventLoopGroup workerGroup) {
29 super(bossGroup, workerGroup);
30 this.initializer = serverChannelInitializer;
34 public ChannelFuture createServer(InetSocketAddress address) {
35 return super.createServer(address, initializer::initialize);
39 public ChannelFuture createLocalServer(LocalAddress address) {
40 return super.createServer(address, LocalServerChannel.class, initializer::initialize);
43 public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
45 public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
47 private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
50 public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
51 this.negotiatorFactory = negotiatorFactory;
56 protected void initializeMessageDecoder(Channel ch) {
57 super.initializeMessageDecoder(ch);
58 ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
62 protected void initializeSessionNegotiator(Channel ch, Promise<NetconfServerSession> promise) {
63 ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
64 negotiatorFactory.getSessionNegotiator(null, ch, promise));