You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/12/27 05:27:27 UTC

[dubbo] branch master updated: extract duplicate code to a method (#5541)

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/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 15ed9f8  extract duplicate code to a method (#5541)
15ed9f8 is described below

commit 15ed9f85929a30aaba0b02d23a00d4339f67dad3
Author: zhenxianyimeng <19...@qq.com>
AuthorDate: Fri Dec 27 13:27:18 2019 +0800

    extract duplicate code to a method (#5541)
---
 .../org/apache/dubbo/rpc/support/RpcUtils.java     | 27 +++++++++++-----------
 1 file changed, 13 insertions(+), 14 deletions(-)

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 e1d85b7..7d4a1ab 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
@@ -57,13 +57,7 @@ public class RpcUtils {
                     && !invocation.getMethodName().startsWith("$")) {
                 String service = invocation.getInvoker().getUrl().getServiceInterface();
                 if (StringUtils.isNotEmpty(service)) {
-                    Class<?> invokerInterface = invocation.getInvoker().getInterface();
-                    Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service)
-                            : ReflectUtils.forName(service);
-                    Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
-                    if (method.getReturnType() == void.class) {
-                        return null;
-                    }
+                    Method method = getMethodByService(invocation, service);
                     return method.getReturnType();
                 }
             }
@@ -81,13 +75,7 @@ public class RpcUtils {
                     && !invocation.getMethodName().startsWith("$")) {
                 String service = invocation.getInvoker().getUrl().getServiceInterface();
                 if (StringUtils.isNotEmpty(service)) {
-                    Class<?> invokerInterface = invocation.getInvoker().getInterface();
-                    Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service)
-                            : ReflectUtils.forName(service);
-                    Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
-                    if (method.getReturnType() == void.class) {
-                        return null;
-                    }
+                    Method method = getMethodByService(invocation, service);
                     return ReflectUtils.getReturnTypes(method);
                 }
             }
@@ -226,4 +214,15 @@ public class RpcUtils {
         }
         return attachmentsToPass;
     }
+
+    private static Method getMethodByService(Invocation invocation, String service) throws NoSuchMethodException {
+        Class<?> invokerInterface = invocation.getInvoker().getInterface();
+        Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service)
+                : ReflectUtils.forName(service);
+        Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
+        if (method.getReturnType() == void.class) {
+            return null;
+        }
+        return method;
+    }
 }