Package com.linkedin.r2.transport.common.bridge.client

Examples of com.linkedin.r2.transport.common.bridge.client.TransportClient


*/
public class PerfClients
{
  public static PerfClient httpRpc(URI uri, int numThreads, int numMsgs, int msgSize)
  {
    final TransportClient transportClient = new HttpClientFactory().getClient(Collections.<String, String>emptyMap());
    final Client client = new TransportClientAdapter(transportClient);
    final RequestGenerator<String> reqGen = new StringRequestGenerator(numMsgs, msgSize);
    final ClientRunnableFactory crf = new RpcClientRunnableFactory(client, uri, reqGen);

    return new PerfClient(crf, numThreads);
View Full Code Here


    return new PerfClient(crf, numThreads);
  }

  public static PerfClient httpRest(URI uri, int numThreads, int numMsgs, int msgSize)
  {
    final TransportClient transportClient = new HttpClientFactory().getClient(Collections.<String, String>emptyMap());
    final Client client = new TransportClientAdapter(transportClient);
    final RequestGenerator<RestRequest> reqGen = new RestRequestGenerator(uri, numMsgs, msgSize);
    final ClientRunnableFactory crf = new RestClientRunnableFactory(client, reqGen);

    return new PerfClient(crf, numThreads);
View Full Code Here

      transportCallback = callback;
    }

    try
    {
      TransportClient client = _balancer.getClient(request, requestContext);

      if (client != null)
      {
        new TransportClientAdapter(client).restRequest(request, requestContext, transportCallback);
      }
View Full Code Here

  {
    trace(_log, "rpc request: ", request);

    try
    {
      TransportClient client = _balancer.getClient(request, requestContext);

      if (client != null)
      {
        new TransportClientAdapter(client).rpcRequest(request, requestContext, callback);
      }
View Full Code Here

                                   SSLParameters sslParameters)
  {
    LOG.info("Getting a client with configuration {} and SSLContext {}",
             properties,
             sslContext);
    TransportClient client = getRawClient(properties, sslContext, sslParameters);

    List<String> httpResponseCompressionOperations = ConfigValueExtractor.buildList(properties.remove(HTTP_RESPONSE_COMPRESSION_OPERATIONS),
                                                                                    LIST_SEPARATOR);

    FilterChain filters;
View Full Code Here

   */
  public static void main(String[] args) throws Exception
  {
    // create HTTP Netty client with default properties
    final HttpClientFactory http = new HttpClientFactory();
    final TransportClient transportClient = http.getClient(Collections.<String, String>emptyMap());
    // create an abstraction layer over the actual client, which supports both REST and RPC
    final Client r2Client = new TransportClientAdapter(transportClient);
    // REST client wrapper that simplifies the interface
    final StringBuilder serverUrlBuilder = new StringBuilder("http://").append(SERVER_HOSTNAME).append(":").append(SERVER_PORT).append("/");
    final RestClient restClient = new RestClient(r2Client, serverUrlBuilder.toString());
View Full Code Here

  }

  @Test
  public void testShutdown() throws ExecutionException, TimeoutException, InterruptedException
  {
    TransportClient client = new HttpClientFactory().getClient(
            Collections.<String, String>emptyMap());

    FutureCallback<None> shutdownCallback = new FutureCallback<None>();
    client.shutdown(shutdownCallback);
    shutdownCallback.get(30, TimeUnit.SECONDS);

    // Now verify a new request will also fail
    RestRequest r = new RestRequestBuilder(URI.create("http://no.such.host.linkedin.com")).build();
    FutureCallback<RestResponse> callback = new FutureCallback<RestResponse>();
    client.restRequest(r, new RequestContext(), new HashMap<String,String>(), new TransportCallbackAdapter<RestResponse>(callback));
    try
    {
      callback.get(30, TimeUnit.SECONDS);
    }
    catch (ExecutionException e)
View Full Code Here

        {
          try
          {
            // this call will queue up messages if we're not listening to the service, but
            // it's ok, because all of the messengers have been stopped.
            final TransportClient client =
                _loadBalancer.getClient(new URIRequest("d2://" + possibleService +
                    random(_possiblePaths)), new RequestContext());

            // if we didn't receive service unavailable, we should
            // get a client back
View Full Code Here

   *           URN, an ServiceUnavailableException will be thrown.
   */
  @Override
  public TransportClient getClient(Request request, RequestContext requestContext) throws ServiceUnavailableException
  {
    TransportClient client;
    URI uri = request.getURI();
    debug(_log, "get client for uri: ", uri);

    ServiceProperties service = listenToServiceAndCluster(uri);

    String serviceName = service.getServiceName();
    String clusterName = service.getClusterName();
    ClusterProperties cluster = getClusterProperties(serviceName, clusterName);

    // Check if we want to override the service URL and bypass choosing among the existing
    // tracker clients. This is useful when the service we want is not announcing itself to
    // the cluster, ie a private service for a set of clients.
    URI targetService = LoadBalancerUtil.TargetHints.getRequestContextTargetService(requestContext);

    if (targetService == null)
    {
      LoadBalancerStateItem<UriProperties> uriItem = getUriItem(serviceName, clusterName, cluster);
      UriProperties uris = uriItem.getProperty();

      List<LoadBalancerState.SchemeStrategyPair> orderedStrategies =
              _state.getStrategiesForService(serviceName,
                                             service.getPrioritizedSchemes());

      TrackerClient trackerClient = chooseTrackerClient(request, requestContext, serviceName, clusterName, cluster,
                                                        uriItem, uris, orderedStrategies, service);

      String clusterAndServiceUriString = trackerClient.getUri() + service.getPath();
      client = new RewriteClient(serviceName,
                                               URI.create(clusterAndServiceUriString),
                                               trackerClient);

      _serviceAvailableStats.inc();
    }
    else
    {
      _log.debug("service hint found, using generic client for target: " + targetService);

      TransportClient transportClient = _state.getClient(serviceName, targetService.getScheme());
      client = new RewriteClient(serviceName,targetService,transportClient);
    }
    return client;
  }
View Full Code Here

      partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1.0));
      server.markUp(TEST_CLUSTER_NAME, URI.create("http://test.uri"), partitionDataMap, callback);
      callback.get(30, TimeUnit.SECONDS);

      URIRequest request = new URIRequest("d2://" + TEST_SERVICE_NAME + "/foo");
      TransportClient client = balancer.getClient(request, new RequestContext());

      // Stop the server to cause a disconnect event
      stopServer();
      // Sleep to ensure the disconnect has propagated; ideally the Toggle should expose
      // some interface to allow detection that the toggle occurred
View Full Code Here

TOP

Related Classes of com.linkedin.r2.transport.common.bridge.client.TransportClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.