Search in sources :

Example 1 with SdkChannelPool

use of software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool in project aws-sdk-java-v2 by aws.

the class NettyNioAsyncHttpClientWireMockTest method closeClient_shouldCloseUnderlyingResources.

@Test
public void closeClient_shouldCloseUnderlyingResources() {
    SdkEventLoopGroup eventLoopGroup = SdkEventLoopGroup.builder().build();
    SdkChannelPool channelPool = mock(SdkChannelPool.class);
    SdkChannelPoolMap<URI, SdkChannelPool> sdkChannelPoolMap = new SdkChannelPoolMap<URI, SdkChannelPool>() {

        @Override
        protected SdkChannelPool newPool(URI key) {
            return channelPool;
        }
    };
    sdkChannelPoolMap.get(URI.create("http://blah"));
    NettyConfiguration nettyConfiguration = new NettyConfiguration(AttributeMap.empty());
    SdkAsyncHttpClient customerClient = new NettyNioAsyncHttpClient(eventLoopGroup, sdkChannelPoolMap, nettyConfiguration);
    customerClient.close();
    assertThat(eventLoopGroup.eventLoopGroup().isShuttingDown()).isTrue();
    assertThat(eventLoopGroup.eventLoopGroup().isTerminated()).isTrue();
    assertThat(sdkChannelPoolMap).isEmpty();
    Mockito.verify(channelPool).close();
}
Also used : SdkChannelPool(software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool) SdkChannelPoolMap(software.amazon.awssdk.http.nio.netty.internal.SdkChannelPoolMap) NettyConfiguration(software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) URI(java.net.URI) Test(org.junit.Test)

Example 2 with SdkChannelPool

use of software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool in project aws-sdk-java-v2 by aws.

the class HttpOrHttp2ChannelPool method configureProtocol.

private void configureProtocol(Channel newChannel, Protocol protocol) {
    if (Protocol.HTTP1_1 == protocol) {
        // For HTTP/1.1 we use a traditional channel pool without multiplexing
        SdkChannelPool idleConnectionMetricChannelPool = new IdleConnectionCountingChannelPool(eventLoop, delegatePool);
        protocolImpl = BetterFixedChannelPool.builder().channelPool(idleConnectionMetricChannelPool).executor(eventLoop).acquireTimeoutAction(BetterFixedChannelPool.AcquireTimeoutAction.FAIL).acquireTimeoutMillis(configuration.connectionAcquireTimeoutMillis()).maxConnections(maxConcurrency).maxPendingAcquires(configuration.maxPendingConnectionAcquires()).build();
    } else {
        Duration idleConnectionTimeout = configuration.reapIdleConnections() ? Duration.ofMillis(configuration.idleTimeoutMillis()) : null;
        SdkChannelPool h2Pool = new Http2MultiplexedChannelPool(delegatePool, eventLoopGroup, idleConnectionTimeout);
        protocolImpl = BetterFixedChannelPool.builder().channelPool(h2Pool).executor(eventLoop).acquireTimeoutAction(BetterFixedChannelPool.AcquireTimeoutAction.FAIL).acquireTimeoutMillis(configuration.connectionAcquireTimeoutMillis()).maxConnections(maxConcurrency).maxPendingAcquires(configuration.maxPendingConnectionAcquires()).build();
    }
    // Give the channel back so it can be acquired again by protocolImpl
    // Await the release completion to ensure we do not unnecessarily acquire a second channel
    delegatePool.release(newChannel).addListener(runOrPropagate(protocolImplPromise, () -> {
        protocolImplPromise.trySuccess(protocolImpl);
    }));
}
Also used : SdkChannelPool(software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool) IdleConnectionCountingChannelPool(software.amazon.awssdk.http.nio.netty.internal.IdleConnectionCountingChannelPool) Duration(java.time.Duration)

Aggregations

SdkChannelPool (software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool)2 URI (java.net.URI)1 Duration (java.time.Duration)1 Test (org.junit.Test)1 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)1 IdleConnectionCountingChannelPool (software.amazon.awssdk.http.nio.netty.internal.IdleConnectionCountingChannelPool)1 NettyConfiguration (software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration)1 SdkChannelPoolMap (software.amazon.awssdk.http.nio.netty.internal.SdkChannelPoolMap)1