+
+ 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 (listenService instanceof BindingDOMNotificationServiceAdapter
+ && publishService instanceof BindingDOMNotificationPublishServiceAdapter) {
+ final BindingDOMNotificationPublishServiceAdapter castedPublish =
+ (BindingDOMNotificationPublishServiceAdapter) publishService;
+ final BindingDOMNotificationServiceAdapter castedListen =
+ (BindingDOMNotificationServiceAdapter) listenService;
+ final DOMNotificationPublishService domPublishService = castedPublish.getDomPublishService();
+ if (domPublishService instanceof DOMNotificationSubscriptionListenerRegistry) {
+ final DOMNotificationSubscriptionListenerRegistry subsRegistry =
+ (DOMNotificationSubscriptionListenerRegistry) domPublishService;
+ return new HeliumNotificationProviderServiceWithInterestListeners(castedPublish, castedListen,
+ subsRegistry);
+ }
+ }
+ return new HeliumNotificationProviderServiceAdapter(publishService, listenService);