use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project carbon-apimgt by wso2.
the class ExtendedHTTPEventAdapter method init.
@Override
public void init() throws OutputEventAdapterException {
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
// ExecutorService will be assigned if it is null
if (executorService == null) {
int minThread;
int maxThread;
long defaultKeepAliveTime;
int jobQueSize;
// If global properties are available those will be assigned else constant values will be assigned
if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) {
minThread = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME));
} else {
minThread = ExtendedHTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE;
}
if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) {
maxThread = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME));
} else {
maxThread = ExtendedHTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE;
}
if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) {
defaultKeepAliveTime = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME));
} else {
defaultKeepAliveTime = ExtendedHTTPEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS;
}
if (globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) {
jobQueSize = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME));
} else {
jobQueSize = ExtendedHTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE;
}
executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize));
// configurations for the httpConnectionManager which will be shared by every http adapter
int defaultMaxConnectionsPerHost;
int maxTotalConnections;
if (globalProperties.get(ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) {
defaultMaxConnectionsPerHost = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST));
} else {
defaultMaxConnectionsPerHost = ExtendedHTTPEventAdapterConstants.DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST;
}
if (globalProperties.get(ExtendedHTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS) != null) {
maxTotalConnections = Integer.parseInt(globalProperties.get(ExtendedHTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS));
} else {
maxTotalConnections = ExtendedHTTPEventAdapterConstants.DEFAULT_MAX_TOTAL_CONNECTIONS;
}
connectionManager = new MultiThreadedHttpConnectionManager();
connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost);
connectionManager.getParams().setMaxTotalConnections(maxTotalConnections);
Map<String, String> staticProperties = eventAdapterConfiguration.getStaticProperties();
if (staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_KEY) != null) {
accessTokenGenerator = new AccessTokenGenerator(staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_URL), staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_KEY), staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_CONSUMER_SECRET));
this.oauthURL = staticProperties.get(ExtendedHTTPEventAdapterConstants.ADAPTER_OAUTH_URL);
}
}
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.
the class HP3PARApiFactory method init.
/**
* Initialize HTTP client
*/
public void init() {
_log.info("3PARDriver:HP3PARApiFactory init enter");
_clientMap = new ConcurrentHashMap<String, HP3PARApi>();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
params.setMaxTotalConnections(_maxConn);
params.setTcpNoDelay(true);
params.setConnectionTimeout(_connTimeout);
params.setSoTimeout(_socketConnTimeout);
_connectionManager = new MultiThreadedHttpConnectionManager();
_connectionManager.setParams(params);
// close idle connections immediately
_connectionManager.closeIdleConnections(0);
HttpClient client = new HttpClient(_connectionManager);
client.getParams().setConnectionManagerTimeout(connManagerTimeout);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
return false;
}
});
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080));
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.
the class VPlexApiFactory method init.
/**
* Initialize HTTP client
*/
private void init() {
// Create the VPlex API client map.
_clientMap = new ConcurrentHashMap<String, VPlexApiClient>();
// Setup the connection parameters.
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setMaxTotalConnections(_maxConn);
params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
params.setConnectionTimeout(_connTimeoutMs);
params.setSoTimeout(_socketTimeoutMs);
params.setTcpNoDelay(true);
// Create the HTTP connection manager for managing the set of HTTP
// connections and set the configuration parameters. Also, make sure
// idle connections are closed immediately to prevent a buildup of
// connections in the CLOSE_WAIT state.
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
mgr.setParams(params);
mgr.closeIdleConnections(0);
// Create the HTTP client and set the handler for determining if an
// HttpMethod should be retried after a recoverable exception during
// execution.
HttpClient client = new HttpClient(mgr);
client.getParams().setConnectionManagerTimeout(connManagerTimeout);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
return false;
}
});
// Create the client handler.
_clientHandler = new ApacheHttpClientHandler(client);
// Register the specific for the HTTPS protocol.
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project coprhd-controller by CoprHD.
the class HDSApiFactory method init.
/**
* Initialize HTTP client
*/
public void init() {
// Create the VPlex API client map.
_clientMap = new ConcurrentHashMap<String, HDSApiClient>();
// Setup the connection parameters.
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setMaxTotalConnections(_maxConn);
params.setDefaultMaxConnectionsPerHost(_maxConnPerHost);
params.setConnectionTimeout(_connTimeoutMs);
params.setSoTimeout(socketConnectionTimeoutMs);
params.setTcpNoDelay(true);
// Create the HTTP connection manager for managing the set of HTTP
// connections.
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
mgr.setParams(params);
// close idle connections immediately
mgr.closeIdleConnections(0);
// Create the HTTP client and set the handler for determining if an
// HttpMethod should be retried after a recoverable exception during
// execution.
HttpClient client = new HttpClient(mgr);
client.getParams().setConnectionManagerTimeout(connManagerTimeout);
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() {
@Override
public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) {
return false;
}
});
// Create the client handler.
_clientHandler = new ApacheHttpClientHandler(client);
// Register the specific for the HTTPS protocol.
Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 443));
}
use of org.apache.commons.httpclient.MultiThreadedHttpConnectionManager in project application by collectionspace.
the class ServicesConnection method initClient.
private void initClient() {
if (manager != null)
return;
synchronized (getClass()) {
if (manager != null)
return;
// We're only connecting to one host, so set the max connections per host to be
// the same as the max total connections.
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setMaxTotalConnections(MAX_SERVICES_CONNECTIONS);
params.setDefaultMaxConnectionsPerHost(MAX_SERVICES_CONNECTIONS);
manager = new MultiThreadedHttpConnectionManager();
manager.setParams(params);
}
}
Aggregations