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.Hashtable;
17 import org.opendaylight.controller.netconf.mapping.api.Capability;
18 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
19 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
20 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
21 import org.opendaylight.controller.netconf.notifications.NetconfNotification;
22 import org.opendaylight.controller.netconf.notifications.NetconfNotificationCollector;
23 import org.opendaylight.controller.netconf.notifications.impl.NetconfNotificationManager;
24 import org.opendaylight.controller.netconf.notifications.impl.ops.CreateSubscription;
25 import org.opendaylight.controller.netconf.notifications.impl.ops.Get;
26 import org.osgi.framework.BundleActivator;
27 import org.osgi.framework.BundleContext;
28 import org.osgi.framework.ServiceRegistration;
30 public class Activator implements BundleActivator {
32 private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
33 private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
34 private NetconfNotificationManager netconfNotificationManager;
37 public void start(final BundleContext context) throws Exception {
38 netconfNotificationManager = new NetconfNotificationManager();
39 netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
41 final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
44 public NetconfOperationService createService(final String netconfSessionIdForReporting) {
45 return new NetconfOperationService() {
47 private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
50 public Set<Capability> getCapabilities() {
51 return Collections.<Capability>singleton(new NotificationsCapability());
55 public Set<NetconfOperation> getNetconfOperations() {
56 return Sets.<NetconfOperation>newHashSet(
57 new Get(netconfSessionIdForReporting, netconfNotificationManager),
63 createSubscription.close();
69 operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, new Hashtable<String, Object>());
74 public void stop(final BundleContext context) throws Exception {
75 if(netconfNotificationCollectorServiceRegistration != null) {
76 netconfNotificationCollectorServiceRegistration.unregister();
77 netconfNotificationCollectorServiceRegistration = null;
79 if (netconfNotificationManager != null) {
80 netconfNotificationManager.close();
82 if (operationaServiceRegistration != null) {
83 operationaServiceRegistration.unregister();
84 operationaServiceRegistration = null;
88 private class NotificationsCapability implements Capability {
90 public String getCapabilityUri() {
91 return NetconfNotification.NOTIFICATION_NAMESPACE;
95 public Optional<String> getModuleNamespace() {
96 return Optional.absent();
100 public Optional<String> getModuleName() {
101 return Optional.absent();
105 public Optional<String> getRevision() {
106 return Optional.absent();
110 public Optional<String> getCapabilitySchema() {
111 return Optional.absent();
115 public Collection<String> getLocation() {
116 return Collections.emptyList();