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/02/12 17:01:20 UTC

[incubator-dubbo] branch master updated: [Dubbo-3237]fix connectionMonitor in RestProtocol seems not work #3237 (#3455)

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

lixiaojie 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 10912c8  [Dubbo-3237]fix connectionMonitor in RestProtocol seems not work #3237 (#3455)
10912c8 is described below

commit 10912c811598285c62f7c0f28530732dd1115e5b
Author: huazhongming <cr...@gmail.com>
AuthorDate: Wed Feb 13 01:01:11 2019 +0800

    [Dubbo-3237]fix connectionMonitor in RestProtocol seems not work #3237 (#3455)
---
 .../org/apache/dubbo/rpc/protocol/rest/RestProtocol.java    | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
index 7f8bc79..4290ef2 100644
--- a/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
+++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java
@@ -61,7 +61,7 @@ public class RestProtocol extends AbstractProxyProtocol {
 
     private static final int HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE = 20;
     private static final int HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL = 20;
-    private static final int HTTPCLIENT_KEEPALIVEDURATION = 30*1000;
+    private static final int HTTPCLIENT_KEEPALIVEDURATION = 30 * 1000;
     private static final int HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS = 1000;
     private static final int HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S = 30;
 
@@ -70,7 +70,7 @@ public class RestProtocol extends AbstractProxyProtocol {
     private final RestServerFactory serverFactory = new RestServerFactory();
 
     // TODO in the future maybe we can just use a single rest client and connection manager
-    private final List<ResteasyClient> clients = Collections.synchronizedList(new LinkedList<ResteasyClient>());
+    private final List<ResteasyClient> clients = Collections.synchronizedList(new LinkedList<>());
 
     private volatile ConnectionMonitor connectionMonitor;
 
@@ -136,9 +136,6 @@ public class RestProtocol extends AbstractProxyProtocol {
 
     @Override
     protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
-        if (connectionMonitor == null) {
-            connectionMonitor = new ConnectionMonitor();
-        }
 
         // TODO more configs to add
         PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
@@ -146,6 +143,10 @@ public class RestProtocol extends AbstractProxyProtocol {
         connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL));
         connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE));
 
+        if (connectionMonitor == null) {
+            connectionMonitor = new ConnectionMonitor();
+            connectionMonitor.start();
+        }
         connectionMonitor.addConnectionManager(connectionManager);
         RequestConfig requestConfig = RequestConfig.custom()
                 .setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT))
@@ -239,7 +240,7 @@ public class RestProtocol extends AbstractProxyProtocol {
 
     protected String getContextPath(URL url) {
         String contextPath = url.getPath();
-        return contextPath.endsWith("/") ? contextPath.substring(0,contextPath.length()-1) : contextPath;
+        return contextPath.endsWith("/") ? contextPath.substring(0, contextPath.length() - 1) : contextPath;
     }
 
     protected class ConnectionMonitor extends Thread {