[incubator-dubbo-website] branch asf-site updated: rebuild website

2019-05-23 Thread iluo
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/asf-site by this push:
 new 03be83b  rebuild website
03be83b is described below

commit 03be83bb5bb7bf51990301323874ac0cd918f00d
Author: Ian Luo 
AuthorDate: Fri May 24 13:24:13 2019 +0800

rebuild website
---
 build/blog.js  |   6 +-
 build/blogDetail.js|   6 +-
 build/community.js |   6 +-
 build/documentation.js |   6 +-
 build/home.js  |   6 +-
 en-us/blog/dubbo2-js.html  |   2 +-
 en-us/blog/dubbo2-js.json  |   2 +-
 en-us/blog/gsoc-2018.html  |   6 +-
 en-us/blog/gsoc-2018.json  |   6 +-
 en-us/blog/prepare-an-apache-release.html  |   5 +-
 en-us/blog/prepare-an-apache-release.json  |   5 +-
 en-us/docs/user/demos/local-call.html  |   2 +-
 en-us/docs/user/demos/local-call.json  |   2 +-
 en-us/docs/user/references/registry/zookeeper.html |   1 +
 en-us/docs/user/references/registry/zookeeper.json |   2 +-
 md_json/blog.json  |  45 ++-
 .../blog/build-new-docker-image-in-dockerhub.html  |  73 
 .../blog/build-new-docker-image-in-dockerhub.json  |  10 +
 zh-cn/blog/dubbo-contribute-to-opensource.html |   2 +-
 zh-cn/blog/dubbo-contribute-to-opensource.json |   2 +-
 zh-cn/blog/dubbo-network-interfaces.html   | 406 +
 zh-cn/blog/dubbo-network-interfaces.json   |  10 +
 zh-cn/blog/dubbo-registry-nacos-integration.html   |   8 +-
 zh-cn/blog/dubbo-registry-nacos-integration.json   |   2 +-
 zh-cn/blog/gsoc-2018.html  |  34 ++
 zh-cn/blog/gsoc-2018.json  |  10 +
 zh-cn/blog/index.html  |   2 +-
 zh-cn/blog/prepare-an-apache-release.html  |   2 +-
 zh-cn/blog/prepare-an-apache-release.json  |   3 +-
 zh-cn/docs/user/references/registry/zookeeper.html |   1 +
 zh-cn/docs/user/references/registry/zookeeper.json |   2 +-
 31 files changed, 630 insertions(+), 45 deletions(-)

