Example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager getParams

List of usage examples for org.apache.commons.httpclient MultiThreadedHttpConnectionManager getParams

Introduction

In this page you can find the example usage for org.apache.commons.httpclient MultiThreadedHttpConnectionManager getParams.

Prototype

public HttpConnectionManagerParams getParams() 

Source Link

Usage

From source file:integration.HeavyLoad.java

public static void main(String[] args) throws IOException {
    url = args[0] + "/create.json";
    final String specFile = args[1];

    for (int i = 2; i < args.length; i++) {
        String server = args[i];//from www  .  j  a  va2  s .  c  om
        servers.add(new ServerStats(server));
    }
    if (servers.isEmpty()) {
        servers.add(new ServerStats(DEFAULT));
    }

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    final HttpConnectionManagerParams params = connectionManager.getParams();
    params.setSoTimeout(TIMEOUT);
    params.setConnectionTimeout(TIMEOUT);
    params.setDefaultMaxConnectionsPerHost(NB_THREADS);
    params.setMaxTotalConnections(NB_THREADS);

    httpClient = new HttpClient(connectionManager);

    spec = FileUtilities.readWholeTextFile(new File(specFile));

    Thread[] threads = new Thread[NB_THREADS];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(new Reader(), "reader-" + i);
        threads[i].start();
    }
    for (int i = 0; i < threads.length; i++) {
        try {
            threads[i].join();
        } catch (InterruptedException e) {
        }
    }
}

From source file:fr.cls.atoll.motu.library.cas.util.HttpUtil.java

public static MultiThreadedHttpConnectionManager createConnectionManager() {

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(25);
    connectionManager.getParams().setMaxTotalConnections(250);

    return connectionManager;
}

From source file:edu.ucsb.eucalyptus.transport.util.Defaults.java

public static MultiThreadedHttpConnectionManager getDefaultHttpManager() {
    MultiThreadedHttpConnectionManager httpConnMgr = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = httpConnMgr.getParams();
    params.setDefaultMaxConnectionsPerHost(16);
    params.setMaxTotalConnections(16);//from  ww  w  .j a  v a  2s .co  m
    params.setTcpNoDelay(true);
    params.setConnectionTimeout(120 * 1000);
    //    params.setReceiveBufferSize( 8388608 );
    //    params.setSendBufferSize( 8388608 );
    params.setStaleCheckingEnabled(true);
    params.setSoTimeout(120 * 1000);
    //    params.setLinger( -1 );
    return httpConnMgr;
}

From source file:com.smartitengineering.dao.hbase.autoincrement.AutoIncrementRowIdForLongTest.java

@BeforeClass
public static void globalSetup() throws Exception {
    /*/*from   w w  w  . j a v  a 2 s .c o  m*/
     * Start HBase and initialize tables
     */
    //-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
            "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
    try {
        TEST_UTIL.startMiniCluster();
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
    }
    //Create table for testing
    InputStream classpathResource = AutoIncrementRowIdForLongTest.class.getClassLoader()
            .getResourceAsStream("ddl-config-sample1.json");
    Collection<HBaseTableConfiguration> configs = ConfigurationJsonParser.getConfigurations(classpathResource);
    try {
        new HBaseTableGenerator(configs, TEST_UTIL.getConfiguration(), true).generateTables();
    } catch (Exception ex) {
        LOGGER.error("Could not create table!", ex);
        Assert.fail(ex.getMessage());
    }
    pool = new HTablePool(TEST_UTIL.getConfiguration(), 200);
    //Start web app
    jettyServer = new Server(PORT);
    final String webapp = "./src/main/webapp/";
    if (!new File(webapp).exists()) {
        throw new IllegalStateException("WebApp file/dir does not exist!");
    }

    Properties properties = new Properties();
    properties.setProperty(GuiceUtil.CONTEXT_NAME_PROP, "com.smartitengineering.dao.impl.hbase");
    properties.setProperty(GuiceUtil.IGNORE_MISSING_DEP_PROP, Boolean.TRUE.toString());
    properties.setProperty(GuiceUtil.MODULES_LIST_PROP, TestModule.class.getName());
    GuiceUtil.getInstance(properties).register();

    WebAppContext webAppHandler = new WebAppContext(webapp, "/");
    jettyServer.setHandler(webAppHandler);
    jettyServer.setSendDateHeader(true);
    jettyServer.start();
    //Initialize client
    final MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    manager.getParams().setDefaultMaxConnectionsPerHost(THREAD_COUNT);
    manager.getParams().setMaxTotalConnections(THREAD_COUNT);
    httpClient = new HttpClient(manager);
}

