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.util.NetconfConstants;
19 import org.opendaylight.controller.netconf.mapping.api.Capability;
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;
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() {
46 public NetconfOperationService createService(final String netconfSessionIdForReporting) {
47 return new NetconfOperationService() {
49 private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
52 public Set<Capability> getCapabilities() {
53 return Collections.<Capability>singleton(new NotificationsCapability());
57 public Set<NetconfOperation> getNetconfOperations() {
58 return Sets.<NetconfOperation>newHashSet(
59 new Get(netconfSessionIdForReporting, netconfNotificationManager),
65 createSubscription.close();
71 Dictionary<String, String> properties = new Hashtable<>();
72 properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
73 operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
78 public void stop(final BundleContext context) throws Exception {
79 if(netconfNotificationCollectorServiceRegistration != null) {
80 netconfNotificationCollectorServiceRegistration.unregister();
81 netconfNotificationCollectorServiceRegistration = null;
83 if (netconfNotificationManager != null) {
84 netconfNotificationManager.close();
86 if (operationaServiceRegistration != null) {
87 operationaServiceRegistration.unregister();
88 operationaServiceRegistration = null;
92 private class NotificationsCapability implements Capability {
94 public String getCapabilityUri() {
95 return NetconfNotification.NOTIFICATION_NAMESPACE;
99 public Optional<String> getModuleNamespace() {
100 return Optional.absent();
104 public Optional<String> getModuleName() {
105 return Optional.absent();
109 public Optional<String> getRevision() {
110 return Optional.absent();
114 public Optional<String> getCapabilitySchema() {
115 return Optional.absent();
119 public Collection<String> getLocation() {
120 return Collections.emptyList();