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 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;
24 import javax.net.ssl.SSLContext;
25 import java.lang.management.ManagementFactory;
26 import java.net.InetSocketAddress;
28 public class NetconfImplActivator implements BundleActivator {
30 private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
32 private NetconfOperationServiceFactoryTracker factoriesTracker;
33 private DefaultCommitNotificationProducer commitNot;
34 private NetconfServerDispatcher dispatch;
35 private NioEventLoopGroup eventLoopGroup;
36 private HashedWheelTimer timer;
39 public void start(final BundleContext context) throws Exception {
40 InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfAddress(context, "TCP is not configured, netconf not available.");
42 NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
43 factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
44 factoriesTracker.open();
46 SessionIdProvider idProvider = new SessionIdProvider();
47 timer = new HashedWheelTimer();
48 NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
49 timer, factoriesListener, idProvider);
51 commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
53 NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
54 factoriesListener, commitNot, idProvider);
56 eventLoopGroup = new NioEventLoopGroup();
58 NetconfServerDispatcher.ServerSslChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerSslChannelInitializer(
59 Optional.<SSLContext>absent(), serverNegotiatorFactory, listenerFactory);
60 dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
62 logger.info("Starting TCP netconf server at {}", address);
63 dispatch.createServer(address);
68 public void stop(final BundleContext context) throws Exception {
69 logger.info("Shutting down netconf because YangStoreService service was removed");
72 eventLoopGroup.shutdownGracefully();