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, "TCP is not configured, netconf not available.");
39 NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
40 factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
41 factoriesTracker.open();
43 SessionIdProvider idProvider = new SessionIdProvider();
44 timer = new HashedWheelTimer();
45 NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
46 timer, factoriesListener, idProvider);
48 commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
50 NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
51 factoriesListener, commitNot, idProvider);
53 eventLoopGroup = new NioEventLoopGroup();
55 NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
56 serverNegotiatorFactory, listenerFactory);
57 dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
59 logger.info("Starting TCP netconf server at {}", address);
60 dispatch.createServer(address);
65 public void stop(final BundleContext context) throws Exception {
66 logger.info("Shutting down netconf because YangStoreService service was removed");
69 eventLoopGroup.shutdownGracefully();