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.base.Optional;
12 import com.google.common.collect.Sets;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.Dictionary;
16 import java.util.Hashtable;
18 import org.opendaylight.controller.netconf.api.Capability;
19 import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
20 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
21 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
22 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
23 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
24 import org.opendaylight.controller.netconf.notifications.NetconfNotification;
25 import org.opendaylight.controller.netconf.notifications.NetconfNotificationCollector;
26 import org.opendaylight.controller.netconf.notifications.impl.NetconfNotificationManager;
27 import org.opendaylight.controller.netconf.notifications.impl.ops.CreateSubscription;
28 import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
29 import org.osgi.framework.BundleActivator;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.ServiceRegistration;
33 public class Activator implements BundleActivator {
35 private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
36 private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
37 private NetconfNotificationManager netconfNotificationManager;
40 public void start(final BundleContext context) throws Exception {
41 netconfNotificationManager = new NetconfNotificationManager();
42 netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
44 final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
46 private final Set<Capability> capabilities = Collections.<Capability>singleton(new NotificationsCapability());
49 public Set<Capability> getCapabilities() {
54 public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
55 listener.onCapabilitiesAdded(capabilities);
56 return new AutoCloseable() {
59 listener.onCapabilitiesRemoved(capabilities);
65 public NetconfOperationService createService(final String netconfSessionIdForReporting) {
66 return new NetconfOperationService() {
68 private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
72 public Set<NetconfOperation> getNetconfOperations() {
73 return Sets.<NetconfOperation>newHashSet(
74 new Get(netconfSessionIdForReporting, netconfNotificationManager),
80 createSubscription.close();
86 final Dictionary<String, String> properties = new Hashtable<>();
87 properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
88 operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
93 public void stop(final BundleContext context) throws Exception {
94 if(netconfNotificationCollectorServiceRegistration != null) {
95 netconfNotificationCollectorServiceRegistration.unregister();
96 netconfNotificationCollectorServiceRegistration = null;
98 if (netconfNotificationManager != null) {
99 netconfNotificationManager.close();
101 if (operationaServiceRegistration != null) {
102 operationaServiceRegistration.unregister();
103 operationaServiceRegistration = null;
107 private class NotificationsCapability implements Capability {
109 public String getCapabilityUri() {
110 return NetconfNotification.NOTIFICATION_NAMESPACE;
114 public Optional<String> getModuleNamespace() {
115 return Optional.absent();
119 public Optional<String> getModuleName() {
120 return Optional.absent();
124 public Optional<String> getRevision() {
125 return Optional.absent();
129 public Optional<String> getCapabilitySchema() {
130 return Optional.absent();
134 public Collection<String> getLocation() {
135 return Collections.emptyList();