Example usage for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager

List of usage examples for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn PoolingHttpClientConnectionManager PoolingHttpClientConnectionManager.

Prototype

public PoolingHttpClientConnectionManager() 

Source Link

Usage

From source file:io.seldon.external.ExternalPredictionServer.java

@Autowired
public ExternalPredictionServer(GlobalConfigHandler globalConfigHandler, ClientRpcStore rpcStore) {
    cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(150);// www.  j av  a  2s . c  o m
    cm.setDefaultMaxPerRoute(150);

    RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(DEFAULT_REQ_TIMEOUT)
            .setConnectTimeout(DEFAULT_CON_TIMEOUT).setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();

    httpClient = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(requestConfig).build();
    globalConfigHandler.addSubscriber(ZK_CONFIG_TEMP, this);
    this.rpcStore = rpcStore;
}

From source file:com.collaide.fileuploader.requests.repository.FilesRequest.java

public CloseableHttpClient getHttpClient() {
    if (httpClient == null) {
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
        cm.setMaxTotal(getMaxConnection());
        httpClient = HttpClients.custom().setConnectionManager(cm).build();
    }//from ww w .  j a v  a  2  s . c  o m
    return httpClient;
}

From source file:org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientSpnegoImpl.java

/**
 * Constructs an HTTP client with user specified by the given credentials.
 *
 * @param url The URL for the Avatica server
 * @param credential The GSS credentials
 *//*from w  w w. j a  v a 2  s . c  o  m*/
public AvaticaCommonsHttpClientSpnegoImpl(URL url, GSSCredential credential) {
    this.url = Objects.requireNonNull(url);

    pool = new PoolingHttpClientConnectionManager();
    // Increase max total connection to 100
    final String maxCnxns = System.getProperty(CACHED_CONNECTIONS_MAX_KEY, CACHED_CONNECTIONS_MAX_DEFAULT);
    pool.setMaxTotal(Integer.parseInt(maxCnxns));
    // Increase default max connection per route to 25
    final String maxCnxnsPerRoute = System.getProperty(CACHED_CONNECTIONS_MAX_PER_ROUTE_KEY,
            CACHED_CONNECTIONS_MAX_PER_ROUTE_DEFAULT);
    pool.setDefaultMaxPerRoute(Integer.parseInt(maxCnxnsPerRoute));

    this.host = new HttpHost(url.getHost(), url.getPort());

    this.authRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO,
            new SPNegoSchemeFactory(STRIP_PORT_ON_SERVER_LOOKUP, USE_CANONICAL_HOSTNAME)).build();

    this.credentialsProvider = new BasicCredentialsProvider();
    if (null != credential) {
        // Non-null credential should be used directly with KerberosCredentials.
        this.credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential));
    } else {
        // A null credential implies that the user is logged in via JAAS using the
        // java.security.auth.login.config system property
        this.credentialsProvider.setCredentials(AuthScope.ANY, EmptyCredentials.INSTANCE);
    }

    this.authCache = new BasicAuthCache();

    // A single thread-safe HttpClient, pooling connections via the ConnectionManager
    this.client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).setConnectionManager(pool)
            .build();
}

From source file:org.glassfish.jersey.apache.connector.HttpMethodTest.java

protected Client createPoolingClient() {
    ClientConfig cc = new ClientConfig();
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(100);/* www .  j  a  v a2  s  .  co m*/
    connectionManager.setDefaultMaxPerRoute(100);
    cc.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
    cc.connectorProvider(new ApacheConnectorProvider());
    return ClientBuilder.newClient(cc);
}

From source file:org.qucosa.camel.component.fcrepo3.Fcrepo3APIAccess.java

public Fcrepo3APIAccess(String host, String port, String user, String password) {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));

    this.host = host;
    this.port = port;

    httpClient = HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager())
            .setDefaultCredentialsProvider(credentialsProvider).build();
}

From source file:org.nebula.framework.client.NebulaRestClient.java

public NebulaRestClient(String accessId, String secretKey, String hostname, int port, String contextPath,
        int connectionTimeoutInSecs, int socketTimeoutInSecs, int maxTotalConnections) {
    this.accessId = accessId;
    this.secretKey = secretKey;
    this.target = new HttpHost(hostname, port);

    requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionTimeoutInSecs * 1000)
            .setConnectTimeout(connectionTimeoutInSecs * 1000).setSocketTimeout(socketTimeoutInSecs * 1000)
            .build();/*w  w w.  j  a  v  a2 s  . co  m*/

    requestMapper = new RequestMapper(contextPath);

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(maxTotalConnections);
    cm.setDefaultMaxPerRoute(maxTotalConnections);
    client = HttpClientBuilder.create().setConnectionManager(cm).build();

}

From source file:com.marand.thinkmed.medications.connector.impl.rest.RestMedicationsConnector.java

@Override
public void afterPropertiesSet() throws Exception {
    final HttpClientContext context = HttpClientContext.create();
    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, port),
            new UsernamePasswordCredentials(username, password));
    context.setCredentialsProvider(credentialsProvider);

    final ResteasyClient client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(
            HttpClientBuilder.create().setConnectionManager(new PoolingHttpClientConnectionManager()).build(),
            context)).build();// www  .  j  a va2 s  .  c o  m
    final ResteasyWebTarget target = client.target(restUri);
    restClient = target.proxy(MedicationsConnectorRestClient.class);
}

From source file:com.kugou.opentsdb.OpenTsdb.java

private OpenTsdb(String hostname, int port, int connectionTimeout, int connectionRequestTimeout,
        int batchSizeLimit) {
    RequestConfig config = RequestConfig.custom().setConnectTimeout(connectionTimeout)
            .setConnectionRequestTimeout(connectionRequestTimeout).setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .build();/*  ww w  .j a  va2s.  c  om*/

    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setDefaultMaxPerRoute(MAX_CONNECTIONS_PER_ROUTE);
    cm.setMaxTotal(MAX_CONNECTIONS_TOTAL);
    client = HttpClients.custom().setConnectionManager(cm).setDefaultRequestConfig(config).build();
    host = new HttpHost(hostname, port);
    this.batchSizeLimit = batchSizeLimit;
    this.connectionTimeout = connectionTimeout;
    this.connectionRequestTimeout = connectionRequestTimeout;
}

From source file:org.alfresco.provision.TestReleaseDeployInfo.java

public TestReleaseDeployInfo(String bmDriverHostname, String bmDriverPort, String username, String password,
        String warFilename, String bmServerHostname, String bmServerPort, String testName,
        String testDescription) throws Exception {
    int idx1 = warFilename.lastIndexOf("/");
    int idx2 = warFilename.lastIndexOf(".");
    this.release = warFilename.substring(idx1 + 1, idx2);
    this.warFilename = warFilename;
    this.bmDriverHostname = bmDriverHostname;
    this.bmDriverPort = bmDriverPort;
    this.username = username;
    this.password = password;
    this.bmServerHostname = bmServerHostname;
    this.bmServerPort = bmServerPort;
    this.testName = testName;
    this.testDescription = testDescription;
    this.schema = getSchema();

    HttpClientConnectionManager poolingConnManager = new PoolingHttpClientConnectionManager();
    this.client = HttpClients.custom().setConnectionManager(poolingConnManager).build();

    final MongoDbFactory factory = new MongoDbFactory();
    factory.setMongoURI("mongodb://" + bmServerHostname + ":27017");
    factory.setDbName("bm20-config");
    final DB db = factory.createInstance();
    this.testDAO = new MongoTestDAO(db);
}

From source file:org.kaaproject.kaa.server.verifiers.gplus.verifier.GplusUserVerifier.java

@Override
public void start() {
    LOG.info("user verifier started");
    threadPool = new ThreadPoolExecutor(configuration.getMinParallelConnections(),
            configuration.getMaxParallelConnections(), configuration.getKeepAliveTimeMilliseconds(),
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
    connectionManager.setMaxTotal(configuration.getMaxParallelConnections());
    httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();
}