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

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new c4ebd3b  [SCB-2157] enhance AsyncUtils.tryCatch
c4ebd3b is described below

commit c4ebd3baa132ff1cfa3f4a60301fb45035798c8e
Author: wujimin <wuji...@huawei.com>
AuthorDate: Wed Dec 9 22:58:31 2020 +0800

    [SCB-2157] enhance AsyncUtils.tryCatch
---
 .../java/org/apache/servicecomb/core/filter/FilterNode.java   |  2 +-
 .../servicecomb/core/invocation/ProducerInvocationFlow.java   |  6 ++----
 .../servicecomb/foundation/common/utils/AsyncUtils.java       | 11 ++++++++++-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/core/src/main/java/org/apache/servicecomb/core/filter/FilterNode.java 
b/core/src/main/java/org/apache/servicecomb/core/filter/FilterNode.java
index a6f817c..31ac18a 100644
--- a/core/src/main/java/org/apache/servicecomb/core/filter/FilterNode.java
+++ b/core/src/main/java/org/apache/servicecomb/core/filter/FilterNode.java
@@ -82,7 +82,7 @@ public class FilterNode {
       return nextNode.onFilter(invocation);
     }
 
-    return AsyncUtils.tryCatch(() -> filter.onFilter(invocation, nextNode))
+    return AsyncUtils.tryCatchSupplierFuture(() -> filter.onFilter(invocation, 
nextNode))
         .thenApply(this::rethrowExceptionInResponse);
   }
 
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/invocation/ProducerInvocationFlow.java
 
b/core/src/main/java/org/apache/servicecomb/core/invocation/ProducerInvocationFlow.java
index 0d0669f..847936d 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/invocation/ProducerInvocationFlow.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/invocation/ProducerInvocationFlow.java
@@ -16,10 +16,9 @@
  */
 package org.apache.servicecomb.core.invocation;
 
-import java.util.concurrent.CompletableFuture;
-
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.exception.Exceptions;
+import org.apache.servicecomb.foundation.common.utils.AsyncUtils;
 import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
 import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
 import org.apache.servicecomb.swagger.invocation.Response;
@@ -49,8 +48,7 @@ public abstract class ProducerInvocationFlow {
   }
 
   public void run() {
-    CompletableFuture.completedFuture(null)
-        .thenApply(v -> invocationCreator.create())
+    AsyncUtils.tryCatchSupplier(invocationCreator::create)
         .exceptionally(this::sendCreateInvocationException)
         .thenAccept(this::tryRunInvocation);
   }
diff --git 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/AsyncUtils.java
 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/AsyncUtils.java
index 3030f88..8f4780e 100644
--- 
a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/AsyncUtils.java
+++ 
b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/AsyncUtils.java
@@ -23,7 +23,16 @@ public final class AsyncUtils {
   private AsyncUtils() {
   }
 
-  public static <T> CompletableFuture<T> 
tryCatch(Supplier<CompletableFuture<T>> supplier) {
+  public static <T> CompletableFuture<T> tryCatchSupplier(Supplier<T> 
supplier) {
+    try {
+      T value = supplier.get();
+      return CompletableFuture.completedFuture(value);
+    } catch (Throwable e) {
+      return completeExceptionally(e);
+    }
+  }
+
+  public static <T> CompletableFuture<T> 
tryCatchSupplierFuture(Supplier<CompletableFuture<T>> supplier) {
     try {
       return supplier.get();
     } catch (Throwable e) {

Reply via email to