Search in sources :

Example 1 with ChannelPoolManagerKey

use of com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey in project rest.li by linkedin.

the class TestEventChannelPoolManagerFactory method testBuildChannelPoolManagers.

@Test
public void testBuildChannelPoolManagers() {
    ChannelPoolManagerFactory channelPoolManagerFactory = getChannelPoolManagerFactory();
    EventProviderRegistry eventProviderRegistry = mock(EventProviderRegistry.class);
    ChannelPoolManagerKey anyChannelPoolManagerKey = mock(ChannelPoolManagerKey.class);
    EventAwareChannelPoolManagerFactory factory = new EventAwareChannelPoolManagerFactory(channelPoolManagerFactory, eventProviderRegistry);
    ChannelPoolManager actualRestManager = factory.buildRest(anyChannelPoolManagerKey);
    ChannelPoolManager actualStreamManager = factory.buildStream(anyChannelPoolManagerKey);
    ChannelPoolManager actualHttp2StreamManager = factory.buildHttp2Stream(anyChannelPoolManagerKey);
    // Expects event provider to have been registered for three times and none is unregistered
    verify(eventProviderRegistry, times(3)).registerChannelPoolEventProvider(any());
    verify(eventProviderRegistry, times(0)).unregisterChannelPoolEventProvider(any());
    actualRestManager.shutdown(Callbacks.empty(), mock(Runnable.class), mock(Runnable.class), 0L);
    actualStreamManager.shutdown(Callbacks.empty(), mock(Runnable.class), mock(Runnable.class), 0L);
    actualHttp2StreamManager.shutdown(Callbacks.empty(), mock(Runnable.class), mock(Runnable.class), 0L);
    // Expects event provider to have been registered for three times and unregistered for three times
    verify(eventProviderRegistry, times(3)).registerChannelPoolEventProvider(any());
    verify(eventProviderRegistry, times(3)).unregisterChannelPoolEventProvider(any());
}
Also used : EventProviderRegistry(com.linkedin.r2.event.EventProviderRegistry) Test(org.testng.annotations.Test)

Example 2 with ChannelPoolManagerKey

use of com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey in project rest.li by linkedin.

the class TestChannelPoolManagerKey method testReturnCorrectIdleTimeout.

/**
 * checks if getIdleTimeout() returns SSL timeout in case of SSL client, and normal timeout in case of NON SSL client
 */
@Test
public void testReturnCorrectIdleTimeout() throws NoSuchAlgorithmException {
    ChannelPoolManagerKey SSLKey = getKeyBuilder().setSSLContext(SSLContext.getDefault()).setSSLParameters(new SSLParameters()).build();
    Assert.assertEquals(SSL_IDLE_TIMEOUT, SSLKey.getIdleTimeout());
    ChannelPoolManagerKey plainKey = getKeyBuilder().build();
    Assert.assertEquals(IDLE_TIMEOUT, plainKey.getIdleTimeout());
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) ChannelPoolManagerKey(com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey) Test(org.testng.annotations.Test)

Example 3 with ChannelPoolManagerKey

use of com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey in project rest.li by linkedin.

the class HttpClientFactory method getRawClient.

TransportClient getRawClient(Map<String, ? extends Object> properties, SSLContext sslContext, SSLParameters sslParameters) {
    // key which identifies and contains the set of transport properties to create a channel pool manager
    ChannelPoolManagerKey key = createChannelPoolManagerKey(properties, null, null);
    ChannelPoolManagerKey sslKey = createChannelPoolManagerKey(properties, sslContext, sslParameters);
    // Raw Client properties
    int shutdownTimeout = chooseNewOverDefault(getIntValue(properties, HTTP_SHUTDOWN_TIMEOUT), DEFAULT_SHUTDOWN_TIMEOUT);
    int requestTimeout = chooseNewOverDefault(getIntValue(properties, HTTP_REQUEST_TIMEOUT), DEFAULT_REQUEST_TIMEOUT);
    int streamingTimeout = chooseNewOverDefault(getIntValue(properties, HTTP_STREAMING_TIMEOUT), DEFAULT_STREAMING_TIMEOUT);
    if (streamingTimeout > DEFAULT_STREAMING_TIMEOUT) {
        // Minimum value for idle timeout so we don't have a busy thread checking for idle timeout too frequently!
        if (streamingTimeout < DEFAULT_MINIMUM_STREAMING_TIMEOUT) {
            streamingTimeout = DEFAULT_MINIMUM_STREAMING_TIMEOUT;
            LOG.warn("Streaming timeout is too small, resetting to the minimum allowed timeout value of {}ms", DEFAULT_MINIMUM_STREAMING_TIMEOUT);
        }
    }
    String httpServiceName = (String) properties.get(HTTP_SERVICE_NAME);
    HttpProtocolVersion httpProtocolVersion = chooseNewOverDefault(getHttpProtocolVersion(properties, HTTP_PROTOCOL_VERSION), _defaultHttpVersion);
    LOG.info("The service '{}' has been assigned to the ChannelPoolManager with key '{}', http.protocolVersion={}, usePipelineV2={}, requestTimeout={}ms, streamingTimeout={}ms", httpServiceName, key.getName(), httpProtocolVersion, _usePipelineV2, requestTimeout, streamingTimeout);
    if (_usePipelineV2) {
        ChannelPoolManager channelPoolManager;
        ChannelPoolManager sslChannelPoolManager;
        switch(httpProtocolVersion) {
            case HTTP_1_1:
                channelPoolManager = _channelPoolManagerFactory.buildStream(key);
                sslChannelPoolManager = _channelPoolManagerFactory.buildStream(sslKey);
                break;
            case HTTP_2:
                channelPoolManager = _channelPoolManagerFactory.buildHttp2Stream(key);
                sslChannelPoolManager = _channelPoolManagerFactory.buildHttp2Stream(sslKey);
                break;
            default:
                throw new IllegalArgumentException("Unrecognized HTTP protocol version " + httpProtocolVersion);
        }
        return new com.linkedin.r2.netty.client.HttpNettyClient(_eventLoopGroup, _executor, _callbackExecutorGroup, channelPoolManager, sslChannelPoolManager, httpProtocolVersion, SystemClock.instance(), requestTimeout, streamingTimeout, shutdownTimeout);
    }
    TransportClient streamClient;
    switch(httpProtocolVersion) {
        case HTTP_1_1:
            streamClient = new HttpNettyStreamClient(_eventLoopGroup, _executor, requestTimeout, shutdownTimeout, _callbackExecutorGroup, _jmxManager, _channelPoolManagerFactory.buildStream(key), _channelPoolManagerFactory.buildStream(sslKey));
            break;
        case HTTP_2:
            streamClient = new Http2NettyStreamClient(_eventLoopGroup, _executor, requestTimeout, shutdownTimeout, _callbackExecutorGroup, _jmxManager, _channelPoolManagerFactory.buildHttp2Stream(key), _channelPoolManagerFactory.buildHttp2Stream(sslKey));
            break;
        default:
            throw new IllegalArgumentException("Unrecognized HTTP protocol version " + httpProtocolVersion);
    }
    HttpNettyClient legacyClient = new HttpNettyClient(_eventLoopGroup, _executor, requestTimeout, shutdownTimeout, _callbackExecutorGroup, _jmxManager, _channelPoolManagerFactory.buildRest(key), _channelPoolManagerFactory.buildRest(sslKey));
    return new MixedClient(legacyClient, streamClient);
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) HttpProtocolVersion(com.linkedin.r2.transport.http.common.HttpProtocolVersion) ChannelPoolManager(com.linkedin.r2.transport.http.client.common.ChannelPoolManager) HttpNettyClient(com.linkedin.r2.transport.http.client.rest.HttpNettyClient) HttpNettyStreamClient(com.linkedin.r2.transport.http.client.stream.http.HttpNettyStreamClient) Http2NettyStreamClient(com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamClient) ChannelPoolManagerKey(com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey)

Example 4 with ChannelPoolManagerKey

use of com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey in project rest.li by linkedin.

the class ChannelPoolManagerFactoryImpl method buildHttp2Stream.

