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:42 UTC

[aries-jax-rs-whiteboard] 01/10: [ARIES-1929] Defer jaxrs registration initialization

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 a49649e9d88c1440f98b618ea9855de7da3ecddf
Author: Carlos Sierra <cs...@apache.org>
AuthorDate: Fri Aug 30 13:44:45 2019 +0200

    [ARIES-1929] Defer jaxrs registration initialization
    
    so it can use all the services and extensions present at the moment of
    the application registration, thus reducing the number of rewrites.
---
 .../jax/rs/whiteboard/internal/Whiteboard.java     |  4 ++-
 .../internal/cxf/CxfJaxrsServiceRegistrator.java   | 39 ++++++++--------------
 pom.xml                                            |  2 +-
 3 files changed, 18 insertions(+), 27 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 df4bfc4..4bf6ca9 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
@@ -719,7 +719,9 @@ public class Whiteboard {
             just(() -> new CxfJaxrsServiceRegistrator(
                     createBus(extensions), tuple, props.get())).
             effects(
-                __ -> {}, __ -> {}, CxfJaxrsServiceRegistrator::close,
+                __ -> {},
+                CxfJaxrsServiceRegistrator::enable,
+                CxfJaxrsServiceRegistrator::close,
                 __ -> {});
     }
 
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java
index d902ab0..6c780ad 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/cxf/CxfJaxrsServiceRegistrator.java
@@ -51,7 +51,6 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
 import org.apache.cxf.jaxrs.ext.ResourceContextProvider;
 import org.apache.cxf.jaxrs.impl.ConfigurableImpl;
-import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ApplicationInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -75,16 +74,9 @@ public class CxfJaxrsServiceRegistrator {
             ServiceTuple::getCachingServiceReference);
 
         _providers = new TreeSet<>(comparing);
-
-        rewire();
     }
 
     public synchronized void add(ResourceProvider resourceProvider) {
-
-        if (_closed) {
-            return;
-        }
-
         _services.add(resourceProvider);
 
         try {
@@ -98,10 +90,6 @@ public class CxfJaxrsServiceRegistrator {
     }
 
     public synchronized void addProvider(ServiceTuple<?> tuple) {
-        if (_closed) {
-            return;
-        }
-
         _providers.add(tuple);
 
         try {
@@ -115,12 +103,18 @@ public class CxfJaxrsServiceRegistrator {
 
     }
 
+    public void enable() {
+        _enabled = true;
+
+        rewire();
+    }
+
     public void close() {
-        if (_closed) {
+        if (!_enabled) {
             return;
         }
 
-        _closed = true;
+        _enabled = false;
 
         if (_server != null) {
             _server.destroy();
@@ -181,28 +175,23 @@ public class CxfJaxrsServiceRegistrator {
     }
 
     public synchronized void remove(ResourceProvider resourceProvider) {
-
-        if (_closed) {
-            return;
-        }
-
         _services.remove(resourceProvider);
 
         rewire();
     }
 
     public synchronized void removeProvider(ServiceTuple<?> tuple) {
-        if (_closed) {
-            return;
-        }
-
         _providers.remove(tuple);
 
         rewire();
     }
 
     @SuppressWarnings("serial")
-    protected synchronized void rewire() {
+    public synchronized void rewire() {
+        if (!_enabled) {
+            return;
+        }
+
         if (!_applicationTuple.isAvailable()) {
             _applicationTuple.dispose();
 
@@ -391,7 +380,7 @@ public class CxfJaxrsServiceRegistrator {
     private final Bus _bus;
     private final Collection<ServiceTuple<?>> _providers;
     private final Collection<ResourceProvider> _services = new ArrayList<>();
-    private volatile boolean _closed = false;
+    private volatile boolean _enabled = false;
     private JAXRSServerFactoryBean _jaxRsServerFactoryBean;
     private Map<String, Object> _properties;
     private Server _server;
diff --git a/pom.xml b/pom.xml
index 82923df..3eab6d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,7 +37,7 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <cxf.version>3.2.5</cxf.version>
         <bnd.version>4.2.0</bnd.version>
-        <dsl.version>1.2.1</dsl.version>
+        <dsl.version>1.2.2-SNAPSHOT</dsl.version>
     </properties>
 
     <scm>