diff --git a/build/blog.js b/build/blog.js
index 2093a47..638de8e 100644
--- a/build/blog.js
+++ b/build/blog.js
@@ -1,6 +1,6 @@
-!function(e){function t(r){if(n[r])return n[r].exports;var 
o=n[r]={i:r,l:!1,exports:{}};return 
e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var 
n={};t.m=e,t.c=n,t.i=function(e){return 
e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var
 n=e&__esModule?function(){return e.default}:function(){return e};return 
t.d(n,"a",n),n},t.o=function(e,t){return 
Object.prototype.hasOwnProperty.call(e,t)},t.p="/build/",t(t.s=80) [...]
-  Copyright (c) 2016 Jed Watson.
+!function(e){function t(r){if(n[r])return n[r].exports;var 
o=n[r]={i:r,l:!1,exports:{}};return 
e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var 
n={};t.m=e,t.c=n,t.i=function(e){return 
e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var
 n=e&__esModule?function(){return e.default}:function(){return e};return 
t.d(n,"a",n),n},t.o=function(e,t){return 
Object.prototype.hasOwnProperty.call(e,t)},t.p="/build/",t(t.s=78) [...]
+  Copyright (c) 2017 Jed Watson.
   Licensed under the MIT License (MIT), see
   http://jedwatson.github.io/classnames
 */
-!function(){"use strict";function n(){for(var 
e=[],t=0;thttp://jedwatson.github.io/classnames
 */
-!function(){"use strict";function n(){for(var 
e=[],t=0;thttp://jedwatson.github.io/classnames
 */
-!function(){"use strict";function n(){for(var 
e=[],t=0;thttp://jedwatson.github.io/classnames
 */
-!function(){"use strict";function n(){for(var 
e=[],t=0;thttp://jedwatson.github.io/classnames
 */
-!function(){"use strict";function n(){for(var 
e=[],t=0;t


-   
+   


Implementation of cross-language calls by Dubbo2.js
diff --git a/en-us/blog/dubbo2-js.json b/en-us/blog/dubbo2-js.json
index a56bfe6..78021db 100644
--- a/en-us/blog/dubbo2-js.json
+++ b/en-us/blog/dubbo2-js.json
@@ -4,7 +4,7 @@
   "link": "/en-us/blog/dubbo2-js.html",
   "meta": {
 "title": "Implementation of cross-language calls by Dubbo2.js",
-"keywords": "Dubbo, 跨语言, Node, NodeJS, js",
+"keywords": "Dubbo, Cross-language, Node, NodeJS, js",
 "description": "This article introduces how to use Dubbo.js to implement 
cross-language calls."
   }
 }
\ No newline at end of file
diff --git a/en-us/blog/gsoc-2018.html b/en-us/blog/gsoc-2018.html
index 639a2b8..5938ae1 100644
--- a/en-us/blog/gsoc-2018.html
+++ b/en-us/blog/gsoc-2018.html
@@ 

[incubator-dubbo-website] branch asf-site updated: Fix some issues of Blog (#374)

2019-05-23 Thread iluo
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/asf-site by this push:
 new 627292e  Fix some issues of Blog (#374)
627292e is described below

commit 627292eda946b65e6f0c61b13d57271900fa913c
Author: Jlcao 
AuthorDate: Fri May 24 11:03:09 2019 +0800

Fix some issues of Blog (#374)

* Update gsoc-2018.md

Add SEO of header in mankdown.

* Update dubbo2-js.md

Fix typo - 'keywords' of SEO in mankdown (跨语言)

* Update prepare-an-apache-release.md

Add 'description' content in SEO header ;
and add the title('#') in the article.

* Update prepare-an-apache-release.md

Add 'description' content in SEO header.

* Rename dubbo-contribue-to-opensource.md to 
dubbo-contribute-to-opensource.md

Fix typo: 'contribue' --> 'contribute'.

* Rename dubbo-contribue-to-opensource.html to 
dubbo-contribute-to-opensource.html

Fix typo: 'contribue' --> 'contribute'.

* Update and rename dubbo-contribue-to-opensource.json to 
dubbo-contribute-to-opensource.json

Fix typo: 'contribue' --> 'contribute'.
---
 blog/en-us/dubbo2-js.md   | 2 +-
 blog/en-us/gsoc-2018.md   | 8 +++-
 blog/en-us/prepare-an-apache-release.md   | 2 ++
 ...ntribue-to-opensource.md => dubbo-contribute-to-opensource.md} | 2 +-
 blog/zh-cn/prepare-an-apache-release.md   | 1 +
 ...bue-to-opensource.html => dubbo-contribute-to-opensource.html} | 2 +-
 ...bue-to-opensource.json => dubbo-contribute-to-opensource.json} | 6 +++---
 7 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/blog/en-us/dubbo2-js.md b/blog/en-us/dubbo2-js.md
index f0ad823..f18eb35 100644
--- a/blog/en-us/dubbo2-js.md
+++ b/blog/en-us/dubbo2-js.md
@@ -1,6 +1,6 @@
 ---
 title: Implementation of cross-language calls by Dubbo2.js
-keywords: Dubbo, 跨语言, Node, NodeJS, js
+keywords: Dubbo, Cross-language, Node, NodeJS, js
 description: This article introduces how to use Dubbo.js to implement 
cross-language calls.
 ---
 
diff --git a/blog/en-us/gsoc-2018.md b/blog/en-us/gsoc-2018.md
index f17f6e5..04d7445 100644
--- a/blog/en-us/gsoc-2018.md
+++ b/blog/en-us/gsoc-2018.md
@@ -1,4 +1,10 @@
+---
+title: GSoC 2018
+keywords: Dubbo, GSoC
+description: The GSoC(Google Summer of Code) 2018 projects has been announced
+---
+
 The GSoC(Google Summer of Code) 2018 projects has been announced
 ---
 
-The GSoC(Google Summer of Code) 2018 projects has been announced, Raghu 
Reddy's project "Extending Serialization protocols support for Apache Dubbo" 
has been 
[accepted](https://summerofcode.withgoogle.com/projects/#4747840161579008)! 
Congratulations!
\ No newline at end of file
+The GSoC(Google Summer of Code) 2018 projects has been announced, Raghu 
Reddy's project "Extending Serialization protocols support for Apache Dubbo" 
has been 
[accepted](https://summerofcode.withgoogle.com/projects/#4747840161579008)! 
Congratulations!
diff --git a/blog/en-us/prepare-an-apache-release.md 
b/blog/en-us/prepare-an-apache-release.md
index b3ca9ee..5613f50 100644
--- a/blog/en-us/prepare-an-apache-release.md
+++ b/blog/en-us/prepare-an-apache-release.md
@@ -1,7 +1,9 @@
 ---
 title: Understanding the Apache Release Cycle
 keywords: Dubbo, Apache, Release
+description: This article introduces how to the Apache publish content and 
process
 ---
+# How to prepare an the Apache Release
 
 ## Understanding the Apache Release Cycle
 
diff --git a/blog/zh-cn/dubbo-contribue-to-opensource.md 
b/blog/zh-cn/dubbo-contribute-to-opensource.md
similarity index 99%
rename from blog/zh-cn/dubbo-contribue-to-opensource.md
rename to blog/zh-cn/dubbo-contribute-to-opensource.md
index fea9034..7dccbde 100644
--- a/blog/zh-cn/dubbo-contribue-to-opensource.md
+++ b/blog/zh-cn/dubbo-contribute-to-opensource.md
@@ -193,4 +193,4 @@ Mailing list 简单来说,就是一个邮件通知机制,所有的 Dubbo 开
 
 ## 5 成为一个开源贡献者
 
-如果你有志于参与开源事业,可以尝试从自己最熟悉的项目开始,开源并不是属于高级开发者的专属词汇,它就是由你我这样的人在需求,修复,构建中演进下去的。Let's 
try it !
\ No newline at end of file
+如果你有志于参与开源事业,可以尝试从自己最熟悉的项目开始,开源并不是属于高级开发者的专属词汇,它就是由你我这样的人在需求,修复,构建中演进下去的。Let's 
try it !
diff --git a/blog/zh-cn/prepare-an-apache-release.md 
b/blog/zh-cn/prepare-an-apache-release.md
index 2ef23a6..c00e131 100644
--- a/blog/zh-cn/prepare-an-apache-release.md
+++ b/blog/zh-cn/prepare-an-apache-release.md
@@ -1,6 +1,7 @@
 ---
 title: 如何准备Apache Release
 keywords: Dubbo, Apache, Release
+description: 本文介绍了Apache如何发布内容和流程
 ---
 
 # 如何准备Apache Release
diff --git a/zh-cn/blog/dubbo-contribue-to-opensource.html 
b/zh-cn/blog/dubbo-contribute-to-opensource.html
similarity index 99%
rename from zh-cn/blog/dubbo-contribue-to-opensource.html
rename to zh-cn/blog/dubbo-contribute-to-opensource.html

[incubator-dubbo-website] branch asf-site updated: new acticle: study dubbo network interfaces seletion (#363)

2019-05-23 Thread kirito
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/asf-site by this push:
 new 574428a  new acticle: study dubbo network interfaces seletion (#363)
574428a is described below

commit 574428a9b9f4aa23bfc214db60f7739e89a35f9b
Author: xujingfeng 
AuthorDate: Thu May 23 17:50:24 2019 +0800

new acticle: study dubbo network interfaces seletion (#363)

* new acticle: study dubbo network interfaces seletion

* fix some type error
---
 blog/zh-cn/dubbo-network-interfaces.md | 526 +
 site_config/blog.js|   7 +
 2 files changed, 533 insertions(+)

diff --git a/blog/zh-cn/dubbo-network-interfaces.md 
b/blog/zh-cn/dubbo-network-interfaces.md
new file mode 100644
index 000..16dc1f3
--- /dev/null
+++ b/blog/zh-cn/dubbo-network-interfaces.md
@@ -0,0 +1,526 @@
+---
+title: 研究 Dubbo 网卡地址注册时的一点思考
+keywords: 网卡地址注册
+description: 研究 Dubbo 网卡地址注册时的一点思考
+---
+
+# 研究 Dubbo 网卡地址注册时的一点思考
+
+## 1 如何选择合适的网卡地址
+
+可能相当一部分人还不知道我这篇文章到底要讲什么,我说个场景,大家应该就明晰了。在分布式服务调用过程中,以 Dubbo 为例,服务提供者往往需要将自身的 IP 
地址上报给注册中心,供消费者去发现。在大多数情况下 Dubbo 都可以正常工作,但如果你留意过 Dubbo 的 github 
issue,其实有不少人反馈:Dubbo Provider 注册了错误的 
IP。如果你能立刻联想到:多网卡、内外网地址共存、VPN、虚拟网卡等关键词,那我建议你一定要继续将本文看下去,因为我也想到了这些,它们都是本文所要探讨的东西!那么“如何选择合适的网卡地址”呢,Dubbo
 现有的逻辑到底算不算完备?我们不急着回答它,而是带着这些问题一起进行研究,相信到文末,其中答案,各位看官自有评说。
+
+## 2 Dubbo 是怎么做的
+
+Dubbo 获取网卡地址的逻辑在各个版本中也是千回百转,走过弯路,也做过优化,我们用最新的 2.7.2-SNAPSHOT 
版本来介绍,在看以下源码时,大家可以怀着质疑的心态去阅读,在 dubbo github 的 master 分支可以获取源码。获取 localhost 
的逻辑位于 `org.apache.dubbo.common.utils.NetUtils#getLocalAddress0()` 之中
+
+```java
+private static InetAddress getLocalAddress0() {
+InetAddress localAddress = null;
+// 首先尝试获取 /etc/hosts 中 hostname 对应的 IP
+localAddress = InetAddress.getLocalHost();
+Optional addressOp = toValidAddress(localAddress);
+if (addressOp.isPresent()) {
+return addressOp.get();
+}
+
+// 没有找到适合注册的 IP,则开始轮询网卡
+Enumeration interfaces = 
NetworkInterface.getNetworkInterfaces();
+if (null == interfaces) {
+return localAddress;
+}
+while (interfaces.hasMoreElements()) {
+NetworkInterface network = interfaces.nextElement();
+Enumeration addresses = network.getInetAddresses();
+while (addresses.hasMoreElements()) {
+// 返回第一个匹配的适合注册的 IP
+Optional addressOp = 
toValidAddress(addresses.nextElement());
+if (addressOp.isPresent()) {
+return addressOp.get();
+}
+}
+}
+return localAddress;
+}
+```
+
+Dubbo 这段选取本地地址的逻辑大致分成了两步
+
+1. 先去 /etc/hosts 文件中找 hostname 对应的 IP 地址,找到则返回;找不到则转 2
+2. 轮询网卡,寻找合适的 IP 地址,找到则返回;找不到返回 null,在 getLocalAddress0 外侧还有一段逻辑,如果返回 null,则注册 
127.0.0.1 这个本地回环地址
+
+首先强调下,这段逻辑并没有太大的问题,先别急着挑刺,让我们来分析下其中的一些细节,并进行验证。
+
+### 2.1 尝试获取 hostname 映射 IP
+
+Dubbo 首先选取的是 hostname 对应的 IP,在源码中对应的 `InetAddress.getLocalHost();`  在 `*nix` 
系统实际部署 Dubbo 应用时,可以首先使用 `hostname` 命令获取主机名
+
+```shell
+xujingfengdeMacBook-Pro:~ xujingfeng$ hostname
+xujingfengdeMacBook-Pro.local
+```
+
+紧接着在 `/etc/hosts` 配置 IP 映射,为了验证 Dubbo 的机制,我们随意为 hostname 配置一个 IP 地址
+
+```
+127.0.0.1  localhost
+1.2.3.4 xujingfengdeMacBook-Pro.local
+```
+
+接着调用 `NetUtils.getLocalAddress0()` 进行验证,控制台打印如下:
+
+```
+xujingfengdeMacBook-Pro.local/1.2.3.4
+```
+
+### 2.2 判定有效的 IP 地址
+
+在 toValidAddress 逻辑中,Dubbo 存在以下逻辑判定一个 IP 地址是否有效
+
+```java
+private static Optional toValidAddress(InetAddress address) {
+if (address instanceof Inet6Address) {
+Inet6Address v6Address = (Inet6Address) address;
+if (isValidV6Address(v6Address)) {
+return Optional.ofNullable(normalizeV6Address(v6Address));
+}
+}
+if (isValidV4Address(address)) {
+return Optional.of(address);
+}
+return Optional.empty();
+}
+```
+
+依次校验其符合 Ipv6 或者 Ipv4 的 IP 规范,对于 Ipv6 的地址,见如下代码:
+
+```java
+static boolean isValidV6Address(Inet6Address address) {
+boolean preferIpv6 = Boolean.getBoolean("java.net.preferIPv6Addresses");
+if (!preferIpv6) {
+return false;
+}
+try {
+return address.isReachable(100);
+} catch (IOException e) {
+// ignore
+}
+return false;
+}
+```
+
+首先获取 `java.net.preferIPv6Addresses` 参数,其默认值为 false,鉴于大多数应用并没有使用 Ipv6 地址作为理想的注册 
IP,这问题不大,紧接着通过 isReachable 判断网卡的连通性。例如一些网卡可能是 
VPN/虚拟网卡的地址,如果没有配置路由表,往往无法连通,可以将之过滤。
+
+对于 Ipv4 的地址,见如下代码:
+
+```java
+static boolean isValidV4Address(InetAddress address) {
+if (address == null || address.isLoopbackAddress()) {
+return false;
+}
+String name = address.getHostAddress();
+boolean result = (name != null
+&& IP_PATTERN.matcher(name).matches()
+&& !Constants.ANYHOST_VALUE.equals(name)
+&& !Constants.LOCALHOST_VALUE.equals(name));
+return result;
+}
+```
+
+对比 Ipv6 的判断,这里我们已经发现前后不对称的情况了
+
+- Ipv4 

[incubator-dubbo] branch master updated: [Dubbo-4115] When the network is reconnected, the listener should not to be empty. (#4116)

2019-05-23 Thread huxing
This is an automated email from the ASF dual-hosted git repository.

huxing 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 779fc27  [Dubbo-4115] When the network is reconnected, the listener 
should not to be empty. (#4116)
779fc27 is described below

commit 779fc27255b30c07164b2db6978c71e7fea0b82f
Author: yì jí 
AuthorDate: Thu May 23 17:40:30 2019 +0800

[Dubbo-4115] When the network is reconnected, the listener should not to be 
empty. (#4116)
---
 .../java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java   | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java
 
b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java
index d0ec619..8f50017 100644
--- 
a/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java
+++ 
b/dubbo-remoting/dubbo-remoting-etcd3/src/main/java/org/apache/dubbo/remoting/etcd/jetcd/JEtcdClient.java
@@ -278,7 +278,14 @@ public class JEtcdClient extends 
AbstractEtcdClient {
 }
 
 try {
-this.listener = null;
+/**
+ * issue : 
https://github.com/apache/incubator-dubbo/issues/4115
+ *
+ * When the network is reconnected, the listener is empty
+ * and the data cannot be received.
+ */
+// this.listener = null;
+
 if (watchRequest != null) {
 WatchCancelRequest watchCancelRequest =
 
WatchCancelRequest.newBuilder().setWatchId(watchId).build();



[incubator-dubbo] branch master updated (1a66206 -> 13e876e)

2019-05-23 Thread iluo
This is an automated email from the ASF dual-hosted git repository.

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


from 1a66206  Performance tuning for TimeoutTask in DefaultFuture (#4129)
 add 13e876e  fix client retry create proxy lead to OOM (#4109)

No new revisions were added by this update.

Summary of changes:
 .../src/main/java/org/apache/dubbo/config/ReferenceConfig.java   | 1 +
 1 file changed, 1 insertion(+)



[incubator-dubbo] branch master updated: Performance tuning for TimeoutTask in DefaultFuture (#4129)

2019-05-23 Thread carryxyh
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 1a66206  Performance tuning for TimeoutTask in DefaultFuture (#4129)
1a66206 is described below

commit 1a66206e5ed3086fc52fab57263b4afe4b6ad8d5
Author: ken.lj 
AuthorDate: Thu May 23 15:30:45 2019 +0800

Performance tuning for TimeoutTask in DefaultFuture (#4129)

Performance tuning for TimeoutTask in DefaultFuture, manually merge #4085 
and #4087
---
 .../remoting/exchange/support/DefaultFuture.java   | 29 --
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
index 1dab931..7f0e3a7 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
@@ -50,20 +50,19 @@ public class DefaultFuture extends 
CompletableFuture {
 
 private static final Map FUTURES = new 
ConcurrentHashMap<>();
 
-private static final Map PENDING_TASKS = new 
ConcurrentHashMap<>();
-
 public static final Timer TIME_OUT_TIMER = new HashedWheelTimer(
 new NamedThreadFactory("dubbo-future-timeout", true),
 30,
 TimeUnit.MILLISECONDS);
 
 // invoke id.
-private final long id;
+private final Long id;
 private final Channel channel;
 private final Request request;
 private final int timeout;
 private final long start = System.currentTimeMillis();
 private volatile long sent;
+private Timeout timeoutCheckTask;
 
 private DefaultFuture(Channel channel, Request request, int timeout) {
 this.channel = channel;
@@ -79,9 +78,8 @@ public class DefaultFuture extends CompletableFuture {
  * check time out of the future
  */
 private static void timeoutCheck(DefaultFuture future) {
-TimeoutCheckTask task = new TimeoutCheckTask(future);
-Timeout t = TIME_OUT_TIMER.newTimeout(task, future.getTimeout(), 
TimeUnit.MILLISECONDS);
-PENDING_TASKS.put(future.getId(), t);
+TimeoutCheckTask task = new TimeoutCheckTask(future.getId());
+future.timeoutCheckTask = TIME_OUT_TIMER.newTimeout(task, 
future.getTimeout(), TimeUnit.MILLISECONDS);
 }
 
 /**
@@ -140,15 +138,19 @@ public class DefaultFuture extends 
CompletableFuture {
 }
 
 public static void received(Channel channel, Response response) {
+received(channel, response, false);
+}
+
+public static void received(Channel channel, Response response, boolean 
timeout) {
 try {
 DefaultFuture future = FUTURES.remove(response.getId());
 if (future != null) {
-future.doReceived(response);
-Timeout t = PENDING_TASKS.remove(future.getId());
-if (t != null) {
+Timeout t = future.timeoutCheckTask;
+if (!timeout) {
 // decrease Time
 t.cancel();
 }
+future.doReceived(response);
 } else {
 logger.warn("The timeout response finally returned at "
 + (new SimpleDateFormat("-MM-dd 
HH:mm:ss.SSS").format(new Date()))
@@ -229,14 +231,15 @@ public class DefaultFuture extends 
CompletableFuture {
 
 private static class TimeoutCheckTask implements TimerTask {
 
-private DefaultFuture future;
+private final Long requestID;
 
-TimeoutCheckTask(DefaultFuture future) {
-this.future = future;
+TimeoutCheckTask(Long requestID) {
+this.requestID = requestID;
 }
 
 @Override
 public void run(Timeout timeout) {
+DefaultFuture future = DefaultFuture.getFuture(requestID);
 if (future == null || future.isDone()) {
 return;
 }
@@ -246,7 +249,7 @@ public class DefaultFuture extends 
CompletableFuture {
 timeoutResponse.setStatus(future.isSent() ? 
Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT);
 timeoutResponse.setErrorMessage(future.getTimeoutMessage(true));
 // handle response.
-DefaultFuture.received(future.getChannel(), timeoutResponse);
+DefaultFuture.received(future.getChannel(), timeoutResponse, true);
 
 }
 }



[incubator-dubbo] branch 3.x-dev updated: optimze TimeTask in DefaultFuture (#4132)

2019-05-23 Thread carryxyh
This is an automated email from the ASF dual-hosted git repository.

carryxyh pushed a commit to branch 3.x-dev
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/3.x-dev by this push:
 new 58c1474  optimze TimeTask in DefaultFuture (#4132)
58c1474 is described below

commit 58c147410f284711bf2d350d79e2f8f7bd360b5e
Author: ken.lj 
AuthorDate: Thu May 23 15:30:28 2019 +0800

optimze TimeTask in DefaultFuture (#4132)

optimze TimeTask in DefaultFuture
---
 .../remoting/exchange/support/DefaultFuture.java   | 42 +++---
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
index f7b5239..510e1f6 100644
--- 
a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
+++ 
b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java
@@ -50,8 +50,6 @@ public class DefaultFuture extends CompletableFuture {
 
 private static final Map FUTURES = new 
ConcurrentHashMap<>();
 
-//private static final Map PENDING_TASKS = new 
ConcurrentHashMap<>();
-
 public static final Timer TIME_OUT_TIMER = new HashedWheelTimer(
 new NamedThreadFactory("dubbo-future-timeout", true),
 30,
@@ -64,6 +62,7 @@ public class DefaultFuture extends CompletableFuture {
 private final int timeout;
 private final long start = System.currentTimeMillis();
 private volatile long sent;
+private Timeout timeoutCheckTask;
 
 private ExecutorService executor;
 
@@ -86,6 +85,14 @@ public class DefaultFuture extends CompletableFuture 
{
 }
 
 /**
+ * check time out of the future
+ */
+private static void timeoutCheck(DefaultFuture future) {
+TimeoutCheckTask task = new TimeoutCheckTask(future.getId());
+future.timeoutCheckTask = TIME_OUT_TIMER.newTimeout(task, 
future.getTimeout(), TimeUnit.MILLISECONDS);
+}
+
+/**
  * init a DefaultFuture
  * 1.init a DefaultFuture
  * 2.timeout check
@@ -142,15 +149,19 @@ public class DefaultFuture extends 
CompletableFuture {
 }
 
 public static void received(Channel channel, Response response) {
+received(channel, response, false);
+}
+
+public static void received(Channel channel, Response response, boolean 
timeout) {
 try {
 DefaultFuture future = FUTURES.remove(response.getId());
 if (future != null) {
+Timeout t = future.timeoutCheckTask;
+if (!timeout) {
+// decrease Time
+t.cancel();
+}
 future.doReceived(response);
-//Timeout t = PENDING_TASKS.remove(future.getId());
-//if (t != null) {
-//// decrease Time
-//t.cancel();
-//}
 } else {
 logger.warn("The timeout response finally returned at "
 + (new SimpleDateFormat("-MM-dd 
HH:mm:ss.SSS").format(new Date()))
@@ -178,6 +189,7 @@ public class DefaultFuture extends 
CompletableFuture {
 this.cancel(true);
 }
 
+
 private void doReceived(Response res) {
 if (res == null) {
 throw new IllegalStateException("response cannot be null");
@@ -224,15 +236,6 @@ public class DefaultFuture extends 
CompletableFuture {
 sent = System.currentTimeMillis();
 }
 
-/**
- * check time out of the future
- */
-private static void timeoutCheck(DefaultFuture future) {
-TimeoutCheckTask task = new TimeoutCheckTask(future.getId());
-TIME_OUT_TIMER.newTimeout(task, future.getTimeout(), 
TimeUnit.MILLISECONDS);
-//PENDING_TASKS.put(future.getId(), t);
-}
-
 private String getTimeoutMessage(boolean scan) {
 long nowTimestamp = System.currentTimeMillis();
 return (sent > 0 ? "Waiting server-side response timeout" : "Sending 
request timeout in client-side")
@@ -256,10 +259,7 @@ public class DefaultFuture extends 
CompletableFuture {
 
 @Override
 public void run(Timeout timeout) {
-// remove from pending task
-//PENDING_TASKS.remove(future.getId());
-
-DefaultFuture future = FUTURES.remove(requestID);
+DefaultFuture future = DefaultFuture.getFuture(requestID);
 if (future == null || future.isDone()) {
 return;
 }
@@ -271,7 +271,7 @@ public class DefaultFuture extends 
CompletableFuture {
 timeoutResponse.setStatus(future.isSent() ? 
Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT);