Search in sources :

Example 21 with TransportClientAdapter

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

the class PerfClients method httpPureStream.

public static PerfClient httpPureStream(URI uri, int numThreads, int numMsgs, int msgSize, int numHeaders, int headerSize) {
    final TransportClient transportClient = FACTORY.getClient(Collections.<String, String>emptyMap());
    final Client client = new TransportClientAdapter(transportClient, true);
    final Generator<StreamRequest> reqGen = new StreamRequestGenerator(uri, numMsgs, msgSize, numHeaders, headerSize);
    final ClientRunnableFactory crf = new StreamClientRunnableFactory(client, reqGen);
    return new FactoryClient(crf, numThreads);
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) Client(com.linkedin.r2.transport.common.Client) StreamRequest(com.linkedin.r2.message.stream.StreamRequest)

Example 22 with TransportClientAdapter

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

the class SimpleLoadBalancerStrawMan method main.

public static void main(String[] args) throws URISyntaxException, ServiceUnavailableException {
    // define the load balancing strategies that we support (round robin, etc)
    Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories = new HashMap<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>>();
    loadBalancerStrategyFactories.put("rr", new RandomLoadBalancerStrategyFactory());
    loadBalancerStrategyFactories.put("degrader", new DegraderLoadBalancerStrategyFactoryV3());
    // define the clients that we support (http, etc)
    Map<String, TransportClientFactory> clientFactories = new HashMap<String, TransportClientFactory>();
    clientFactories.put("http", new HttpClientFactory());
    // listen for service updates (could be a glu discovery client, zk discovery client,
    // config discovery client, etc)
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    MockStore<ServiceProperties> serviceRegistry = new MockStore<ServiceProperties>();
    MockStore<ClusterProperties> clusterRegistry = new MockStore<ClusterProperties>();
    MockStore<UriProperties> uriRegistry = new MockStore<UriProperties>();
    SimpleLoadBalancerState state = new SimpleLoadBalancerState(executorService, uriRegistry, clusterRegistry, serviceRegistry, clientFactories, loadBalancerStrategyFactories);
    // create the load balancer
    SimpleLoadBalancer loadBalancer = new SimpleLoadBalancer(state);
    final TransportClient tc = loadBalancer.getClient(new URIRequest("d2://browsemaps/52"), new RequestContext());
    final Client c = new TransportClientAdapter(tc, true);
    c.restRequest(null);
}
Also used : HashMap(java.util.HashMap) DegraderLoadBalancerStrategyFactoryV3(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3) MockStore(com.linkedin.d2.discovery.stores.mock.MockStore) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) RequestContext(com.linkedin.r2.message.RequestContext) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) Client(com.linkedin.r2.transport.common.Client) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) LoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) RandomLoadBalancerStrategyFactory(com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory) URIRequest(com.linkedin.d2.balancer.util.URIRequest) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 23 with TransportClientAdapter

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

the class TestMIMEChainingMultipleSources method setup.

@BeforeMethod
public void setup() throws IOException {
    _latch = new CountDownLatch(2);
    _clientFactory = new HttpClientFactory();
    _client = new TransportClientAdapter(_clientFactory.getClient(Collections.<String, String>emptyMap()));
    _server_A_client = new TransportClientAdapter(_clientFactory.getClient(Collections.<String, String>emptyMap()));
    final HttpServerFactory httpServerFactory = new HttpServerFactory();
    final ServerARequestHandler serverARequestHandler = new ServerARequestHandler();
    final TransportDispatcher serverATransportDispatcher = new TransportDispatcherBuilder().addStreamHandler(SERVER_A_URI, serverARequestHandler).build();
    final ServerBRequestHandler serverBRequestHandler = new ServerBRequestHandler();
    final TransportDispatcher serverBTransportDispatcher = new TransportDispatcherBuilder().addStreamHandler(SERVER_B_URI, serverBRequestHandler).build();
    _serverA = httpServerFactory.createServer(PORT_SERVER_A, serverATransportDispatcher, true);
    _serverB = httpServerFactory.createServer(PORT_SERVER_B, serverBTransportDispatcher, true);
    _serverA.start();
    _serverB.start();
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 24 with TransportClientAdapter

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

the class AbstractStreamTest method setup.

@BeforeClass
public void setup() throws IOException {
    _scheduler = Executors.newSingleThreadScheduledExecutor();
    _clientFactory = getClientFactory();
    _http1Client = new TransportClientAdapter(_clientFactory.getClient(getHttp1ClientProperties()), true);
    _http2Client = new TransportClientAdapter(_clientFactory.getClient(getHttp2ClientProperties()), true);
    _server = getServerFactory().createH2cServer(PORT, getTransportDispatcher(), true);
    _server.start();
}
Also used : TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) BeforeClass(org.testng.annotations.BeforeClass)

Example 25 with TransportClientAdapter

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

the class TestChannelPoolBehavior method setup.

@BeforeClass
public void setup() throws IOException {
    _scheduler = Executors.newSingleThreadScheduledExecutor();
    _clientFactory = new HttpClientFactory();
    _client1 = new TransportClientAdapter(_clientFactory.getClient(getClientProperties()), true);
    _client2 = new TransportClientAdapter(_clientFactory.getClient(getClientProperties()), true);
    _server = new HttpServerFactory().createServer(PORT, getTransportDispatcher(), true);
    _server.start();
}
Also used : HttpServerFactory(com.linkedin.r2.transport.http.server.HttpServerFactory) TransportClientAdapter(com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

TransportClientAdapter (com.linkedin.r2.transport.common.bridge.client.TransportClientAdapter)33 HashMap (java.util.HashMap)18 Client (com.linkedin.r2.transport.common.Client)16 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)16 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)14 RestRequest (com.linkedin.r2.message.rest.RestRequest)11 Test (org.testng.annotations.Test)11 None (com.linkedin.common.util.None)10 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)9 FutureCallback (com.linkedin.common.callback.FutureCallback)8 HttpServerFactory (com.linkedin.r2.transport.http.server.HttpServerFactory)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)7 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)7 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)7 URI (java.net.URI)7 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)6 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)6 BeforeClass (org.testng.annotations.BeforeClass)6 RequestContext (com.linkedin.r2.message.RequestContext)5