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.netconf.api.Capability;
17 import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
18 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
19 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
20 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
21 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
22 import org.opendaylight.controller.netconf.notifications.NetconfNotification;
23 import org.opendaylight.controller.netconf.notifications.NetconfNotificationCollector;
24 import org.opendaylight.controller.netconf.notifications.impl.NetconfNotificationManager;
25 import org.opendaylight.controller.netconf.notifications.impl.ops.CreateSubscription;
26 import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
27 import org.opendaylight.controller.netconf.util.capability.BasicCapability;
28 import org.osgi.framework.BundleActivator;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.ServiceRegistration;
32 public class Activator implements BundleActivator {
34 private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
35 private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
36 private NetconfNotificationManager netconfNotificationManager;
39 public void start(final BundleContext context) throws Exception {
40 netconfNotificationManager = new NetconfNotificationManager();
41 netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
43 final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
45 private final Set<Capability> capabilities = Collections.<Capability>singleton(new BasicCapability(NetconfNotification.NOTIFICATION_NAMESPACE));
48 public Set<Capability> getCapabilities() {
53 public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
54 listener.onCapabilitiesAdded(capabilities);
55 return new AutoCloseable() {
58 listener.onCapabilitiesRemoved(capabilities);
64 public NetconfOperationService createService(final String netconfSessionIdForReporting) {
65 return new NetconfOperationService() {
67 private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
71 public Set<NetconfOperation> getNetconfOperations() {
72 return Sets.<NetconfOperation>newHashSet(
73 new Get(netconfSessionIdForReporting, netconfNotificationManager),
79 createSubscription.close();
85 final Dictionary<String, String> properties = new Hashtable<>();
86 properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
87 operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
92 public void stop(final BundleContext context) throws Exception {
93 if(netconfNotificationCollectorServiceRegistration != null) {
94 netconfNotificationCollectorServiceRegistration.unregister();
95 netconfNotificationCollectorServiceRegistration = null;
97 if (netconfNotificationManager != null) {
98 netconfNotificationManager.close();
100 if (operationaServiceRegistration != null) {
101 operationaServiceRegistration.unregister();
102 operationaServiceRegistration = null;