2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.netconf.impl.osgi;
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;
25 public class NetconfImplActivator implements BundleActivator {
27 private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
29 private NetconfOperationServiceFactoryTracker factoriesTracker;
30 private DefaultCommitNotificationProducer commitNot;
31 private NetconfServerDispatcher dispatch;
32 private NioEventLoopGroup eventLoopGroup;
33 private HashedWheelTimer timer;
36 public void start(final BundleContext context) throws Exception {
37 InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context,
38 "TCP is not configured, netconf not available.", false);
40 NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
41 factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
42 factoriesTracker.open();
44 SessionIdProvider idProvider = new SessionIdProvider();
45 timer = new HashedWheelTimer();
46 NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
47 timer, factoriesListener, idProvider);
49 commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
51 NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
52 factoriesListener, commitNot, idProvider);
54 eventLoopGroup = new NioEventLoopGroup();
56 NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
57 serverNegotiatorFactory, listenerFactory);
58 dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
60 logger.info("Starting TCP netconf server at {}", address);
61 dispatch.createServer(address);
66 public void stop(final BundleContext context) throws Exception {
67 logger.info("Shutting down netconf because YangStoreService service was removed");
70 eventLoopGroup.shutdownGracefully();