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