Example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections

List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpConnectionManagerParams setMaxTotalConnections.

Prototype

public void setMaxTotalConnections(int paramInt) 

Source Link

Usage

From source file:org.wso2.carbon.core.init.CarbonServerManager.java

private ConfigurationContext getClientConfigurationContext() throws AxisFault {
    String clientRepositoryLocation = serverConfig.getFirstProperty(CLIENT_REPOSITORY_LOCATION);
    String clientAxis2XmlLocationn = serverConfig.getFirstProperty(CLIENT_AXIS2_XML_LOCATION);
    ConfigurationContext clientConfigContextToReturn = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(clientRepositoryLocation, clientAxis2XmlLocationn);
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    // Set the default max connections per host
    int defaultMaxConnPerHost = 500;
    Parameter defaultMaxConnPerHostParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("defaultMaxConnPerHost");
    if (defaultMaxConnPerHostParam != null) {
        defaultMaxConnPerHost = Integer.parseInt((String) defaultMaxConnPerHostParam.getValue());
    }/*from   w  w  w  .jav a2s .  c o  m*/
    params.setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);

    // Set the max total connections
    int maxTotalConnections = 15000;
    Parameter maxTotalConnectionsParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("maxTotalConnections");
    if (maxTotalConnectionsParam != null) {
        maxTotalConnections = Integer.parseInt((String) maxTotalConnectionsParam.getValue());
    }
    params.setMaxTotalConnections(maxTotalConnections);

    params.setSoTimeout(600000);
    params.setConnectionTimeout(600000);

    httpConnectionManager.setParams(params);
    clientConfigContextToReturn.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER,
            httpConnectionManager);
    registerHouseKeepingTask(clientConfigContextToReturn);
    clientConfigContextToReturn.setProperty(ServerConstants.WORK_DIR, serverWorkDir);
    return clientConfigContextToReturn;
}

