Java 类com.amazonaws.http.IdleConnectionReaper 实例源码

项目:elasticsearch_my    文件:AwsEc2ServiceImpl.java   
@Override
public void close() throws IOException {
    if (client != null) {
        client.shutdown();
    }

    // Ensure that IdleConnectionReaper is shutdown
    IdleConnectionReaper.shutdown();
}
项目:elasticsearch_my    文件:InternalAwsS3Service.java   
@Override
protected void doClose() throws ElasticsearchException {
    for (AmazonS3Client client : clients.values()) {
        client.shutdown();
    }

    // Ensure that IdleConnectionReaper is shutdown
    IdleConnectionReaper.shutdown();
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClientTest.java   
/**
 * A memory leak was introduced in 1.11 that prevented connection managers from being
 * deregistered with the IdleConnectionReaper. This test asserts that any clients registered
 * with the reaper are also deregistered on shutdown of the client.
 *
 * @see <a href="https://github.com/aws/aws-sdk-java/issues/722">Issue #722</a>
 */
@Test
public void connectionManagersAreUnregisteredFromIdleConnectionReaper() {
    // Clears out the IdleConnectionReaper. This is helpful when there are open registered connections from previous tests.
    IdleConnectionReaper.shutdown();
    for (int count = 0; count < 100; count++) {
        new AmazonWebServiceClient(new ClientConfiguration()) {
        }.shutdown();
    }
    assertEquals(0, IdleConnectionReaper.getRegisteredConnectionManagers().size());
}
项目:ibm-cos-sdk-java    文件:ApacheHttpClientFactory.java   
@Override
public ConnectionManagerAwareHttpClient create(HttpClientSettings settings) {
    final HttpClientBuilder builder = HttpClients.custom();
    // Note that it is important we register the original connection manager with the
    // IdleConnectionReaper as it's required for the successful deregistration of managers
    // from the reaper. See https://github.com/aws/aws-sdk-java/issues/722.
    final HttpClientConnectionManager cm = cmFactory.create(settings);

    builder.setRequestExecutor(new SdkHttpRequestExecutor())
            .setKeepAliveStrategy(buildKeepAliveStrategy(settings))
            .disableRedirectHandling()
            .disableAutomaticRetries()
            .setConnectionManager(ClientConnectionManagerFactory.wrap(cm));

    // By default http client enables Gzip compression. So we disable it
    // here.
    // Apache HTTP client removes Content-Length, Content-Encoding and
    // Content-MD5 headers when Gzip compression is enabled. Currently
    // this doesn't affect S3 or Glacier which exposes these headers.
    //
    if (!(settings.useGzip())) {
        builder.disableContentCompression();
    }

    HttpResponseInterceptor itcp = new CRC32ChecksumResponseInterceptor();
    if (settings.calculateCRC32FromCompressedData()) {
        builder.addInterceptorFirst(itcp);
    } else {
        builder.addInterceptorLast(itcp);
    }

    addProxyConfig(builder, settings);

    final ConnectionManagerAwareHttpClient httpClient = new SdkHttpClient(builder.build(), cm);

    if (settings.useReaper()) {
        IdleConnectionReaper.registerConnectionManager(cm, settings.getMaxIdleConnectionTime());
    }

    return httpClient;
}