1 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601;
3 import io.fd.honeycomb.v3po.notification.NotificationCollector;
4 import io.fd.honeycomb.v3po.notification.NotificationProducer;
5 import io.fd.honeycomb.v3po.notification.impl.HoneycombNotificationCollector;
6 import io.fd.honeycomb.v3po.notification.impl.NotificationProducerRegistry;
7 import io.fd.honeycomb.v3po.notification.impl.NotificationProducerTracker;
8 import java.util.Collection;
9 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
10 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
11 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
12 import org.opendaylight.yangtools.yang.binding.Notification;
14 public class HoneycombNotificationManagerModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.AbstractHoneycombNotificationManagerModule {
16 public HoneycombNotificationManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
17 super(identifier, dependencyResolver);
20 public HoneycombNotificationManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601.HoneycombNotificationManagerModule oldModule, java.lang.AutoCloseable oldInstance) {
21 super(identifier, dependencyResolver, oldModule, oldInstance);
25 public void customValidation() {
26 // add custom validation form module attributes here.
30 public java.lang.AutoCloseable createInstance() {
31 final DOMNotificationRouter notificationRouter = getDomNotificationServiceDependency();
33 // Create the registry to keep track of what's registered
34 final NotificationProducerRegistry notificationProducerRegistry =
35 new NotificationProducerRegistry(getNotificationProducersDependency());
37 // Create BA version of notification service (implementation is free from ODL)
38 final BindingToNormalizedNodeCodec codec = getRuntimeMappingCodecDependency();
39 final BindingDOMNotificationPublishServiceAdapter bindingDOMNotificationPublishServiceAdapter =
40 new BindingDOMNotificationPublishServiceAdapter(codec, notificationRouter);
42 // Create Collector on top of BA notification service and registry
43 final HoneycombNotificationCollector honeycombNotificationCollector =
44 new HoneycombNotificationCollector(bindingDOMNotificationPublishServiceAdapter, notificationProducerRegistry);
46 // Create tracker, responsible for starting and stopping registered notification producers whenever necessary
47 final NotificationProducerTracker notificationProducerTracker =
48 new NotificationProducerTracker(notificationProducerRegistry, honeycombNotificationCollector,
51 // TODO wire with restconf
52 // DOMNotificationService is already provided by DOMBroker injected into RESTCONF, however RESTCONF
53 // only supports data-change notification, nothing else. So currently its impossible.
55 return new CloseableCollector(honeycombNotificationCollector, () -> {
56 // Close all resources in order opposite to instantiation
57 notificationProducerTracker.close();
58 honeycombNotificationCollector.close();
59 bindingDOMNotificationPublishServiceAdapter.close();
60 // notificationProducerRegistry; no close, it's just a collection
65 * NotificationCollector wrapper in which close method execution can be injected
67 private class CloseableCollector implements AutoCloseable, NotificationCollector, NotificationProducer {
69 private final HoneycombNotificationCollector honeycombNotificationCollector;
70 private final AutoCloseable resources;
72 CloseableCollector(final HoneycombNotificationCollector honeycombNotificationCollector,
73 final AutoCloseable resources) {
74 this.honeycombNotificationCollector = honeycombNotificationCollector;
75 this.resources = resources;
79 public void close() throws Exception {
84 public void onNotification(final Notification notification) {
85 honeycombNotificationCollector.onNotification(notification);
89 public Collection<Class<? extends Notification>> getNotificationTypes() {
90 return honeycombNotificationCollector.getNotificationTypes();