You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2019/09/11 13:15:45 UTC

[aries-jax-rs-whiteboard] 04/10: [ARIES-1929] Add support for a ready service for applications

This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git

commit bdd962c77d86dd5522077cf657e1977bf18300ef
Author: Carlos Sierra <cs...@apache.org>
AuthorDate: Fri Aug 30 15:12:37 2019 +0200

    [ARIES-1929] Add support for a ready service for applications
    
    It is treated as a raw dependency for the application. It allows to
    defer application tracking until the ready service is present so the
    rest of the components can be registered before the application, thus
    minimizing the number of application rewires.
---
 .../jax/rs/whiteboard/internal/Whiteboard.java     | 67 ++++++++++++++++++++--
 1 file changed, 62 insertions(+), 5 deletions(-)

diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
index 32d90ca..db36c32 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
@@ -493,11 +493,11 @@ public class Whiteboard {
 
         OSGi<CachingServiceReference<Application>> applicationsForWhiteboard =
             waitForApplicationDependencies(
-                onlyValid(
-                    applications,
-                    _runtime::addInvalidApplication,
-                    _runtime::removeInvalidApplication)
-                );
+                waitForReadyService(
+                    onlyValid(
+                        applications,
+                        _runtime::addInvalidApplication,
+                        _runtime::removeInvalidApplication)));
 
         OSGi<ApplicationReferenceWithContext> applicationsWithContext =
             waitForApplicationContext(
@@ -742,6 +742,24 @@ public class Whiteboard {
                 filter(this::matchesWhiteboard);
     }
 
+    private String getApplicationReadyServiceFilter(
+        CachingServiceReference<Application> reference) {
+
+        Object applicationReadyServiceFilter =
+            _configurationMap.get("application.ready.service.filter");
+
+        if (applicationReadyServiceFilter == null) {
+            applicationReadyServiceFilter =
+                reference.getProperty("application.ready.service.filter");
+        }
+
+        if (applicationReadyServiceFilter != null) {
+            return String.valueOf(applicationReadyServiceFilter);
+        }
+
+        return null;
+    }
+
     private OSGi<CachingServiceReference<Object>> getResourcesForWhiteboard() {
         return serviceReferences(_resourcesFilter.toString()).
             filter(this::matchesWhiteboard);
@@ -1086,6 +1104,45 @@ public class Whiteboard {
         });
     }
 
+    private OSGi<CachingServiceReference<Application>> waitForReadyService(
+        OSGi<CachingServiceReference<Application>> program) {
+
+        return program.flatMap(reference -> {
+            String applicationReadyServiceFilter =
+                getApplicationReadyServiceFilter(reference);
+
+            if (applicationReadyServiceFilter != null) {
+                return effects(
+                    () -> _runtime.addDependentApplication(reference),
+                    () -> _runtime.removeDependentApplication(reference)
+                ).then(
+                    once(serviceReferences(applicationReadyServiceFilter)).
+                        effects(
+                            ifDebugEnabled(
+                                _log,
+                                () ->
+                                    "Ready service for " + reference +
+                                        " has been tracked"),
+                            ifDebugEnabled(
+                                _log,
+                                () -> "Ready service for " + reference +
+                                    " is gone")
+                        ).
+                        then(just(reference).
+                            effects(
+                                __ -> {},
+                                __ -> _runtime.addDependentApplication(
+                                    reference)))
+                ).effects(
+                    _runtime::removeDependentApplication,
+                    __ -> {}
+                );
+            }
+
+            return just(reference);
+        });
+    }
+
     private OSGi<?> waitForExtensionDependencies(
         CachingServiceReference<?> reference,
         CachingServiceReference<CxfJaxrsServiceRegistrator>