diff options
author | Devi Sandeep Endluri V V <dendluri@codeaurora.org> | 2016-03-30 11:43:53 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2016-08-24 08:07:51 -0600 |
commit | 62faf59da6137d7d17a01f85b0919f8b12b332c3 (patch) | |
tree | 598968ebc7c7a76120ceb526744f59282aa61510 | |
parent | cc9d1287d7ff732537f2fc0d1514e79ede953381 (diff) | |
download | android_external_apache-http-62faf59da6137d7d17a01f85b0919f8b12b332c3.tar.gz android_external_apache-http-62faf59da6137d7d17a01f85b0919f8b12b332c3.tar.bz2 android_external_apache-http-62faf59da6137d7d17a01f85b0919f8b12b332c3.zip |
Add support for closing multiple idle connections
Apache-http stack can have multiple threads having open idle
connections. Adding tcm support to close these idle connections
Change-Id: I501e81bcc8c8514c68190ae11afaf44ab4e41741
Add TCM (TCP Connection Management) support
TCM service indicates to close the TCP idle connections
on time so that the application servers do not time out
on connection and wake the modem cellular data connection
up and cost power.
Change-Id: I74465117c0254636dd79fe4336b07f1e8080ea88
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | src/org/apache/http/impl/conn/SingleClientConnManager.java | 4 | ||||
-rw-r--r-- | src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java | 84 | ||||
-rw-r--r-- | src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java | 8 |
4 files changed, 91 insertions, 7 deletions
@@ -18,7 +18,7 @@ apache_http_src_files := \ $(call all-java-files-under,src) \ $(call all-java-files-under,android) -apache_http_java_libs := conscrypt +apache_http_java_libs := conscrypt tcmiface apache_http_packages := $(strip \ com.android.internal.http.multipart \ diff --git a/src/org/apache/http/impl/conn/SingleClientConnManager.java b/src/org/apache/http/impl/conn/SingleClientConnManager.java index d8fb956..42928fb 100644 --- a/src/org/apache/http/impl/conn/SingleClientConnManager.java +++ b/src/org/apache/http/impl/conn/SingleClientConnManager.java @@ -108,8 +108,7 @@ public class SingleClientConnManager implements ClientConnectionManager { /** Indicates whether this connection manager is shut down. */ protected volatile boolean isShutDown; - - + private TcmIdleTimerMonitor mIdleMonitor; /** * Creates a new simple connection manager. @@ -131,6 +130,7 @@ public class SingleClientConnManager implements ClientConnectionManager { this.lastReleaseTime = -1L; this.alwaysShutDown = false; //@@@ from params? as argument? this.isShutDown = false; + mIdleMonitor = new TcmIdleTimerMonitor(this); } // <constructor> diff --git a/src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java b/src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java new file mode 100644 index 0000000..ac46948 --- /dev/null +++ b/src/org/apache/http/impl/conn/TcmIdleTimerMonitor.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.apache.http.impl.conn; + +import dalvik.system.PathClassLoader; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import org.apache.http.conn.ClientConnectionManager; +import java.util.concurrent.TimeUnit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import com.quicinc.tcmiface.DpmTcmIface; + +/** + * @hide + */ +public class TcmIdleTimerMonitor implements DpmTcmIface { + private final Log log = LogFactory.getLog(getClass()); + private org.apache.http.conn.ClientConnectionManager connectionManager; + private static Object tcmClient = null; + private static Method mTcmRegisterMethod = null; + private static Object lockObj = new Object(); + Object result = null; + + /** @hide */ + public TcmIdleTimerMonitor(ClientConnectionManager connManager) { + synchronized(lockObj) { + this.connectionManager = connManager; + //load tcm + try { + if (mTcmRegisterMethod == null || tcmClient == null) { + //load tcm if not already loaded + PathClassLoader tcmClassLoader = + new PathClassLoader("/system/framework/tcmclient.jar", + ClassLoader.getSystemClassLoader()); + Class tcmClass = tcmClassLoader.loadClass("com.qti.tcmclient.DpmTcmClient"); + Method mGetTcmMethod = tcmClass.getDeclaredMethod("getInstance"); + tcmClient = mGetTcmMethod.invoke(null); + mTcmRegisterMethod = tcmClass.getDeclaredMethod("registerTcmMonitor", DpmTcmIface.class); + } + if (mTcmRegisterMethod != null && tcmClient != null) { + result = mTcmRegisterMethod.invoke(tcmClient, this); + } + } catch (ClassNotFoundException e) { + //Ignore ClassNotFound Exception + } catch (Exception e) { + log.debug("Failed to load tcmclient " + e); + } + } + } + + /** @hide */ + public synchronized void OnCloseIdleConn() + { + connectionManager.closeIdleConnections(0, TimeUnit.MILLISECONDS); + } +} // class TcmIdleTimerMonitor diff --git a/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java b/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java index 7d6a560..2b16712 100644 --- a/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java +++ b/src/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java @@ -47,7 +47,7 @@ import org.apache.http.conn.ManagedClientConnection; import org.apache.http.conn.OperatedClientConnection; import org.apache.http.params.HttpParams; import org.apache.http.impl.conn.DefaultClientConnectionOperator; - +import org.apache.http.impl.conn.TcmIdleTimerMonitor; /** @@ -84,8 +84,8 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { /** The operator for opening and updating connections. */ protected ClientConnectionOperator connOperator; - - + /** The operator for monitoring idle connections. */ + private TcmIdleTimerMonitor mIdleMonitor; /** * Creates a new thread safe connection manager. * @@ -101,7 +101,7 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager { this.schemeRegistry = schreg; this.connOperator = createConnectionOperator(schreg); this.connectionPool = createConnectionPool(params); - + mIdleMonitor = new TcmIdleTimerMonitor(this); } // <constructor> |