本文整理汇总了Java中io.grpc.PickFirstBalancerFactory类的典型用法代码示例。如果您正苦于以下问题:Java PickFirstBalancerFactory类的具体用法?Java PickFirstBalancerFactory怎么用?Java PickFirstBalancerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PickFirstBalancerFactory类属于io.grpc包,在下文中一共展示了PickFirstBalancerFactory类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPickFirstBalancerFactory
import io.grpc.PickFirstBalancerFactory; //导入依赖的package包/类
@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);
}
}
}
示例2: newLoadBalancer
import io.grpc.PickFirstBalancerFactory; //导入依赖的package包/类
@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);
}