From source file:edu.harvard.med.iccbl.screensaver.soaputils.PugSoapUtil.java

private static void updateStub(org.apache.axis2.client.Stub stub, int maxTotal, int maxPerHost) {
    MultiThreadedHttpConnectionManager httpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = httpConnectionManager.getParams();
    if (params == null) {
        params = new HttpConnectionManagerParams();
    }/*from   w  ww.j a va  2 s.c  o  m*/
    params.setMaxTotalConnections(maxTotal);
    params.setDefaultMaxConnectionsPerHost(maxPerHost);
    // extra, not prescribed -sde4
    params.setConnectionTimeout(600000);
    params.setSoTimeout(600000);
    httpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(httpConnectionManager);
    ServiceClient serviceClient = stub._getServiceClient();
    ConfigurationContext context = serviceClient.getServiceContext().getConfigurationContext();
    context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
}

From source file:edu.harvard.i2b2.common.util.axis2.ServiceClient.java

public static String sendREST(String restEPR, OMElement request) throws Exception {

    String response = null;//  w w  w  . j  a v  a 2  s.  c o m
    org.apache.axis2.client.ServiceClient serviceClient = null;
    try {

        serviceClient = new org.apache.axis2.client.ServiceClient();

        ServiceContext context = serviceClient.getServiceContext();
        MultiThreadedHttpConnectionManager connManager = (MultiThreadedHttpConnectionManager) context
                .getProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);

        if (connManager == null) {
            connManager = new MultiThreadedHttpConnectionManager();
            context.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connManager);
            connManager.getParams().setMaxTotalConnections(100);
            connManager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 100);
        }
        HttpClient httpClient = new HttpClient(connManager);

        Options options = new Options();
        options.setTo(new EndpointReference(restEPR));
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
        options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
        serviceClient.setOptions(options);

        OMElement result = serviceClient.sendReceive(request);
        if (result != null) {
            response = result.toString();
            log.debug(response);
        }
    } catch (Exception e) {
        log.debug("Cleanup Error .", e);
        e.printStackTrace();
        throw new I2B2Exception("" + StackTraceUtil.getStackTrace(e));
    } finally {
        if (serviceClient != null) {
            try {
                serviceClient.cleanupTransport();
                serviceClient.cleanup();
            } catch (AxisFault e) {
                log.debug("Error .", e);
            }
        }
    }

    return response;
}

From source file:davmail.http.DavGatewayHttpClientFacade.java

/**
 * Create and set connection pool.//w  w w .ja  va  2s  .  c o m
 *
 * @param httpClient httpClient instance
 */
public static void createMultiThreadedHttpConnectionManager(HttpClient httpClient) {
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(100);
    connectionManager.getParams().setConnectionTimeout(10000);
    synchronized (LOCK) {
        httpConnectionManagerThread.addConnectionManager(connectionManager);
    }
    httpClient.setHttpConnectionManager(connectionManager);
}

From source file:com.cloud.cluster.ClusterServiceServletImpl.java

private HttpClient getHttpClient() {

    if (s_client == null) {
        MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
        mgr.getParams().setDefaultMaxConnectionsPerHost(4);

        // TODO make it configurable
        mgr.getParams().setMaxTotalConnections(1000);

        s_client = new HttpClient(mgr);
        HttpClientParams clientParams = new HttpClientParams();
        clientParams.setSoTimeout(_requestTimeoutSeconds * 1000);

        s_client.setParams(clientParams);
    }//from w w  w.  ja va2  s  .  c  om
    return s_client;
}

From source file:com.twistbyte.affiliate.HttpUtility.java

public HttpUtility() {

    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();

    connectionManager.getParams().setDefaultMaxConnectionsPerHost(50);
    connectionManager.getParams().setMaxTotalConnections(50);

    httpclient = new HttpClient(connectionManager);

    // connect timeout in 8 seconds
    httpclient.getParams().setParameter("http.connection.timeout", new Integer(8000));
    httpclient.getParams().setParameter("http.socket.timeout", new Integer(300000));

    Protocol protocol = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", protocol);
}

From source file:com.google.jstestdriver.requesthandlers.RequestHandlersModule.java

@Provides
@Singleton/*  w ww.  ja  va 2  s .  c  om*/
HttpClient provideHttpClient() {
    Protocol.registerProtocol("https",
            new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443));
    MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
    manager.getParams().setDefaultMaxConnectionsPerHost(20);
    manager.getParams().setMaxTotalConnections(200);
    HttpClient client = new HttpClient(manager);
    client.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    return client;
}