Revision: 7ff0789ef153
Author: [email protected] <[email protected]>
Date: Thu Aug 1 08:21:20 2013
Log: Fixed Issue #94:HTTP Client RA : Connection idles in CLOSE_WAIT
http://code.google.com/p/jain-slee/source/detail?r=7ff0789ef153&repo=http
Modified:
/resources/http-client/ra/src/main/java/org/mobicents/client/slee/resource/http/HttpClientResourceAdaptor.java
=======================================
---
/resources/http-client/ra/src/main/java/org/mobicents/client/slee/resource/http/HttpClientResourceAdaptor.java
Mon Jul 8 09:10:05 2013
+++
/resources/http-client/ra/src/main/java/org/mobicents/client/slee/resource/http/HttpClientResourceAdaptor.java
Thu Aug 1 08:21:20 2013
@@ -29,6 +29,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import javax.slee.Address;
import javax.slee.EventTypeID;
@@ -53,6 +54,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
@@ -101,6 +103,8 @@
private Map<HttpRoute, Integer> maxForRoutes;
private HttpClientFactory httpClientFactory;
+ private IdleConnectionMonitorThread idleConnectionMonitorThread = null;
+
// LIFECYCLE METHODS
/*
@@ -198,14 +202,18 @@
ThreadSafeClientConnManager threadSafeClientConnManager = new
ThreadSafeClientConnManager(schemeRegistry);
threadSafeClientConnManager.setMaxTotal(maxTotal);
for (Entry<HttpRoute, Integer> entry :
maxForRoutes.entrySet()) {
- if(tracer.isInfoEnabled()){
+ if (tracer.isInfoEnabled()) {
tracer.info(String.format("Configuring MaxForRoute %s
max %d", entry.getKey(), entry.getValue()));
}
threadSafeClientConnManager.setMaxForRoute(entry.getKey(),
entry.getValue());
}
httpclient = new
DefaultHttpClient(threadSafeClientConnManager, params);
+
+ this.idleConnectionMonitorThread = new
IdleConnectionMonitorThread(threadSafeClientConnManager);
+ this.idleConnectionMonitorThread.start();
}
isActive = true;
+
if (tracer.isInfoEnabled()) {
tracer.info(String.format("HttpClientResourceAdaptor=%s entity
activated.",
this.resourceAdaptorContext.getEntityName()));
@@ -219,6 +227,10 @@
*/
public void raStopping() {
this.isActive = false;
+
+ if (this.idleConnectionMonitorThread != null) {
+ this.idleConnectionMonitorThread.shutdown();
+ }
}
/*
@@ -234,6 +246,7 @@
executorService = null;
this.httpclient.getConnectionManager().shutdown();
+ this.idleConnectionMonitorThread = null;
this.httpclient = null;
}
@@ -694,6 +707,42 @@
}
}
}
+
+ }
+
+ public class IdleConnectionMonitorThread extends Thread {
+
+ private final ClientConnectionManager connMgr;
+ private volatile boolean shutdown;
+
+ public IdleConnectionMonitorThread(ClientConnectionManager
connMgr) {
+ super();
+ this.connMgr = connMgr;
+ }
+
+ @Override
+ public void run() {
+ try {
+ while (!shutdown) {
+ synchronized (this) {
+ wait(5000);
+
+ // close connections that have been idle longer
than 30
+ // sec
+ connMgr.closeIdleConnections(30, TimeUnit.SECONDS);
+ }
+ }
+ } catch (InterruptedException ex) {
+ // terminate
+ }
+ }
+
+ public void shutdown() {
+ shutdown = true;
+ synchronized (this) {
+ notifyAll();
+ }
+ }
}
--
---
You received this message because you are subscribed to the Google Groups "mobicents-commits" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.