Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dubbo-3237]fix connectionMonitor in RestProtocol seems not work #3237 #3455

Merged
merged 3 commits into from
Feb 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -136,16 +136,17 @@ public void run() {

@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();
// 20 is the default maxTotal of current PoolingClientConnectionManager
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))
Expand Down Expand Up @@ -239,7 +240,7 @@ public void destroy() {

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 {
Expand Down