From source file:org.wso2.carbon.device.mgt.extensions.remote.session.authentication.oauth.OAuthTokenValidatorStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 *
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 *//*from ww  w .j  a v  a 2 s .  c o m*/
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer
            .parseInt(tokenValidationProperties.get(RemoteSessionConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(Integer
            .parseInt(tokenValidationProperties.get(RemoteSessionConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.device.mgt.input.adapter.http.oauth.OAuthTokenValidaterStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 *
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 *//*from  ww w.  j  a  v a 2  s  .  c o  m*/
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(
            Integer.parseInt(globalProperties.get(HTTPEventAdapterConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(
            Integer.parseInt(globalProperties.get(HTTPEventAdapterConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.device.mgt.iot.input.adapter.http.oauth.OAuthTokenValidaterStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 *
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 */// w ww . j  a v  a2  s .  c  om
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer.parseInt(eventAdapterConfiguration.getProperties()
            .get(HTTPEventAdapterConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(Integer.parseInt(eventAdapterConfiguration.getProperties()
            .get(HTTPEventAdapterConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.device.mgt.iot.output.adapter.ui.authentication.oauth.OAuthTokenValidaterStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 *
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 *//*from w w  w  .  j  a v  a 2s.  co m*/
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer.parseInt(
            tokenValidationProperties.getProperty(WebsocketConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(Integer
            .parseInt(tokenValidationProperties.getProperty(WebsocketConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.device.mgt.mobile.windows.api.common.authenticator.OAuthTokenValidationStubFactory.java

/**
 * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
 *
 * @param properties Properties to configure MultiThreadedHttpConnectionManager
 * @return An instance of properly configured MultiThreadedHttpConnectionManager
 *///  w  ww  . j  a  v  a  2 s .co m
private HttpConnectionManager createConnectionManager(Properties properties) {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    if (properties == null || properties.isEmpty()) {
        throw new IllegalArgumentException("Parameters required to initialize HttpClient instances "
                + "associated with OAuth token validation service stub are not provided");
    }
    String maxConnectionsPerHostParam = properties
            .getProperty(PluginConstants.AuthenticatorProperties.MAX_CONNECTION_PER_HOST);
    if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, "
                    + "which is 2, will be used");
        }
    } else {
        params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
    }

    String maxTotalConnectionsParam = properties
            .getProperty(PluginConstants.AuthenticatorProperties.MAX_TOTAL_CONNECTIONS);
    if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, "
                    + "which is 10, will be used");
        }
    } else {
        params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
    }
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return connectionManager;
}

From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.authentication.oauth.OAuthTokenValidaterStubFactory.java

/**
 * This created httpclient pool that can be used to connect to external entity. This connection can be configured
 * via broker.xml by setting up the required http connection parameters.
 *
 * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager
 *///from   w w w  . j a  va 2  s. c om
private HttpClient createHttpClient() {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(Integer
            .parseInt(tokenValidationProperties.get(WebsocketConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST)));
    params.setMaxTotalConnections(
            Integer.parseInt(tokenValidationProperties.get(WebsocketConstants.MAXIMUM_TOTAL_HTTP_CONNECTION)));
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.mashup.javascript.hostobjects.pooledhttpclient.PooledHttpClientHostObject.java

public PooledHttpClientHostObject() {
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = connectionManager.getParams();
    params.setDefaultMaxConnectionsPerHost(CONN_POOL_THREAD_MAX);
    params.setMaxTotalConnections(CONN_POOL_GLOBAL_MAX);

    this.httpClient = new HttpClient(connectionManager);
}

From source file:org.wso2.carbon.micro.integrator.core.internal.ServiceComponent.java

private ConfigurationContext getClientConfigurationContext() throws AxisFault {
    String clientRepositoryLocation = serverConfig.getFirstProperty(CLIENT_REPOSITORY_LOCATION);
    String clientAxis2XmlLocationn = serverConfig.getFirstProperty(CLIENT_AXIS2_XML_LOCATION);
    ConfigurationContext clientConfigContextToReturn = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(clientRepositoryLocation, clientAxis2XmlLocationn);
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();

    // Set the default max connections per host
    int defaultMaxConnPerHost = 500;
    Parameter defaultMaxConnPerHostParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("defaultMaxConnPerHost");
    if (defaultMaxConnPerHostParam != null) {
        defaultMaxConnPerHost = Integer.parseInt((String) defaultMaxConnPerHostParam.getValue());
    }/*from   w  ww .j ava 2 s  . c om*/
    params.setDefaultMaxConnectionsPerHost(defaultMaxConnPerHost);

    // Set the max total connections
    int maxTotalConnections = 15000;
    Parameter maxTotalConnectionsParam = clientConfigContextToReturn.getAxisConfiguration()
            .getParameter("maxTotalConnections");
    if (maxTotalConnectionsParam != null) {
        maxTotalConnections = Integer.parseInt((String) maxTotalConnectionsParam.getValue());
    }
    params.setMaxTotalConnections(maxTotalConnections);

    params.setSoTimeout(600000);
    params.setConnectionTimeout(600000);

    httpConnectionManager.setParams(params);
    clientConfigContextToReturn.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER,
            httpConnectionManager);
    //        registerHouseKeepingTask(clientConfigContextToReturn);
    clientConfigContextToReturn.setProperty(ServerConstants.WORK_DIR, serverWorkDir);
    return clientConfigContextToReturn;
}

From source file:org.wso2.carbon.webapp.authenticator.framework.Utils.OAuthTokenValidationStubFactory.java

/**
 * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
 *
 * @param properties Properties to configure MultiThreadedHttpConnectionManager
 * @return An instance of properly configured MultiThreadedHttpConnectionManager
 *//*w  ww  .j  a v a 2  s  . c  o m*/
private HttpConnectionManager createConnectionManager(Properties properties) {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    if (properties == null || properties.isEmpty()) {
        throw new IllegalArgumentException("Parameters required to initialize HttpClient instances "
                + "associated with OAuth token validation service stub are not provided");
    }
    String maxConnectionsPerHostParam = properties.getProperty("MaxConnectionsPerHost");
    if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, "
                    + "which is 2, will be used");
        }
    } else {
        params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
    }

    String maxTotalConnectionsParam = properties.getProperty("MaxTotalConnections");
    if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, "
                    + "which is 10, will be used");
        }
    } else {
        params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
    }
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return connectionManager;
}