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 2017/11/21 17:44:24 UTC

[05/11] aries-jax-rs-whiteboard git commit: Use effects

Use effects


Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/02898c9b
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/02898c9b
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/02898c9b

Branch: refs/heads/master
Commit: 02898c9bb2be78a3d31463425c59aa40d8dae7e0
Parents: 24467b3
Author: Carlos Sierra <cs...@apache.org>
Authored: Mon Nov 20 18:00:55 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Nov 20 18:01:31 2017 +0100

----------------------------------------------------------------------
 .../activator/CXFJaxRsBundleActivator.java      | 13 +++---
 .../aries/jax/rs/whiteboard/internal/Utils.java |  7 ----
 .../jax/rs/whiteboard/internal/Whiteboard.java  | 42 +++++++-------------
 3 files changed, 20 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/02898c9b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
index 3a21e20..c80b463 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
@@ -24,7 +24,6 @@ import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.ext.RuntimeDelegate;
 
 import org.apache.aries.jax.rs.whiteboard.internal.ClientBuilderFactory;
-import org.apache.aries.jax.rs.whiteboard.internal.Utils;
 import org.apache.aries.jax.rs.whiteboard.internal.Whiteboard;
 import org.apache.aries.osgi.functional.OSGi;
 import org.apache.aries.osgi.functional.OSGiResult;
@@ -40,7 +39,6 @@ import static org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.createWhite
 import static org.apache.aries.osgi.functional.OSGi.all;
 import static org.apache.aries.osgi.functional.OSGi.configurations;
 import static org.apache.aries.osgi.functional.OSGi.just;
-import static org.apache.aries.osgi.functional.OSGi.onClose;
 import static org.apache.aries.osgi.functional.OSGi.register;
 
 public class CXFJaxRsBundleActivator implements BundleActivator {
@@ -106,11 +104,12 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
     private static OSGi<?> runWhiteboard(
         BundleContext bundleContext, Dictionary<String, ?> configuration) {
 
-        Whiteboard whiteboard = createWhiteboard(bundleContext, configuration);
-
-        whiteboard.start();
-
-        return onClose(whiteboard::stop);
+        return just(
+            createWhiteboard(bundleContext, configuration)
+        ).effects(
+            Whiteboard::start,
+            Whiteboard::stop
+        );
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/02898c9b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
index c7b271b..014eabb 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
@@ -186,13 +186,6 @@ public class Utils {
         );
     }
 
-    public static void unregisterEndpoint(
-        CXFJaxRsServiceRegistrator registrator,
-        ResourceProvider resourceProvider) {
-
-        registrator.remove(resourceProvider);
-    }
-
     public static void updateProperty(
         ServiceRegistration<?> serviceRegistration, String key, Object value) {
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/02898c9b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
----------------------------------------------------------------------
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 df5dd13..c0e36ae 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
@@ -80,6 +80,7 @@ import static org.apache.aries.jax.rs.whiteboard.internal.Utils.service;
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.serviceObjects;
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.updateProperty;
 import static org.apache.aries.osgi.functional.OSGi.all;
+import static org.apache.aries.osgi.functional.OSGi.effects;
 import static org.apache.aries.osgi.functional.OSGi.just;
 import static org.apache.aries.osgi.functional.OSGi.nothing;
 import static org.apache.aries.osgi.functional.OSGi.onClose;
@@ -329,8 +330,7 @@ public class Whiteboard {
             highest(
                 serviceReferences(
                     CXFJaxRsServiceRegistrator.class,
-                    String.format(
-                        "(%s=%s)", JAX_RS_NAME, DEFAULT_NAME)
+                    String.format("(%s=%s)", JAX_RS_NAME, DEFAULT_NAME)
                 ).filter(
                     new TargetFilter<>(_runtimeReference)
                 )
@@ -431,8 +431,8 @@ public class Whiteboard {
             properties));
     }
 
-    private ServiceRegistration<?>
-        registerJaxRSServiceRuntime(Map<String, Object> properties) {
+    private ServiceRegistration<?> registerJaxRSServiceRuntime(
+        Map<String, Object> properties) {
 
         properties.putIfAbsent(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
 
@@ -509,18 +509,13 @@ public class Whiteboard {
                 _runtime::addNotGettableExtension,
                 _runtime::removeNotGettableExtension
             ).recoverWith(
-                (t, e) -> {
-                    _runtime.addErroredExtension(
-                        t.getCachingServiceReference());
-
-                    return
-                        onClose(
-                            () -> _runtime.removeErroredExtension(
-                                t.getCachingServiceReference())
-                        ).then(
-                            nothing()
-                        );
-                }
+                (t, e) ->
+                    just(t.getCachingServiceReference()).
+                    effects(
+                        _runtime::addErroredExtension,
+                        _runtime::removeErroredExtension
+                    ).
+                    then(nothing())
             ).effects(
                 registrator::addProvider,
                 registrator::removeProvider
@@ -547,9 +542,9 @@ public class Whiteboard {
             applicationReference.getProperty(JAX_RS_EXTENSION_SELECT));
 
         if (extensionDependencies.length > 0) {
-            program = just(0).effects(
-                __ -> _runtime.addDependentApplication(applicationReference),
-                __ -> _runtime.removeDependentApplication(applicationReference)
+            program = effects(
+                () -> _runtime.addDependentApplication(applicationReference),
+                () -> _runtime.removeDependentApplication(applicationReference)
             ).then(program);
         }
         else {
@@ -781,15 +776,6 @@ public class Whiteboard {
         return register(Servlet.class, cxfNonSpringServlet, properties);
     }
 
-    private static <T> OSGi<ResourceProvider> registerEndpoint(
-        CXFJaxRsServiceRegistrator registrator,
-        ResourceProvider resourceProvider) {
-
-        registrator.add(resourceProvider);
-
-        return just(resourceProvider);
-    }
-
     private static boolean signalsValidInterface(
         CachingServiceReference<Object> serviceReference) {