- remove TLS/SSL support from netconf server and client
[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, "TCP is not configured, netconf not available.");
38
39         NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
40         factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
41         factoriesTracker.open();
42
43         SessionIdProvider idProvider = new SessionIdProvider();
44         timer = new HashedWheelTimer();
45         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
46                 timer, factoriesListener, idProvider);
47
48         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
49
50         NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
51                 factoriesListener, commitNot, idProvider);
52
53         eventLoopGroup = new NioEventLoopGroup();
54
55         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
56                 serverNegotiatorFactory, listenerFactory);
57         dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
58
59         logger.info("Starting TCP netconf server at {}", address);
60         dispatch.createServer(address);
61
62     }
63
64     @Override
65     public void stop(final BundleContext context) throws Exception {
66         logger.info("Shutting down netconf because YangStoreService service was removed");
67
68         commitNot.close();
69         eventLoopGroup.shutdownGracefully();
70         timer.stop();
71     }
72 }