Merge "(Bug 2035) - Increasing default Akka config for auto-down of unreachable nodes...
[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.Hashtable;
16 import java.util.Set;
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;
29
30 public class Activator implements BundleActivator {
31
32     private ServiceRegistration<NetconfNotificationCollector> netconfNotificationCollectorServiceRegistration;
33     private ServiceRegistration<NetconfOperationServiceFactory> operationaServiceRegistration;
34     private NetconfNotificationManager netconfNotificationManager;
35
36     @Override
37     public void start(final BundleContext context) throws Exception {
38         netconfNotificationManager = new NetconfNotificationManager();
39         netconfNotificationCollectorServiceRegistration = context.registerService(NetconfNotificationCollector.class, netconfNotificationManager, new Hashtable<String, Object>());
40
41         final NetconfOperationServiceFactory netconfOperationServiceFactory = new NetconfOperationServiceFactory() {
42
43             @Override
44             public NetconfOperationService createService(final String netconfSessionIdForReporting) {
45                 return new NetconfOperationService() {
46
47                     private final CreateSubscription createSubscription = new CreateSubscription(netconfSessionIdForReporting, netconfNotificationManager);
48
49                     @Override
50                     public Set<Capability> getCapabilities() {
51                         return Collections.<Capability>singleton(new NotificationsCapability());
52                     }
53
54                     @Override
55                     public Set<NetconfOperation> getNetconfOperations() {
56                         return Sets.<NetconfOperation>newHashSet(
57                                 new Get(netconfSessionIdForReporting, netconfNotificationManager),
58                                 createSubscription);
59                     }
60
61                     @Override
62                     public void close() {
63                         createSubscription.close();
64                     }
65                 };
66             }
67         };
68
69         operationaServiceRegistration = context.registerService(NetconfOperationServiceFactory.class, netconfOperationServiceFactory, new Hashtable<String, Object>());
70
71     }
72
73     @Override
74     public void stop(final BundleContext context) throws Exception {
75         if(netconfNotificationCollectorServiceRegistration != null) {
76             netconfNotificationCollectorServiceRegistration.unregister();
77             netconfNotificationCollectorServiceRegistration = null;
78         }
79         if (netconfNotificationManager != null) {
80             netconfNotificationManager.close();
81         }
82         if (operationaServiceRegistration != null) {
83             operationaServiceRegistration.unregister();
84             operationaServiceRegistration = null;
85         }
86     }
87
88     private class NotificationsCapability implements Capability {
89         @Override
90         public String getCapabilityUri() {
91             return NetconfNotification.NOTIFICATION_NAMESPACE;
92         }
93
94         @Override
95         public Optional<String> getModuleNamespace() {
96             return Optional.absent();
97         }
98
99         @Override
100         public Optional<String> getModuleName() {
101             return Optional.absent();
102         }
103
104         @Override
105         public Optional<String> getRevision() {
106             return Optional.absent();
107         }
108
109         @Override
110         public Optional<String> getCapabilitySchema() {
111             return Optional.absent();
112         }
113
114         @Override
115         public Collection<String> getLocation() {
116             return Collections.emptyList();
117         }
118     }
119 }