Java Code Examples for io.grpc.LoadBalancer#Helper

The following examples show how to use io.grpc.LoadBalancer#Helper . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrcaOobUtil.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static OrcaReportingHelperWrapper newOrcaReportingHelperWrapper(
    LoadBalancer.Helper delegate,
    OrcaOobReportListener listener,
    BackoffPolicy.Provider backoffPolicyProvider,
    Supplier<Stopwatch> stopwatchSupplier) {
  final OrcaReportingHelper orcaHelper =
      new OrcaReportingHelper(delegate, listener, backoffPolicyProvider, stopwatchSupplier);

  return new OrcaReportingHelperWrapper() {
    @Override
    public void setReportingConfig(OrcaReportingConfig config) {
      orcaHelper.setReportingConfig(config);
    }

    @Override
    public Helper asHelper() {
      return orcaHelper;
    }
  };
}
 
Example 2
Source File: OrcaOobUtil.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
OrcaReportingHelper(
    LoadBalancer.Helper delegate,
    OrcaOobReportListener listener,
    BackoffPolicy.Provider backoffPolicyProvider,
    Supplier<Stopwatch> stopwatchSupplier) {
  this.delegate = checkNotNull(delegate, "delegate");
  this.listener = checkNotNull(listener, "listener");
  this.backoffPolicyProvider = checkNotNull(backoffPolicyProvider, "backoffPolicyProvider");
  this.stopwatchSupplier = checkNotNull(stopwatchSupplier, "stopwatchSupplier");
  syncContext = checkNotNull(delegate.getSynchronizationContext(), "syncContext");
}
 
Example 3
Source File: OrcaOobUtil.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public OrcaReportingHelperWrapper newOrcaReportingHelperWrapper(
    LoadBalancer.Helper delegate,
    OrcaOobReportListener listener) {
  return newOrcaReportingHelperWrapper(
      delegate,
      listener,
      new ExponentialBackoffPolicy.Provider(),
      GrpcUtil.STOPWATCH_SUPPLIER);
}
 
Example 4
Source File: GrpclbLoadBalancerProvider.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return
      new GrpclbLoadBalancer(
          helper,
          new CachedSubchannelPool(helper),
          TimeProvider.SYSTEM_TIME_PROVIDER,
          Stopwatch.createUnstarted(),
          new ExponentialBackoffPolicy.Provider());
}
 
Example 5
Source File: LrsLoadBalancer.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
  LrsConfig config = (LrsConfig) resolvedAddresses.getLoadBalancingPolicyConfig();
  LoadStatsStore store =
      resolvedAddresses.getAttributes().get(XdsAttributes.ATTR_CLUSTER_SERVICE_LOAD_STATS_STORE);
  checkNotNull(config, "missing LRS lb config");
  checkNotNull(store, "missing cluster service stats object");
  checkAndSetUp(config, store);

  if (switchingLoadBalancer == null) {
    loadStatsStore.addLocality(config.locality);
    final ClientLoadCounter counter = loadStatsStore.getLocalityCounter(config.locality);
    LoadBalancer.Helper loadRecordingHelper = new ForwardingLoadBalancerHelper() {
      @Override
      protected Helper delegate() {
        return helper;
      }

      @Override
      public void updateBalancingState(ConnectivityState newState, SubchannelPicker newPicker) {
        SubchannelPicker loadRecordingPicker =
            new LoadRecordingSubchannelPicker(counter, newPicker);
        super.updateBalancingState(newState, loadRecordingPicker);
      }
    };
    switchingLoadBalancer = new GracefulSwitchLoadBalancer(loadRecordingHelper);
  }
  String updatedChildPolicyName = config.childPolicy.getProvider().getPolicyName();
  if (!Objects.equals(childPolicyName, updatedChildPolicyName)) {
    switchingLoadBalancer.switchTo(config.childPolicy.getProvider());
    childPolicyName = updatedChildPolicyName;
  }
  ResolvedAddresses downStreamResult =
      resolvedAddresses.toBuilder()
          .setLoadBalancingPolicyConfig(config.childPolicy.getConfig())
          .build();
  switchingLoadBalancer.handleResolvedAddresses(downStreamResult);
}
 
Example 6
Source File: SecretRoundRobinLoadBalancerProvider.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new RoundRobinLoadBalancer(helper);
}
 
Example 7
Source File: GrpclbLoadBalancerFactory.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return provider.newLoadBalancer(helper);
}
 
Example 8
Source File: PickFirstLoadBalancerProvider.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new PickFirstLoadBalancer(helper);
}
 
Example 9
Source File: RlsLoadBalancerProvider.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new RlsLoadBalancer(helper);
}
 
Example 10
Source File: LrsLoadBalancerProvider.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new LrsLoadBalancer(helper);
}
 
Example 11
Source File: LrsLoadBalancer.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
LrsLoadBalancer(LoadBalancer.Helper helper) {
  this.helper = checkNotNull(helper, "helper");
}
 
Example 12
Source File: AgentClientMock.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
    return new CustomLoadBalancer(helper);
}
 
Example 13
Source File: ForwardingLoadBalancerHelperTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
protected LoadBalancer.Helper delegate() {
  return mockDelegate;
}
 
Example 14
Source File: ForwardingLoadBalancerHelperTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
protected LoadBalancer.Helper delegate() {
  return mockDelegate;
}
 
Example 15
Source File: SecretRoundRobinLoadBalancerProvider.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new RoundRobinLoadBalancer(helper);
}
 
Example 16
Source File: PickFirstLoadBalancerProvider.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new PickFirstLoadBalancer(helper);
}
 
Example 17
Source File: GrpclbLoadBalancerProvider.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) {
  return new GrpclbLoadBalancer(
      helper, new CachedSubchannelPool(), TimeProvider.SYSTEM_TIME_PROVIDER,
      new ExponentialBackoffPolicy.Provider());
}
 
Example 18
Source File: ForwardingLoadBalancerHelper.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the underlying helper.
 */
protected abstract LoadBalancer.Helper delegate();
 
Example 19
Source File: OrcaOobUtil.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a wrapped {@link LoadBalancer.Helper}. Subchannels created through it will retrieve
 * ORCA load reports if the server supports it.
 */
public abstract LoadBalancer.Helper asHelper();
 
Example 20
Source File: ForwardingLoadBalancerHelper.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the underlying helper.
 */
protected abstract LoadBalancer.Helper delegate();