Fixed bug when Binding-Aware Data Change Listeners we're not triggered.
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerDispatcher.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.controller.netconf.impl;
10
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 org.opendaylight.controller.netconf.api.NetconfSession;
16 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
17 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
18 import org.opendaylight.protocol.framework.AbstractDispatcher;
19
20 import java.net.InetSocketAddress;
21
22 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
23
24     private final ServerChannelInitializer initializer;
25
26     public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
27             EventLoopGroup workerGroup) {
28         super(bossGroup, workerGroup);
29         this.initializer = serverChannelInitializer;
30     }
31
32     public ChannelFuture createServer(InetSocketAddress address) {
33
34         return super.createServer(address, new PipelineInitializer<NetconfSession>() {
35             @Override
36             public void initializeChannel(final SocketChannel ch, final Promise<NetconfSession> promise) {
37                 initializer.initialize(ch, promise);
38             }
39         });
40     }
41
42     public static class ServerChannelInitializer extends AbstractChannelInitializer {
43
44         private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
45         private final NetconfServerSessionListenerFactory listenerFactory;
46
47         public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
48                                             NetconfServerSessionListenerFactory listenerFactory) {
49             this.negotiatorFactory = negotiatorFactory;
50             this.listenerFactory = listenerFactory;
51         }
52
53         @Override
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));
57         }
58
59     }
60
61 }