Package com.linkedin.d2.balancer.clients

Examples of com.linkedin.d2.balancer.clients.DynamicClient


      ZKFSLoadBalancer balancer = getBalancer();
      FutureCallback<None> callback = new FutureCallback<None>();
      balancer.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      Directory dir = balancer.getDirectory();

      ZKConnection conn = new ZKConnection("localhost:" + PORT, 30000);
      conn.start();

      ZooKeeperPermanentStore<ServiceProperties> store =
              new ZooKeeperPermanentStore<ServiceProperties>(conn, new ServicePropertiesJsonSerializer(), ZKFSUtil.servicePath(BASE_PATH));
      callback = new FutureCallback<None>();
      store.start(callback);
      callback.get(30, TimeUnit.SECONDS);

      ServiceProperties props = new ServiceProperties(TEST_SERVICE_NAME, "someCluster", "/somePath", "someStrategy");
      store.put(TEST_SERVICE_NAME, props);

      FutureCallback<List<String>> serviceCallback = new FutureCallback<List<String>>();
      dir.getServiceNames(serviceCallback);

      Assert.assertEquals(serviceCallback.get(30, TimeUnit.SECONDS), Collections.singletonList(TEST_SERVICE_NAME));
    }
    finally
    {
View Full Code Here


                  _config.clientServicesConfig,
                  _config.d2ServicePath);

    final LoadBalancerWithFacilities loadBalancer = loadBalancerFactory.create(cfg);

    D2Client d2Client = new DynamicClient(loadBalancer, loadBalancer);

    /**
     * If we created default transport client factories, we need to shut them down when d2Client
     * is being shut down.
     */
 
View Full Code Here

      InterruptedException,
      ExecutionException,
      IOException,
      PropertyStoreException
  {
    DynamicClient client = new DynamicClient(getLoadBalancer(_hostPort), null);

    for (;;)
    {
      int index = 0;
      if (_services.length > 1)
      {
        index = _random.nextInt(_services.length);
      }

      String service = _services[index];
      URI uri = URI.create("d2://" + service);

      RpcRequest req =
          new RpcRequestBuilder(uri).setEntity("hi there".getBytes("UTF-8")).build();

      try
      {
        Future<RpcResponse> response = client.rpcRequest(req);
        String responseString = response.get().getEntity().asString("UTF-8");

        System.err.println(uri + " response: " + responseString);
      }
      catch (ExecutionException e)
View Full Code Here

          PropertyStoreException, TimeoutException
  {
    String responseString = null;
    if (hasService(zkclient, zkserver, d2path, cluster, service))
    {
      DynamicClient client = new DynamicClient(getLoadBalancer(zkclient, zkserver, d2path, service), null);
      URI uri = URI.create("d2://" + service + "/");

      try
      {
        if (! requestType.equalsIgnoreCase("rest"))
        {
          RpcRequest req =
            new RpcRequestBuilder(uri).setEntity("".getBytes("UTF-8")).build();
          Future<RpcResponse> response = client.rpcRequest(req);
          responseString = response.get().getEntity().asString("UTF-8");
        }
        else
        {
          RestRequest restRequest = new RestRequestBuilder(uri).setEntity("".getBytes("UTF-8")).build();
          Future<RestResponse> response = client.restRequest(restRequest, new RequestContext());
          responseString = response.get().getEntity().asString("UTF-8");
        }
      }
      finally
      {
View Full Code Here

                                  ExecutionException,
                                  IOException,
                                  PropertyStoreException,
                                  TimeoutException
  {
    return new DynamicClient(getLoadBalancer(zkclient, zkserver, d2path, service), null);
  }
View Full Code Here

    _zkfsLoadBalancer = getZKFSLoadBalancer(zkHostsPortsConnectionString, d2path, servicePath);
    FutureCallback<None> startupCallback = new FutureCallback<None>();
    _zkfsLoadBalancer.start(startupCallback);
    startupCallback.get(5000, TimeUnit.MILLISECONDS);

    return new DynamicClient(_zkfsLoadBalancer, null);
  }
View Full Code Here

    new R2D2Client(args[0]).run();
  }

  public R2D2Client(String hostPort) throws Exception
  {
    _client = new DynamicClient(LoadBalancerEchoClient.getLoadBalancer(hostPort), null);
    _random = new Random();

  }
View Full Code Here

  @BeforeTest
  public void init()
  {
    _loadBalancer = MockLBFactory.createLoadBalancer();
    _r2Client = new DynamicClient(_loadBalancer, null);
    _restClient = new RestClient(_r2Client, "d2://");
  }
View Full Code Here

  public TrackerClient getClient(String serviceName, URI uri)
  {
    if (_partitionDescriptions.get(uri) != null)
    {
      // shorten the update interval to 20ms in order to increase the possibility of deadlock
      _trackerClients.putIfAbsent(uri, new TrackerClient(uri, _partitionDescriptions.get(uri), null, new SettableClock(), null, 20));

      return _trackerClients.get(uri);
    }
    return null;
  }
View Full Code Here

  @Override
  public TrackerClient getClient(String clusterName, URI uri)
  {
    Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
    partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1));
    return (getClient) ? new TrackerClient(uri, partitionDataMap, new TestClient()) : null;
  }
View Full Code Here

TOP

Related Classes of com.linkedin.d2.balancer.clients.DynamicClient

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.