cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [1/2] cxf git commit: Prototyping the code for using the configured Executor for the async calls based on the copy from the JAXWS client code
Date Fri, 04 Aug 2017 11:51:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 21197c8f9 -> d86a5597a


Prototyping the code for using the configured Executor for the async calls based on the copy
from the JAXWS client code


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a2aad4fc
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2aad4fc
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2aad4fc

Branch: refs/heads/master
Commit: a2aad4fcecfc390c7004fc5d806816d0a9e7257d
Parents: c26e8b9
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Aug 4 12:50:52 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 4 12:50:52 2017 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/AbstractClient.java | 31 ++++++++++++++++++++
 .../cxf/jaxrs/client/ClientProxyImpl.java       |  1 +
 .../org/apache/cxf/jaxrs/client/WebClient.java  |  1 +
 .../jaxrs/client/spec/ClientBuilderImpl.java    |  4 ++-
 .../cxf/jaxrs/client/spec/ClientImpl.java       |  6 +++-
 .../client/spec/InvocationBuilderImpl.java      |  2 +-
 6 files changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a2aad4fc/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index 57bcfd3..bafc59c 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -40,6 +40,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Logger;
 
@@ -104,6 +106,8 @@ import org.apache.cxf.transport.MessageObserver;
  *
  */
 public abstract class AbstractClient implements Client {
+    public static final String EXECUTOR_SERVICE_PROPERTY = "executorService";
+    
     protected static final String REQUEST_CONTEXT = "RequestContext";
     protected static final String RESPONSE_CONTEXT = "ResponseContext";
     protected static final String KEEP_CONDUIT_ALIVE = "KeepConduitAlive";
@@ -1068,6 +1072,33 @@ public abstract class AbstractClient implements Client {
         return exchange;
     }
 
+    protected void setAsyncMessageObserverIfNeeded(Exchange exchange) {
+        if (!exchange.isSynchronous()) {
+            ExecutorService executor = (ExecutorService)cfg.getRequestContext().get(EXECUTOR_SERVICE_PROPERTY);
+            if (executor != null) {
+                exchange.put(Executor.class, executor);
+                
+                final ClientMessageObserver observer = new ClientMessageObserver(cfg);
+                
+                exchange.put(MessageObserver.class, new MessageObserver() {
+                    public void onMessage(final Message message) {
+                        if (!message.getExchange()
+                            .containsKey(Executor.class.getName() + ".USING_SPECIFIED"))
{
+    
+                            executor.execute(new Runnable() {
+                                public void run() {
+                                    observer.onMessage(message);
+                                }
+                            });
+                        } else {
+                            observer.onMessage(message);
+                        }
+                    }
+                });
+            }
+        }
+    }
+
     protected void setContexts(Message message, Exchange exchange,
                                Map<String, Object> context, boolean proxy) {
         Map<String, Object> reqContext = null;

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2aad4fc/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index 3151c6f..6bb11fa 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -841,6 +841,7 @@ public class ClientProxyImpl extends AbstractClient implements
     protected void doInvokeAsync(OperationResourceInfo ori, Message outMessage,
                                  InvocationCallback<Object> asyncCallback) {
         outMessage.getExchange().setSynchronous(false);
+        setAsyncMessageObserverIfNeeded(outMessage.getExchange());
         JaxrsClientCallback<?> cb = new JaxrsClientCallback<Object>(asyncCallback,
             ori.getMethodToInvoke().getReturnType(), ori.getMethodToInvoke().getGenericReturnType());
         outMessage.getExchange().put(JaxrsClientCallback.class, cb);

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2aad4fc/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
index 38c579d..69e691e 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
@@ -959,6 +959,7 @@ public class WebClient extends AbstractClient {
                                   inAnns, respClass, outType, null, null);
 
         m.getExchange().setSynchronous(false);
+        setAsyncMessageObserverIfNeeded(m.getExchange());
         m.getExchange().put(JaxrsClientCallback.class, cb);
 
         doRunInterceptorChain(m);

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2aad4fc/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientBuilderImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientBuilderImpl.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientBuilderImpl.java
index ee02ef7..7c219b0 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientBuilderImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientBuilderImpl.java
@@ -35,6 +35,8 @@ import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Configuration;
 
+import org.apache.cxf.jaxrs.client.WebClient;
+
 public class ClientBuilderImpl extends ClientBuilder {
 
     private Configurable<ClientBuilder> configImpl;
@@ -153,7 +155,7 @@ public class ClientBuilderImpl extends ClientBuilder {
 
     @Override
     public ClientBuilder executorService(ExecutorService executorService) {
-        return configImpl.property("executorService", executorService);
+        return configImpl.property(WebClient.EXECUTOR_SERVICE_PROPERTY, executorService);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2aad4fc/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
index 983f3e6..36d9465 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
@@ -299,7 +299,11 @@ public class ClientImpl implements Client {
                 || tlsParams.getHostnameVerifier() != null) {
                 clientCfg.getHttpConduit().setTlsClientParameters(tlsParams);
             }
-
+            // Executor for the asynchronous calls
+            Object executorServiceProp = configProps.get(WebClient.EXECUTOR_SERVICE_PROPERTY);
+            if (executorServiceProp != null) {
+                clientCfg.getResponseContext().put(WebClient.EXECUTOR_SERVICE_PROPERTY, executorServiceProp);
+            }
             setConnectionProperties(configProps, clientCfg);
             // CXF Features
             for (org.apache.cxf.feature.Feature cxfFeature : cxfFeatures) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2aad4fc/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
index 2a1ba9b..31c6c9d 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
@@ -390,7 +390,7 @@ public class InvocationBuilderImpl implements Invocation.Builder {
     }
 
     private ExecutorService getConfiguredExecutorService() {
-        return (ExecutorService)config.getProperty("executorService");
+        return (ExecutorService)config.getProperty(WebClient.EXECUTOR_SERVICE_PROPERTY);
     }
 
 }


Mime
View raw message