org.alfresco.http
Class SharedHttpClientProvider
java.lang.Object
org.alfresco.http.SharedHttpClientProvider
- All Implemented Interfaces:
- HttpClientProvider
public final class SharedHttpClientProvider
- extends Object
- implements HttpClientProvider
A class responsible for managing shared HTTP connections. This uses a
thread-safe connection-manager instead of creating a new istance on every call.
This is done for the folowing reasons:
- Creating new HTTPClient instances for each request has memory-overhead and most
important, opens a new connection for each request. Even though the connection is released
they are kept in 'CLOSE_WAIT' state by the OS. This can, on high usage, empty out available outgoing TCP-ports and
influence the testing on the client, having impact on the results.
- Using a single HTTPClient allows creating a pool of connections that can be kept alive to
a certain route (route = combination of host and port) for a max number of time. This eliminates connection
setup and additional server round-trips, raising the overall throughput of http-calls (Browsers use
this mechanism all the time to lower loading-times).
- Author:
- Frederik Heremans, Derek Hulley, Michael Suzuki
|
Method Summary |
org.apache.http.client.HttpClient |
getHttpClient()
|
org.apache.http.client.HttpClient |
getHttpClient(String username,
String password)
Get a new client using basic authentication |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_CONNECTION_TIMEOUT_MILLISEC
public static final int DEFAULT_CONNECTION_TIMEOUT_MILLISEC
- See Also:
- Constant Field Values
DEFAULT_SOCKET_TIMEOUT_MILLISEC
public static final int DEFAULT_SOCKET_TIMEOUT_MILLISEC
- See Also:
- Constant Field Values
SharedHttpClientProvider
public SharedHttpClientProvider(int maxNumberOfConnections)
- Constructs with
DEFAULT_CONNECTION_TIMEOUT_MILLISEC and
DEFAULT_SOCKET_TIMEOUT_MILLISEC.
- See Also:
SharedHttpClientProvider#SharedHttpClientProvider(String, int, int)
SharedHttpClientProvider
public SharedHttpClientProvider(int maxNumberOfConnections,
int connectionTimeoutMs,
int socketTimeoutMs)
- See Connection management.
- Parameters:
maxNumberOfConnections - the maximum number of Http connections in the poolconnectionTimeoutMs - the time to wait for a connection from the pool before failuresocketTimeoutMs - the time to wait for data activity on a connection before failure
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
- Specified by:
getHttpClient in interface HttpClientProvider
- Returns:
- the
HttpClient instance to use for the next HTTP call.
getHttpClient
public org.apache.http.client.HttpClient getHttpClient(String username,
String password)
- Description copied from interface:
HttpClientProvider
- Get a new client using basic authentication
- Specified by:
getHttpClient in interface HttpClientProvider
- Parameters:
username - the usernamepassword - the password for the user
- Returns:
- the
HttpClient instance to use for the next HTTP call.
Copyright © 2012. All Rights Reserved.