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.controller.netconf.notifications.impl.osgi;
11 import com.google.common.collect.Sets;
12 import java.util.Collections;
13 import java.util.Dictionary;
14 import java.util.Hashtable;
16 import org.opendaylight.controller.config.util.capability.BasicCapability;
17 import org.opendaylight.controller.config.util.capability.Capability;
18 import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
19 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
20 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
21 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
22 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
23 import org.opendaylight.controller.netconf.notifications.NetconfNotification;
24 import org.opendaylight.controller.netconf.notifications.NetconfNotificationCollector;
25 import org.opendaylight.controller.netconf.notifications.impl.NetconfNotificationManager;
26 import org.opendaylight.controller.netconf.notifications.impl.ops.CreateSubscription;
27 import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
28 import org.osgi.framework.BundleActivator;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.ServiceRegistration;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class Activator implements BundleActivator {
36 private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
38 private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
39 private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
40 private NetconfNotificationManager netconfNotificationManager;
43 public void start(final BundleContext context) throws Exception {
44 netconfNotificationManager = new NetconfNotificationManager();
45 netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
47 final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
49 private final Set<Capability> capabilities = Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
52 public Set<Capability> getCapabilities() {
57 public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
58 listener.onCapabilitiesChanged(capabilities, Collections.<Capability>emptySet());
59 return new AutoCloseable() {
62 listener.onCapabilitiesChanged(Collections.<Capability>emptySet(), capabilities);
68 public NetconfOperationService createService(final String netconfSessionIdForReporting) {
69 return new NetconfOperationService() {
71 private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
74 public Set<NetconfOperation> getNetconfOperations() {
75 return Sets.<NetconfOperation>newHashSet(
76 new Get(netconfSessionIdForReporting, netconfNotificationManager),
82 createSubscription.close();
88 final Dictionary<String, String> properties = new Hashtable<>();
89 properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
90 operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
94 public void stop(final BundleContext context) throws Exception {
95 if(netconfNotificationCollectorServiceRegistration != null) {
96 netconfNotificationCollectorServiceRegistration.unregister();
97 netconfNotificationCollectorServiceRegistration = null;
99 if (netconfNotificationManager != null) {
100 netconfNotificationManager.close();
102 if (operationaServiceRegistration != null) {
103 operationaServiceRegistration.unregister();
104 operationaServiceRegistration = null;