[dubbo] branch master updated: Refactor: remove NetUtils.getHostAddress() and relace it with NetUtils.getLocalHost() (#5526)

2019-12-24 Thread liujun
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 fa157de  Refactor: remove NetUtils.getHostAddress() and relace it with 
NetUtils.getLocalHost() (#5526)
fa157de is described below

commit fa157deadf65d00c9884d611430ec78e585840ff
Author: LinShunKang 
AuthorDate: Wed Dec 25 15:22:57 2019 +0800

Refactor: remove NetUtils.getHostAddress() and relace it with 
NetUtils.getLocalHost() (#5526)
---
 .../ConsumerContextClusterInterceptor.java |  2 +-
 .../org/apache/dubbo/common/utils/NetUtils.java| 22 ++
 .../apache/dubbo/common/utils/NetUtilsTest.java|  7 +++
 3 files changed, 18 insertions(+), 13 deletions(-)

diff --git 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/interceptor/ConsumerContextClusterInterceptor.java
 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/interceptor/ConsumerContextClusterInterceptor.java
index 1216ed6..ec6323e 100644
--- 
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/interceptor/ConsumerContextClusterInterceptor.java
+++ 
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/interceptor/ConsumerContextClusterInterceptor.java
@@ -31,7 +31,7 @@ public class ConsumerContextClusterInterceptor implements 
ClusterInterceptor, Cl
 public void before(AbstractClusterInvoker invoker, Invocation 
invocation) {
 RpcContext.getContext()
 .setInvocation(invocation)
-.setLocalAddress(NetUtils.getHostAddress(), 0);
+.setLocalAddress(NetUtils.getLocalHost(), 0);
 if (invocation instanceof RpcInvocation) {
 ((RpcInvocation) invocation).setInvoker(invoker);
 }
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
index 5c3f9a5..ee2aa61 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
@@ -139,12 +139,12 @@ public class NetUtils {
 if (address == null || address.isLoopbackAddress()) {
 return false;
 }
+
 String name = address.getHostAddress();
-boolean result = (name != null
+return (name != null
 && IP_PATTERN.matcher(name).matches()
 && !ANYHOST_VALUE.equals(name)
 && !LOCALHOST_VALUE.equals(name));
-return result;
 }
 
 /**
@@ -186,18 +186,16 @@ public class NetUtils {
 
 private static volatile String HOST_ADDRESS;
 
-public static String getHostAddress () {
+public static String getLocalHost() {
 if (HOST_ADDRESS != null) {
 return HOST_ADDRESS;
 }
 
-HOST_ADDRESS = getLocalHost();
-return HOST_ADDRESS;
-}
-
-public static String getLocalHost() {
 InetAddress address = getLocalAddress();
-return address == null ? LOCALHOST_VALUE : address.getHostAddress();
+if (address != null) {
+return HOST_ADDRESS = address.getHostAddress();
+}
+return LOCALHOST_VALUE;
 }
 
 public static String filterLocalHost(String host) {
@@ -287,7 +285,7 @@ public class NetUtils {
 Optional addressOp = 
toValidAddress(addresses.nextElement());
 if (addressOp.isPresent()) {
 try {
-if(addressOp.get().isReachable(100)){
+if (addressOp.get().isReachable(100)) {
 return addressOp.get();
 }
 } catch (IOException e) {
@@ -387,7 +385,7 @@ public class NetUtils {
 InetAddress address = (InetAddress) addresses.nextElement();
 if (preferIpv6 && address instanceof Inet6Address) {
 try {
-if(address.isReachable(100)){
+if (address.isReachable(100)) {
 multicastSocket.setInterface(address);
 interfaceSet = true;
 break;
@@ -397,7 +395,7 @@ public class NetUtils {
 }
 } else if (!preferIpv6 && address instanceof Inet4Address) {
 try {
-if(address.isReachable(100)){
+if (address.isReachable(100)) {
 multicastSocket.setInterface(address);
 interfaceSet = true;
 break;
diff --git 
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java 

[dubbo-go] branch develop updated: add lock for invocation attachment

2019-12-24 Thread fangyc
This is an automated email from the ASF dual-hosted git repository.

fangyc pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
 new 944e6dc  add lock for invocation attachment
 new 382169c  Merge pull request #288 from xujianhai666/fix-map-attach
944e6dc is described below

commit 944e6dc899f22f1b99f2afe57eb1794449bcb2aa
Author: xujianhai666 
AuthorDate: Wed Dec 18 22:52:15 2019 +0800

add lock for invocation attachment
---
 protocol/invocation/rpcinvocation.go | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/protocol/invocation/rpcinvocation.go 
b/protocol/invocation/rpcinvocation.go
index 2124a22..bddd83b 100644
--- a/protocol/invocation/rpcinvocation.go
+++ b/protocol/invocation/rpcinvocation.go
@@ -19,6 +19,7 @@ package invocation
 
 import (
"reflect"
+   "sync"
 )
 
 import (
@@ -37,6 +38,7 @@ type RPCInvocation struct {
callBack   interface{}
attachmentsmap[string]string
invokerprotocol.Invoker
+   lock   sync.RWMutex
 }
 
 func NewRPCInvocation(methodName string, arguments []interface{}, attachments 
map[string]string) *RPCInvocation {
@@ -80,6 +82,8 @@ func (r *RPCInvocation) Attachments() map[string]string {
 }
 
 func (r *RPCInvocation) AttachmentsByKey(key string, defaultValue string) 
string {
+   r.lock.RLock()
+   defer r.lock.RUnlock()
if r.attachments == nil {
return defaultValue
}
@@ -91,6 +95,8 @@ func (r *RPCInvocation) AttachmentsByKey(key string, 
defaultValue string) string
 }
 
 func (r *RPCInvocation) SetAttachments(key string, value string) {
+   r.lock.Lock()
+   defer r.lock.Unlock()
if r.attachments == nil {
r.attachments = make(map[string]string)
}