Java 类org.apache.http.nio.conn.NHttpClientConnectionManager 实例源码

项目:java-restclient    文件:IdleAsyncConnectionEvictor.java   
public IdleAsyncConnectionEvictor(
        final NHttpClientConnectionManager connectionManager,
        final ThreadFactory threadFactory,
        final long sleepTime, final TimeUnit sleepTimeUnit,
        final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
    ThreadFactory threadFactory1 = threadFactory != null ? threadFactory : new DefaultThreadFactory();
    this.sleepTimeMs = sleepTimeUnit != null ? sleepTimeUnit.toMillis(sleepTime) : sleepTime;
    this.maxIdleTimeMs = maxIdleTimeUnit != null ? maxIdleTimeUnit.toMillis(maxIdleTime) : maxIdleTime;
    this.thread = threadFactory1.newThread(new Runnable() {
        @Override
        public void run() {
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    Thread.sleep(sleepTimeMs);
                    connectionManager.closeExpiredConnections();
                    if (maxIdleTimeMs > 0) {
                        connectionManager.closeIdleConnections(maxIdleTimeMs, TimeUnit.MILLISECONDS);
                    }
                }
            } catch (final Exception ex) {
                log.warn("Evictor exception", ex);
            }
        }
    });
}
项目:incubator-gobblin    文件:ApacheHttpAsyncClient.java   
private NHttpClientConnectionManager getNHttpConnManager(Config config) throws IOException {
  NHttpClientConnectionManager httpConnManager;

  String connMgrStr = config.getString(HTTP_CONN_MANAGER);
  switch (ApacheHttpClient.ConnManager.valueOf(connMgrStr.toUpperCase())) {
    case POOLING:
      ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
      PoolingNHttpClientConnectionManager poolingConnMgr = new PoolingNHttpClientConnectionManager(ioReactor);
      poolingConnMgr.setMaxTotal(config.getInt(POOLING_CONN_MANAGER_MAX_TOTAL_CONN));
      poolingConnMgr.setDefaultMaxPerRoute(config.getInt(POOLING_CONN_MANAGER_MAX_PER_CONN));
      httpConnManager = poolingConnMgr;
      break;
    default:
      throw new IllegalArgumentException(connMgrStr + " is not supported");
  }

  LOG.info("Using " + httpConnManager.getClass().getSimpleName());
  return httpConnManager;
}
项目:java-restclient    文件:IdleAsyncConnectionEvictor.java   
public IdleAsyncConnectionEvictor(
        final NHttpClientConnectionManager connectionManager,
        final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
    this(connectionManager, null,
            maxIdleTime > 0 ? maxIdleTime : 5, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,
            maxIdleTime, maxIdleTimeUnit);
}
项目:httpclientutil    文件:NIdleConnectionEvictor.java   
public NIdleConnectionEvictor(
        final NHttpClientConnectionManager connMgr,
        final ThreadFactory threadFactory,
        final long sleepTime, final TimeUnit sleepTimeUnit,
        final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
    //this.connMgr = Args.notNull(connMgr, "Connection manager");
    this.connMgr = connMgr;
    this.threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory();
    this.sleepTimeMs = sleepTimeUnit != null ? sleepTimeUnit.toMillis(sleepTime) : sleepTime;
    this.maxIdleTimeMs = maxIdleTimeUnit != null ? maxIdleTimeUnit.toMillis(maxIdleTime) : maxIdleTime;
    this.thread = this.threadFactory.newThread(new Runnable() {
        @Override
        public void run() {
            try {
                while (!Thread.currentThread().isInterrupted()) {
                    Thread.sleep(sleepTimeMs);
                    connMgr.closeExpiredConnections();
                    if (maxIdleTimeMs > 0) {
                        connMgr.closeIdleConnections(maxIdleTimeMs, TimeUnit.MILLISECONDS);
                    }
                }
            } catch (Exception ex) {
                exception = ex;
            }

        }
    });
}
项目:httpclientutil    文件:NIdleConnectionEvictor.java   
public NIdleConnectionEvictor(
        final NHttpClientConnectionManager connMgr,
        final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
    this(connMgr, null,
            maxIdleTime > 0 ? maxIdleTime : 5, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,
            maxIdleTime, maxIdleTimeUnit);
}
项目:bce-sdk-java    文件:BceHttpClient.java   
/**
 * Create connection manager for asynchronous http client.
 *
 * @return Connection manager for asynchronous http client.
 * @throws IOReactorException in case if a non-recoverable I/O error.
 */
