You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ca...@apache.org on 2019/01/08 02:20:15 UTC

[incubator-dubbo] branch master updated: code optimization (#3167)

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

carryxyh 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 e095bd9  code optimization (#3167)
e095bd9 is described below

commit e095bd9bab6c9527ee4da7031f49575651af1696
Author: huazhongming <cr...@gmail.com>
AuthorDate: Tue Jan 8 10:20:10 2019 +0800

    code optimization (#3167)
    
    code optimization
---
 .../src/main/java/org/apache/dubbo/rpc/AbstractResult.java           | 4 +++-
 .../dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java | 3 ++-
 .../src/main/java/org/apache/dubbo/rpc/RpcException.java             | 5 ++++-
 .../src/main/java/org/apache/dubbo/rpc/RpcInvocation.java            | 3 ++-
 .../src/main/java/org/apache/dubbo/rpc/service/GenericService.java   | 2 +-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java
index 760a9c1..b898934 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java
@@ -16,6 +16,8 @@
  */
 package org.apache.dubbo.rpc;
 
+import org.apache.dubbo.common.utils.StringUtils;
+
 import java.util.HashMap;
 import java.util.Map;
 
@@ -58,7 +60,7 @@ public abstract class AbstractResult implements Result {
     @Override
     public String getAttachment(String key, String defaultValue) {
         String result = attachments.get(key);
-        if (result == null || result.length() == 0) {
+        if (StringUtils.isEmpty(result)) {
             result = defaultValue;
         }
         return result;
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
index a9000ec..eaa467d 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.Constants;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.threadlocal.InternalThreadLocal;
 import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.common.utils.StringUtils;
 
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
@@ -364,7 +365,7 @@ public class RpcContext {
      */
     public String getLocalHostName() {
         String host = localAddress == null ? null : localAddress.getHostName();
-        if (host == null || host.length() == 0) {
+        if (StringUtils.isEmpty(host)) {
             return getLocalHost();
         }
         return host;
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java
index deb37ca..dc8a1b4 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java
@@ -34,7 +34,10 @@ public /**final**/ class RpcException extends RuntimeException {
     public static final int SERIALIZATION_EXCEPTION = 5;
     public static final int NO_INVOKER_AVAILABLE_AFTER_FILTER = 6;
     private static final long serialVersionUID = 7815426752583648734L;
-    private int code; // RpcException cannot be extended, use error code for exception type to keep compatibility
+    /**
+     * RpcException cannot be extended, use error code for exception type to keep compatibility
+     */
+    private int code;
 
     public RpcException() {
         super();
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
index b40f544..707bf3b 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.rpc;
 
 import org.apache.dubbo.common.Constants;
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.utils.StringUtils;
 
 import java.io.Serializable;
 import java.lang.reflect.Method;
@@ -198,7 +199,7 @@ public class RpcInvocation implements Invocation, Serializable {
             return defaultValue;
         }
         String value = attachments.get(key);
-        if (value == null || value.length() == 0) {
+        if (StringUtils.isEmpty(value)) {
             return defaultValue;
         }
         return value;
diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java
index 124db22..07517d4 100644
--- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java
+++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java
@@ -31,7 +31,7 @@ public interface GenericService {
      * @param parameterTypes Parameter types
      * @param args           Arguments
      * @return invocation return value
-     * @throws Throwable potential exception thrown from the invocation
+     * @throws GenericException potential exception thrown from the invocation
      */
     Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException;