2 * Copyright (c) 2015 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
9 package org.opendaylight.netconf.notifications.impl.osgi;
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.collect.Sets;
13 import java.util.Collections;
14 import java.util.Dictionary;
15 import java.util.Hashtable;
17 import org.opendaylight.controller.config.util.capability.BasicCapability;
18 import org.opendaylight.controller.config.util.capability.Capability;
19 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
20 import org.opendaylight.netconf.api.util.NetconfConstants;
21 import org.opendaylight.netconf.mapping.api.NetconfOperation;
22 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
23 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
24 import org.opendaylight.netconf.notifications.NetconfNotification;
25 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
26 import org.opendaylight.netconf.notifications.impl.NetconfNotificationManager;
27 import org.opendaylight.netconf.notifications.impl.ops.CreateSubscription;
28 import org.opendaylight.netconf.notifications.impl.ops.Get;
29 import org.osgi.framework.BundleActivator;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.ServiceRegistration;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class Activator implements BundleActivator {
37 private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
39 private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
40 private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
41 private NetconfNotificationManager netconfNotificationManager;
44 public void start(final BundleContext context) throws Exception {
45 netconfNotificationManager = new NetconfNotificationManager();
46 // Add properties to autowire with netconf-impl instance for cfg subsystem
47 final Dictionary<String, String> props = new Hashtable<>();
48 props.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_NOTIFICATION);
49 netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
51 final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
53 private final Set<Capability> capabilities = Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
56 public Set<Capability> getCapabilities() {
61 public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
62 listener.onCapabilitiesChanged(capabilities, Collections.<Capability>emptySet());
63 return new AutoCloseable() {
66 listener.onCapabilitiesChanged(Collections.<Capability>emptySet(), capabilities);
72 public NetconfOperationService createService(final String netconfSessionIdForReporting) {
73 return new NetconfOperationService() {
75 private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
78 public Set<NetconfOperation> getNetconfOperations() {
79 return Sets.<NetconfOperation>newHashSet(
80 new Get(netconfSessionIdForReporting, netconfNotificationManager),
86 createSubscription.close();
92 final Dictionary<String, String> properties = new Hashtable<>();
93 properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
94 operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
98 public void stop(final BundleContext context) throws Exception {
99 if(netconfNotificationCollectorServiceRegistration != null) {
100 netconfNotificationCollectorServiceRegistration.unregister();
101 netconfNotificationCollectorServiceRegistration = null;
103 if (netconfNotificationManager != null) {
104 netconfNotificationManager.close();
106 if (operationaServiceRegistration != null) {
107 operationaServiceRegistration.unregister();
108 operationaServiceRegistration = null;
113 NetconfNotificationManager getNetconfNotificationManager() {
114 return netconfNotificationManager;