protected NHttpClientConnectionManager createNHttpClientConnectionManager() throws IOReactorException {
    ConnectingIOReactor ioReactor =
            new DefaultConnectingIOReactor(IOReactorConfig.custom()
                    .setSoTimeout(this.config.getSocketTimeoutInMillis()).setTcpNoDelay(true).build());
    PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager(ioReactor);
    connectionManager.setDefaultMaxPerRoute(this.config.getMaxConnections());
    connectionManager.setMaxTotal(this.config.getMaxConnections());
    return connectionManager;
}
项目:bce-sdk-java    文件:BceHttpClient.java   
/**
 * Create asynchronous http client based on connection manager.
 *
 * @param connectionManager Asynchronous http client connection manager.
 * @return Asynchronous http client based on connection manager.
 */
protected CloseableHttpAsyncClient createHttpAsyncClient(NHttpClientConnectionManager connectionManager) {
    HttpAsyncClientBuilder builder = HttpAsyncClients.custom().setConnectionManager(connectionManager);

    int socketBufferSizeInBytes = this.config.getSocketBufferSizeInBytes();
    if (socketBufferSizeInBytes > 0) {
        builder.setDefaultConnectionConfig(
                ConnectionConfig.custom().setBufferSize(socketBufferSizeInBytes).build());
    }
    return builder.build();
}
项目:saki-monkey    文件:MandrillAsyncClient.java   
/**
 * Factory method for Apache HttpAsyncClient
 * 
 * @return
 */
protected CloseableHttpAsyncClient createHttpAsyncClient() {

    log.info("Creating HttpAsyncClient");
    HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();

    clientBuilder.setSSLStrategy(createSSLIOSessionStrategy());

    /*
     * defaultMaxPerRoute and maxTotal will be overridden by connection manager
     * if it is set.
     */
    ConnectionSettings connSettings = createConnectionSettings();
    clientBuilder.setConnectionManagerShared(connSettings.shared);
    clientBuilder.setMaxConnPerRoute(connSettings.defaultMaxPerRoute);
    clientBuilder.setMaxConnTotal(connSettings.maxTotal);

    NHttpClientConnectionManager connectionManager = createConnectionManager();
    if(connectionManager != null){
        log.info("Connection manager is set");
        clientBuilder.setConnectionManager(connectionManager);
    }

    HttpHost proxy = detectHttpProxy();
    if (proxy != null) {

        clientBuilder.setProxy(proxy);

        CredentialsProvider credsProvider = createDefaultCredentialsProvider(
                proxy.getHostName(), proxy.getPort());
        if (credsProvider != null) {
            clientBuilder.setDefaultCredentialsProvider(credsProvider);
        }
    }
    String userAgent = getUserAgent();
    log.debug("User-Agent: {}", userAgent);
    clientBuilder.setUserAgent(userAgent);
    clientBuilder.setDefaultRequestConfig(createDefaultRequestConfig());
    return clientBuilder.build();
}
项目:java-restclient    文件:IdleAsyncConnectionEvictor.java   
public IdleAsyncConnectionEvictor(
        final NHttpClientConnectionManager connectionManager,
        final long sleepTime, final TimeUnit sleepTimeUnit,
        final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
    this(connectionManager, null, sleepTime, sleepTimeUnit, maxIdleTime, maxIdleTimeUnit);
}
项目:yunpian-java-sdk    文件:AsyncClientEvictExpiredConnections.java   
public IdleConnectionEvictor(NHttpClientConnectionManager connMgr) {
    super();
    this.connMgr = connMgr;
}
项目:aliyun-tablestore-java-sdk    文件:AsyncServiceClient.java   
public IdleConnectionEvictor(NHttpClientConnectionManager connMgr,
        long closePeriod) {
    this.connMgr = connMgr;
    this.closePeriod = closePeriod;
}
项目:Android-Studio-Translate-Tool    文件:AsyncClientEvictExpiredConnections.java   
public IdleConnectionEvictor(NHttpClientConnectionManager connMgr) {
    super();
    this.connMgr = connMgr;
}
项目:httpclientutil    文件:NIdleConnectionEvictor.java   
public NIdleConnectionEvictor(
        final NHttpClientConnectionManager connMgr,
        final long sleepTime, final TimeUnit sleepTimeUnit,
        final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
    this(connMgr, null, sleepTime, sleepTimeUnit, maxIdleTime, maxIdleTimeUnit);
}
项目:httpclientutil    文件:NIdleConnectionEvictor.java   
public NIdleConnectionEvictor setConnMgr(final NHttpClientConnectionManager connMgr){
    this.connMgr = Args.notNull(connMgr, "Connection manager");     
    return this;
}
项目:saki-monkey    文件:MandrillAsyncClient.java   
/**
 * Implement this to override connection manager settings
 * @return
 */
protected NHttpClientConnectionManager createConnectionManager() {
    return null;
}