Search in sources :

Example 41 with TransportClientAdapter

use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter in project parseq by linkedin.

the class ParSeqRestClientIntegrationTest method newTransportClient.

private Client newTransportClient(Map<String, ? extends Object> properties) {
    Client client = new TransportClientAdapter(_clientFactory.getClient(properties));
    _transportClients.add(client);
    return client;
}
Also used : TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) Client(com.linkedin.r2.transport.common.Client)

Example 42 with TransportClientAdapter

use of com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter in project incubator-gobblin by apache.

the class SharedRestClientFactory method createResource.

@Override
public SharedResourceFactoryResponse<RestClient> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, SharedRestClientKey> config) throws NotConfiguredException {
    try {
        SharedRestClientKey key = config.getKey();
        if (!(key instanceof UriRestClientKey)) {
            return new ResourceCoordinate<>(this, new UriRestClientKey(key.serviceName, resolveUriPrefix(config.getConfig(), key)), config.getScope());
        }
        String uriPrefix = ((UriRestClientKey) key).getUri();
        log.info(String.format("Creating a brand new rest client for service name %s and uri prefix %s", key.serviceName, uriPrefix));
        HttpClientFactory http = new HttpClientFactory(FilterChains.empty(), new NioEventLoopGroup(0, /* use default settings */
        ExecutorsUtils.newDaemonThreadFactory(Optional.<Logger>absent(), Optional.of("R2 Nio Event Loop-%d"))), true, Executors.newSingleThreadScheduledExecutor(ExecutorsUtils.newDaemonThreadFactory(Optional.<Logger>absent(), Optional.of("R2 Netty Scheduler"))), true);
        Properties props = ConfigUtils.configToProperties(config.getConfig());
        if (!props.containsKey(HttpClientFactory.HTTP_REQUEST_TIMEOUT)) {
            // Rest.li changed the default timeout from 10s to 1s. Since some clients (e.g. throttling) relied on the longer
            // timeout, override this property uless set by the user explicitly
            props.setProperty(HttpClientFactory.HTTP_REQUEST_TIMEOUT, "10000");
        }
        Client r2Client = new TransportClientAdapter(http.getClient(Maps.fromProperties(props)));
        return new ResourceInstance<>(new RestClient(r2Client, uriPrefix));
    } catch (URISyntaxException use) {
        throw new RuntimeException("Could not create a rest client for key " + Optional.fromNullable(config.getKey().toConfigurationKey()).or("null"));
    }
}
Also used : RestClient(com.linkedin.restli.client.RestClient) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) ResourceInstance(org.apache.gobblin.broker.ResourceInstance) RestClient(com.linkedin.restli.client.RestClient) Client(com.linkedin.r2.transport.common.Client) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ResourceCoordinate(org.apache.gobblin.broker.ResourceCoordinate)

Aggregations

TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)42 HashMap (java.util.HashMap)21 Client (com.linkedin.r2.transport.common.Client)20 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)17 Test (org.testng.annotations.Test)15 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)14 RestRequest (com.linkedin.r2.message.rest.RestRequest)12 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)12 None (com.linkedin.common.util.None)10 FutureCallback (com.linkedin.common.callback.FutureCallback)9 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)9 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 BeforeClass (org.testng.annotations.BeforeClass)9 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)8 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)8 RestClient (com.linkedin.restli.client.RestClient)8 URI (java.net.URI)8 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)7 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)7 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)6