Java 类io.grpc.PickFirstBalancerFactory 实例源码

项目:jetcd    文件:LoadBalancerTest.java   
@Test
public void testPickFirstBalancerFactory() throws Exception {
  try (Client client = Client.builder()
          .endpoints(TestConstants.endpoints)
          .loadBalancerFactory(PickFirstBalancerFactory.getInstance())
          .build();

       KV kv = client.getKVClient()) {
    PutResponse response;
    long lastMemberId = 0;

    for (int i = 0; i < TestConstants.endpoints.length * 2; i++) {
      response = kv.put(TestUtil.randomByteSequence(), TestUtil.randomByteSequence()).get();

      if (i == 0) {
        lastMemberId = response.getHeader().getMemberId();
      }

      assertThat(response.getHeader().getMemberId()).isEqualTo(lastMemberId);
    }
  }
}
项目:grpc-java    文件:GrpclbLoadBalancerFactory.java   
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new GrpclbLoadBalancer(
      helper, PickFirstBalancerFactory.getInstance(),
      RoundRobinLoadBalancerFactory.getInstance(),
      // TODO(zhangkun83): balancer sends load reporting RPCs from it, which also involves
      // channelExecutor thus may also run other tasks queued in the channelExecutor.  If such
      // load should not be on the shared scheduled executor, we should use a combination of the
      // scheduled executor and the default app executor.
      SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE),
      TIME_PROVIDER);
}