394771b122691f54f1d93648074bc3cf57820709
[transportpce.git] / tests / honeynode / 2.2.1 / netconf-impl / src / main / java / org / opendaylight / netconf / impl / NetconfServerDispatcherImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.impl;
10
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.LocalServerChannel;
16 import io.netty.util.concurrent.Promise;
17 import java.net.InetSocketAddress;
18 import org.opendaylight.netconf.api.NetconfServerDispatcher;
19 import org.opendaylight.netconf.impl.util.DeserializerExceptionHandler;
20 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
21 import org.opendaylight.protocol.framework.AbstractDispatcher;
22
23 public class NetconfServerDispatcherImpl extends AbstractDispatcher<NetconfServerSession,
24         NetconfServerSessionListener> implements NetconfServerDispatcher {
25
26     private final ServerChannelInitializer initializer;
27
28     public NetconfServerDispatcherImpl(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
29                                        EventLoopGroup workerGroup) {
30         super(bossGroup, workerGroup);
31         this.initializer = serverChannelInitializer;
32     }
33
34     @Override
35     public ChannelFuture createServer(InetSocketAddress address) {
36         return super.createServer(address, initializer::initialize);
37     }
38
39     @Override
40     public ChannelFuture createLocalServer(LocalAddress address) {
41         return super.createServer(address, LocalServerChannel.class, initializer::initialize);
42     }
43
44     public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
45
46         public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
47
48         private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
49
50
51         public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
52             this.negotiatorFactory = negotiatorFactory;
53
54         }
55
56         @Override
57         protected void initializeMessageDecoder(Channel ch) {
58             super.initializeMessageDecoder(ch);
59             ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
60         }
61
62         @Override
63         protected void initializeSessionNegotiator(Channel ch, Promise<NetconfServerSession> promise) {
64             ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
65                     negotiatorFactory.getSessionNegotiator(null, ch, promise));
66         }
67     }
68 }