@Override
public ChannelPoolManager buildHttp2Stream(ChannelPoolManagerKey channelPoolManagerKey) {
    DefaultChannelGroup channelGroup = new DefaultChannelGroup("R2 client channels", _eventLoopGroup.next());
    ChannelPoolFactory channelPoolFactory;
    if (_usePipelineV2) {
        channelPoolFactory = new Http2ChannelPoolFactory(_scheduler, _eventLoopGroup, channelGroup, channelPoolManagerKey.getStrategy(), channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getMaxPoolSize(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.getPoolWaiterSize(), MAX_INITIAL_LINE_LENGTH, channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getMaxResponseSize(), channelPoolManagerKey.isTcpNoDelay(), _enableSSLSessionResumption, _connectTimeout, _sslHandShakeTimeout);
    } else {
        channelPoolFactory = new Http2NettyStreamChannelPoolFactory(channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getPoolWaiterSize(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.isTcpNoDelay(), _scheduler, channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getGracefulShutdownTimeout(), channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getMaxResponseSize(), _enableSSLSessionResumption, _eventLoopGroup, channelGroup, _connectTimeout, _sslHandShakeTimeout);
    }
    return new ChannelPoolManagerImpl(channelPoolFactory, channelPoolManagerKey.getName() + "-HTTP/2-Stream", channelGroup, _scheduler);
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) HttpNettyStreamChannelPoolFactory(com.linkedin.r2.transport.http.client.stream.http.HttpNettyStreamChannelPoolFactory) HttpChannelPoolFactory(com.linkedin.r2.netty.client.http.HttpChannelPoolFactory) Http2NettyStreamChannelPoolFactory(com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamChannelPoolFactory) Http2ChannelPoolFactory(com.linkedin.r2.netty.client.http2.Http2ChannelPoolFactory) HttpNettyChannelPoolFactory(com.linkedin.r2.transport.http.client.rest.HttpNettyChannelPoolFactory) Http2NettyStreamChannelPoolFactory(com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamChannelPoolFactory) Http2ChannelPoolFactory(com.linkedin.r2.netty.client.http2.Http2ChannelPoolFactory)

Example 5 with ChannelPoolManagerKey

use of com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey in project rest.li by linkedin.

the class ChannelPoolManagerFactoryImpl method buildStream.

@Override
public ChannelPoolManager buildStream(ChannelPoolManagerKey channelPoolManagerKey) {
    DefaultChannelGroup channelGroup = new DefaultChannelGroup("R2 client channels", _eventLoopGroup.next());
    ChannelPoolFactory channelPoolFactory;
    if (_usePipelineV2) {
        channelPoolFactory = new HttpChannelPoolFactory(_scheduler, _eventLoopGroup, channelGroup, channelPoolManagerKey.getStrategy(), channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getMaxPoolSize(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.getPoolWaiterSize(), MAX_INITIAL_LINE_LENGTH, channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getMaxConcurrentConnectionInitializations(), channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getMaxResponseSize(), channelPoolManagerKey.isTcpNoDelay(), _enableSSLSessionResumption, _channelPoolWaiterTimeout, _connectTimeout, _sslHandShakeTimeout);
    } else {
        channelPoolFactory = new HttpNettyStreamChannelPoolFactory(channelPoolManagerKey.getMaxPoolSize(), channelPoolManagerKey.getIdleTimeout(), channelPoolManagerKey.getPoolWaiterSize(), channelPoolManagerKey.getStrategy(), channelPoolManagerKey.getMinPoolSize(), channelPoolManagerKey.isTcpNoDelay(), _scheduler, channelPoolManagerKey.getMaxConcurrentConnectionInitializations(), channelPoolManagerKey.getSslContext(), channelPoolManagerKey.getSslParameters(), channelPoolManagerKey.getMaxHeaderSize(), channelPoolManagerKey.getMaxChunkSize(), channelPoolManagerKey.getMaxResponseSize(), _enableSSLSessionResumption, _eventLoopGroup, channelGroup, _channelPoolWaiterTimeout, _connectTimeout, _sslHandShakeTimeout);
    }
    return new ChannelPoolManagerImpl(channelPoolFactory, channelPoolManagerKey.getName() + "-Stream", channelGroup, _scheduler);
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) HttpNettyStreamChannelPoolFactory(com.linkedin.r2.transport.http.client.stream.http.HttpNettyStreamChannelPoolFactory) HttpChannelPoolFactory(com.linkedin.r2.netty.client.http.HttpChannelPoolFactory) Http2NettyStreamChannelPoolFactory(com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamChannelPoolFactory) Http2ChannelPoolFactory(com.linkedin.r2.netty.client.http2.Http2ChannelPoolFactory) HttpNettyChannelPoolFactory(com.linkedin.r2.transport.http.client.rest.HttpNettyChannelPoolFactory) HttpChannelPoolFactory(com.linkedin.r2.netty.client.http.HttpChannelPoolFactory) HttpNettyStreamChannelPoolFactory(com.linkedin.r2.transport.http.client.stream.http.HttpNettyStreamChannelPoolFactory)

Aggregations

ChannelPoolManagerKey (com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKey)4 Test (org.testng.annotations.Test)4 ChannelPoolManager (com.linkedin.r2.transport.http.client.common.ChannelPoolManager)3 ChannelPoolManagerKeyBuilder (com.linkedin.r2.transport.http.client.common.ChannelPoolManagerKeyBuilder)3 FutureCallback (com.linkedin.common.callback.FutureCallback)2 None (com.linkedin.common.util.None)2 HttpChannelPoolFactory (com.linkedin.r2.netty.client.http.HttpChannelPoolFactory)2 Http2ChannelPoolFactory (com.linkedin.r2.netty.client.http2.Http2ChannelPoolFactory)2 ChannelPoolManagerFactoryImpl (com.linkedin.r2.transport.http.client.common.ChannelPoolManagerFactoryImpl)2 HttpNettyChannelPoolFactory (com.linkedin.r2.transport.http.client.rest.HttpNettyChannelPoolFactory)2 HttpNettyStreamChannelPoolFactory (com.linkedin.r2.transport.http.client.stream.http.HttpNettyStreamChannelPoolFactory)2 Http2NettyStreamChannelPoolFactory (com.linkedin.r2.transport.http.client.stream.http2.Http2NettyStreamChannelPoolFactory)2 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 EventProviderRegistry (com.linkedin.r2.event.EventProviderRegistry)1 HttpServerBuilder (com.linkedin.r2.testutils.server.HttpServerBuilder)1 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)1 HttpNettyClient (com.linkedin.r2.transport.http.client.rest.HttpNettyClient)1