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

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 04aae2a  Merge pull request #3095, remove @AsyncFor from core 
framework.
04aae2a is described below

commit 04aae2a66ea56b9aaba131c373bd645a648d9c76
Author: ken.lj <[email protected]>
AuthorDate: Wed Jan 2 10:12:12 2019 +0800

    Merge pull request #3095, remove @AsyncFor from core framework.
    
    * remove @Async from core framework.
    
    * refactor method name to isReturnFuture
---
 .../dubbo/common/async/support/AsyncFor.java       | 41 ----------------------
 .../dubbo/rpc/proxy/AbstractProxyInvoker.java      |  2 +-
 .../dubbo/rpc/proxy/InvokerInvocationHandler.java  | 18 +---------
 .../org/apache/dubbo/rpc/support/RpcUtils.java     | 11 +-----
 .../dubbo/rpc/protocol/dubbo/DubboInvoker.java     |  2 +-
 5 files changed, 4 insertions(+), 70 deletions(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/async/support/AsyncFor.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/async/support/AsyncFor.java
deleted file mode 100644
index 21ca9fc..0000000
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/async/support/AsyncFor.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.async.support;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * TODO This definition should better be placed in module 'dubbo-config-api', 
but only can be done when "rpc" dependencies are removed from "dubbo-config-api"
- * If a method is annotated with AsyncFor, it will be treated as an async 
counterpart for the sync specified in value.
- */
-@Documented
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface AsyncFor {
-
-    /**
-     * The original sync-style method name
-     *
-     * @return
-     */
-    String value();
-
-}
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java
index b275fa1..0f5a5df 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java
@@ -83,7 +83,7 @@ public abstract class AbstractProxyInvoker<T> implements 
Invoker<T> {
         RpcContext rpcContext = RpcContext.getContext();
         try {
             Object obj = doInvoke(proxy, invocation.getMethodName(), 
invocation.getParameterTypes(), invocation.getArguments());
-            if (RpcUtils.isFutureReturnType(invocation)) {
+            if (RpcUtils.isReturnTypeFuture(invocation)) {
                 return new AsyncRpcResult((CompletableFuture<Object>) obj);
             } else if (rpcContext.isAsyncStarted()) { // ignore obj in case of 
RpcContext.startAsync()? always rely on user to write back.
                 return new 
AsyncRpcResult(rpcContext.getAsyncContext().getInternalFuture());
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
index 59799db..3cdb65c 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java
@@ -17,7 +17,6 @@
 package org.apache.dubbo.rpc.proxy;
 
 import org.apache.dubbo.common.Constants;
-import org.apache.dubbo.common.async.support.AsyncFor;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.rpc.Invoker;
@@ -59,22 +58,7 @@ public class InvokerInvocationHandler implements 
InvocationHandler {
     }
 
     private RpcInvocation createInvocation(Method method, Object[] args) {
-        RpcInvocation invocation;
-        if (RpcUtils.hasGeneratedFuture(method)) {
-            AsyncFor asyncFor = method.getAnnotation(AsyncFor.class);
-            try {
-                Class<?> clazz = method.getDeclaringClass();
-                Method syncMethod = clazz.getMethod(asyncFor.value(), 
method.getParameterTypes());
-                invocation = new RpcInvocation(syncMethod, args);
-                invocation.setAttachment(Constants.FUTURE_GENERATED_KEY, 
"true");
-                invocation.setAttachment(Constants.ASYNC_KEY, "true");
-                return invocation;
-            } catch (Exception e) {
-                logger.warn("Annotated method " + method.getName() + " with 
AsyncFor, but cannot find the original sync method " + asyncFor.value());
-            }
-        }
-
-        invocation = new RpcInvocation(method, args);
+        RpcInvocation invocation = new RpcInvocation(method, args);
         if (RpcUtils.hasFutureReturnType(method)) {
             invocation.setAttachment(Constants.FUTURE_RETURNTYPE_KEY, "true");
             invocation.setAttachment(Constants.ASYNC_KEY, "true");
diff --git 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java
 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java
index cf18a82..e5a3899 100644
--- 
a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java
+++ 
b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java
@@ -18,7 +18,6 @@ package org.apache.dubbo.rpc.support;
 
 import org.apache.dubbo.common.Constants;
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.async.support.AsyncFor;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.ReflectUtils;
@@ -183,15 +182,7 @@ public class RpcUtils {
         return isAsync;
     }
 
-    public static boolean isGeneratedFuture(Invocation inv) {
-        return 
Boolean.TRUE.toString().equals(inv.getAttachment(Constants.FUTURE_GENERATED_KEY));
-    }
-
-    public static boolean hasGeneratedFuture(Method method) {
-        return method.isAnnotationPresent(AsyncFor.class) && 
hasFutureReturnType(method);
-    }
-
-    public static boolean isFutureReturnType(Invocation inv) {
+    public static boolean isReturnTypeFuture(Invocation inv) {
         return 
Boolean.TRUE.toString().equals(inv.getAttachment(Constants.FUTURE_RETURNTYPE_KEY));
     }
 
diff --git 
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
 
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
index 41ec2b2..5f2c61b 100644
--- 
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
+++ 
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java
@@ -81,7 +81,7 @@ public class DubboInvoker<T> extends AbstractInvoker<T> {
         }
         try {
             boolean isAsync = RpcUtils.isAsync(getUrl(), invocation);
-            boolean isAsyncFuture =  RpcUtils.isGeneratedFuture(inv) || 
RpcUtils.isFutureReturnType(inv);
+            boolean isAsyncFuture = RpcUtils.isReturnTypeFuture(inv);
             boolean isOneway = RpcUtils.isOneway(getUrl(), invocation);
             int timeout = getUrl().getMethodParameter(methodName, 
Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
             if (isOneway) {

Reply via email to