xsql should pull junit directly
[controller.git] / opendaylight / netconf / netconf-notifications-impl / src / main / java / org / opendaylight / controller / netconf / notifications / impl / osgi / Activator.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.notifications.impl.osgi;
10
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;
17 import java.util.Set;
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;
31
32 public class Activator implements BundleActivator {
33
34     private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
35     private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
36     private NetconfNotificationManager netconfNotificationManager;
37
38     @Override
39     public void start(final BundleContext context) throws Exception {
40         netconfNotificationManager = new NetconfNotificationManager();
41         netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
42
43         final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
44
45             @Override
46             public NetconfOperationService createService(final String netconfSessionIdForReporting) {
47                 return new NetconfOperationService() {
48
49                     private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
50
51                     @Override
52                     public Set<Capability> getCapabilities() {
53                         return Collections.<Capability>singleton(new NotificationsCapability());
54                     }
55
56                     @Override
57                     public Set<NetconfOperation> getNetconfOperations() {
58                         return Sets.<NetconfOperation>newHashSet(
59                                 new Get(netconfSessionIdForReporting, netconfNotificationManager),
60                                 createSubscription);
61                     }
62
63                     @Override
64                     public void close() {
65                         createSubscription.close();
66                     }
67                 };
68             }
69         };
70
71         Dictionary<String, String> properties = new Hashtable<>();
72         properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
73         operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, properties);
74
75     }
76
77     @Override
78     public void stop(final BundleContext context) throws Exception {
79         if(netconfNotificationCollectorServiceRegistration != null) {
80             netconfNotificationCollectorServiceRegistration.unregister();
81             netconfNotificationCollectorServiceRegistration = null;
82         }
83         if (netconfNotificationManager != null) {
84             netconfNotificationManager.close();
85         }
86         if (operationaServiceRegistration != null) {
87             operationaServiceRegistration.unregister();
88             operationaServiceRegistration = null;
89         }
90     }
91
92     private class NotificationsCapability implements Capability {
93         @Override
94         public String getCapabilityUri() {
95             return NetconfNotification.NOTIFICATION_NAMESPACE;
96         }
97
98         @Override
99         public Optional<String> getModuleNamespace() {
100             return Optional.absent();
101         }
102
103         @Override
104         public Optional<String> getModuleName() {
105             return Optional.absent();
106         }
107
108         @Override
109         public Optional<String> getRevision() {
110             return Optional.absent();
111         }
112
113         @Override
114         public Optional<String> getCapabilitySchema() {
115             return Optional.absent();
116         }
117
118         @Override
119         public Collection<String> getLocation() {
120             return Collections.emptyList();
121         }
122     }
123 }