Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2012-02-23 16:18:50 +0000
committerSteffen Pingel2012-02-23 16:18:50 +0000
commit9bdc9ffcd64018ecdd1cd86ef2352493d26d1413 (patch)
treeafa03e5c843caa4092627417bf7c35d3bf8c072a
parent67b2cb6035fd420002c8d16586033fc5d8fce206 (diff)
downloadorg.eclipse.mylyn.commons-9bdc9ffcd64018ecdd1cd86ef2352493d26d1413.tar.gz
org.eclipse.mylyn.commons-9bdc9ffcd64018ecdd1cd86ef2352493d26d1413.tar.xz
org.eclipse.mylyn.commons-9bdc9ffcd64018ecdd1cd86ef2352493d26d1413.zip
NEW - bug 372360: manage idle connections
https://bugs.eclipse.org/bugs/show_bug.cgi?id=372360
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java10
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/repositories/http/core/IdleConnectionMonitorThread.java92
2 files changed, 100 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
index 2c060065..051734ad 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
@@ -60,6 +60,7 @@ import org.eclipse.mylyn.commons.core.operations.OperationUtil;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
+import org.eclipse.mylyn.internal.commons.repositories.http.core.IdleConnectionMonitorThread;
import org.eclipse.mylyn.internal.commons.repositories.http.core.PollingProtocolSocketFactory;
import org.eclipse.mylyn.internal.commons.repositories.http.core.PollingSslProtocolSocketFactory;
@@ -81,9 +82,9 @@ public class HttpUtil {
private static final long CLOSE_TIMEOUT = -1;
/**
- * @see IdleConnectionTimeoutThread#setTimeoutInterval(long)
+ * @see IdleConnectionMonitorThread
*/
- private static final int CONNECTION_TIMEOUT_INTERVAL = 30 * 1000;
+ private static final int CONNECTION_TIMEOUT_INTERVAL = 1 * 30 * 1000;
private static final int CONNNECT_TIMEOUT = 60 * 1000;
@@ -311,6 +312,11 @@ public class HttpUtil {
connectionManager.setDefaultMaxPerRoute(100);
connectionManager.setMaxTotal(1000);
}
+
+ IdleConnectionMonitorThread thread = new IdleConnectionMonitorThread(CONNECTION_TIMEOUT_INTERVAL);
+ thread.setTimeout(CONNNECT_TIMEOUT);
+ thread.addConnectionManager(connectionManager);
+ thread.start();
}
return connectionManager;
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/repositories/http/core/IdleConnectionMonitorThread.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/repositories/http/core/IdleConnectionMonitorThread.java
new file mode 100644
index 00000000..7d3bcc72
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/repositories/http/core/IdleConnectionMonitorThread.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.commons.repositories.http.core;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.http.conn.ClientConnectionManager;
+
+/**
+ * Closes idle connections periodically.
+ *
+ * @author spingel
+ */
+public class IdleConnectionMonitorThread extends Thread {
+
+ private final List<ClientConnectionManager> connectionManagers;
+
+ private long pollingInterval;
+
+ private volatile boolean shutdown;
+
+ private long timeout;
+
+ public IdleConnectionMonitorThread(long pollingInterval) {
+ this.pollingInterval = pollingInterval;
+ this.connectionManagers = new CopyOnWriteArrayList<ClientConnectionManager>();
+ setDaemon(true);
+ }
+
+ public void addConnectionManager(ClientConnectionManager manager) {
+ connectionManagers.add(manager);
+ }
+
+ public long getPollingInterval() {
+ return pollingInterval;
+ }
+
+ public long getTimeout() {
+ return timeout;
+ }
+
+ public void removeConnectionManager(ClientConnectionManager manager) {
+ connectionManagers.remove(manager);
+ }
+
+ @Override
+ public void run() {
+ try {
+ while (!shutdown) {
+ for (ClientConnectionManager connectionManager : connectionManagers) {
+ connectionManager.closeExpiredConnections();
+ if (timeout > 0) {
+ connectionManager.closeIdleConnections(timeout, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ synchronized (this) {
+ wait(pollingInterval);
+ }
+ }
+ } catch (InterruptedException e) {
+ // shutdown
+ }
+ }
+
+ public void setPollingInterval(long pollingInterval) {
+ this.pollingInterval = pollingInterval;
+ }
+
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public void shutdown() {
+ this.shutdown = true;
+ synchronized (this) {
+ notifyAll();
+ }
+ }
+
+}

Back to the top