Bug 3135 - Fixed support for InterestListener
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / NotificationBrokerImplModule.java
index 72231d17d1b0b98b77bbdaedfbc8cc33b2cd07b1..cabdd15513e3dd89144029c3b515c2d1ed80dbce 100644 (file)
@@ -1,48 +1,74 @@
-/**
-* Generated file
-
-* Generated from: yang module name: opendaylight-sal-binding-broker-impl  yang module local name: binding-notification-broker
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Wed Nov 20 17:33:01 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.config.yang.md.sal.binding.impl;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-
-import org.opendaylight.controller.sal.binding.impl.NotificationBrokerImpl;
-
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners;
+import org.opendaylight.controller.md.sal.binding.compat.HydrogenNotificationBrokerImpl;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
+import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
+import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
 
 /**
 *
 */
-public final class NotificationBrokerImplModule extends org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractNotificationBrokerImplModule
-{
+public final class NotificationBrokerImplModule extends
+        org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractNotificationBrokerImplModule {
 
-    public NotificationBrokerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+    public NotificationBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+            final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public NotificationBrokerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, NotificationBrokerImplModule oldModule, java.lang.AutoCloseable oldInstance) {
+    public NotificationBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+            final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+            final NotificationBrokerImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    public void validate(){
+    public void validate() {
         super.validate();
         // Add custom validation for module attributes here.
     }
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        ExecutorService executor = Executors.newFixedThreadPool(5);
-        ListeningExecutorService listeningExecutor = MoreExecutors.listeningDecorator(executor);
-        NotificationBrokerImpl broker = new NotificationBrokerImpl(listeningExecutor);
-        return broker;
+
+        final NotificationPublishService notificationPublishService = getNotificationPublishAdapterDependency();
+        final NotificationService notificationService = getNotificationAdapterDependency();
+
+        if(notificationPublishService != null & notificationService != null) {
+            return createHeliumAdapter(notificationPublishService,notificationService);
+        }
+
+        /*
+         *  FIXME: Switch to new broker (which has different threading model)
+         *  once this change is communicated with downstream users or
+         *  we will have adapter implementation which will honor Helium
+         *  threading model for notifications.
+         */
+        return new HydrogenNotificationBrokerImpl(SingletonHolder.getDefaultNotificationExecutor());
+    }
+
+    private static AutoCloseable createHeliumAdapter(final NotificationPublishService publishService,
+            final NotificationService listenService) {
+        if(publishService instanceof BindingDOMNotificationPublishServiceAdapter) {
+            final BindingDOMNotificationPublishServiceAdapter casted = (BindingDOMNotificationPublishServiceAdapter) publishService;
+            final DOMNotificationPublishService domService = casted.getDomPublishService();
+            if(domService instanceof DOMNotificationSubscriptionListenerRegistry) {
+                final DOMNotificationSubscriptionListenerRegistry subsRegistry = (DOMNotificationSubscriptionListenerRegistry) domService;
+                return new HeliumNotificationProviderServiceWithInterestListeners(publishService, listenService, casted.getCodecRegistry(), subsRegistry);
+            }
+        }
+        return new HeliumNotificationProviderServiceAdapter(publishService, listenService);
     }
 }