Refactor persister.
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / osgi / NetconfImplActivator.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 package org.opendaylight.controller.netconf.impl.osgi;
9
10 import com.google.common.base.Optional;
11 import io.netty.channel.nio.NioEventLoopGroup;
12 import io.netty.util.HashedWheelTimer;
13 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
14 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
15 import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
16 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
17 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
18 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
19 import org.osgi.framework.BundleActivator;
20 import org.osgi.framework.BundleContext;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import javax.net.ssl.SSLContext;
25 import java.lang.management.ManagementFactory;
26 import java.net.InetSocketAddress;
27
28 public class NetconfImplActivator implements BundleActivator {
29
30     private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
31
32     private NetconfOperationServiceFactoryTracker factoriesTracker;
33     private DefaultCommitNotificationProducer commitNot;
34     private NetconfServerDispatcher dispatch;
35     private NioEventLoopGroup eventLoopGroup;
36     private HashedWheelTimer timer;
37
38     @Override
39     public void start(final BundleContext context) throws Exception {
40         InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context, "TCP is not configured, netconf not available.");
41
42         NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
43         factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
44         factoriesTracker.open();
45
46         SessionIdProvider idProvider = new SessionIdProvider();
47         timer = new HashedWheelTimer();
48         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
49                 timer, factoriesListener, idProvider);
50
51         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
52
53         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
54                 factoriesListener, commitNot, idProvider);
55
56         eventLoopGroup = new NioEventLoopGroup();
57
58         NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
59                 Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
60         dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
61
62         logger.info("Starting TCP netconf server at {}", address);
63         dispatch.createServer(address);
64
65     }
66
67     @Override
68     public void stop(final BundleContext context) throws Exception {
69         logger.info("Shutting down netconf because YangStoreService service was removed");
70
71         commitNot.close();
72         eventLoopGroup.shutdownGracefully();
73         timer.stop();
74     }
75 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.