io.grpc.internal.ExponentialBackoffPolicy Java Examples

The following examples show how to use io.grpc.internal.ExponentialBackoffPolicy. 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: XdsNameResolverProvider.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public XdsNameResolver newNameResolver(URI targetUri, Args args) {
  if (SCHEME.equals(targetUri.getScheme())) {
    String targetPath = Preconditions.checkNotNull(targetUri.getPath(), "targetPath");
    Preconditions.checkArgument(
        targetPath.startsWith("/"),
        "the path component (%s) of the target (%s) must start with '/'",
        targetPath,
        targetUri);
    String name = targetPath.substring(1);
    return
        new XdsNameResolver(
            name,
            args,
            new ExponentialBackoffPolicy.Provider(),
            GrpcUtil.STOPWATCH_SUPPLIER,
            XdsChannelFactory.getInstance(),
            Bootstrapper.getInstance());
  }
  return null;
}
 
Example #2
Source File: XdsExperimentalNameResolverProvider.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public NameResolver newNameResolver(URI targetUri, Args args) {
  if (SCHEME.equals(targetUri.getScheme())) {
    String targetPath = Preconditions.checkNotNull(targetUri.getPath(), "targetPath");
    Preconditions.checkArgument(
        targetPath.startsWith("/"),
        "the path component (%s) of the target (%s) must start with '/'",
        targetPath,
        targetUri);
    String name = targetPath.substring(1);
    return
        new XdsNameResolver(
            name,
            args,
            new ExponentialBackoffPolicy.Provider(),
            GrpcUtil.STOPWATCH_SUPPLIER,
            XdsChannelFactory.getInstance(),
            Bootstrapper.getInstance());
  }
  return null;
}
 
Example #3
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 #4
Source File: XdsClientWrapperForServerSds.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/** Creates an XdsClient and starts a watch. */
public void createXdsClientAndStart() {
  checkState(xdsClient == null, "start() called more than once");
  Bootstrapper.BootstrapInfo bootstrapInfo;
  List<Bootstrapper.ServerInfo> serverList;
  try {
    bootstrapInfo = Bootstrapper.getInstance().readBootstrap();
    serverList = bootstrapInfo.getServers();
    if (serverList.isEmpty()) {
      throw new ManagementServerNotFoundException("No management server provided by bootstrap");
    }
  } catch (IOException | ManagementServerNotFoundException e) {
    logger.log(Level.FINE, "Exception reading bootstrap", e);
    logger.log(Level.INFO, "Fallback to plaintext for server at port {0}", port);
    return;
  }
  Node node = bootstrapInfo.getNode();
  timeService = SharedResourceHolder.get(timeServiceResource);
  XdsClientImpl xdsClientImpl =
      new XdsClientImpl(
          "",
          serverList,
          XdsClient.XdsChannelFactory.getInstance(),
          node,
          createSynchronizationContext(),
          timeService,
          new ExponentialBackoffPolicy.Provider(),
          GrpcUtil.STOPWATCH_SUPPLIER);
  start(xdsClientImpl);
}
 
Example #5
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 #6
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 #7
Source File: ExponentialBackoffReconnectJob.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public final void resetBackoffNanos() {
    exponentialBackoffPolicy = new ExponentialBackoffPolicy();
}
 
Example #8
Source File: EdsLoadBalancer.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handleResolvedAddresses(ResolvedAddresses resolvedAddresses) {
  logger.log(XdsLogLevel.DEBUG, "Received resolution result: {0}", resolvedAddresses);
  Object lbConfig = resolvedAddresses.getLoadBalancingPolicyConfig();
  if (lbConfig == null) {
    handleNameResolutionError(Status.UNAVAILABLE.withDescription("Missing EDS lb config"));
    return;
  }
  EdsConfig newEdsConfig = (EdsConfig) lbConfig;
  if (logger.isLoggable(XdsLogLevel.INFO)) {
    logger.log(
        XdsLogLevel.INFO,
        "Received EDS lb config: cluster={0}, child_policy={1}, "
            + "eds_service_name={2}, report_load={3}",
        newEdsConfig.clusterName,
        newEdsConfig.endpointPickingPolicy.getProvider().getPolicyName(),
        newEdsConfig.edsServiceName,
        newEdsConfig.lrsServerName != null);
  }
  boolean firstUpdate = false;
  if (clusterName == null) {
    firstUpdate = true;
  }
  clusterName = newEdsConfig.clusterName;
  if (xdsClientPool == null) {
    Attributes attributes = resolvedAddresses.getAttributes();
    xdsClientPool = attributes.get(XdsAttributes.XDS_CLIENT_POOL);
    if (xdsClientPool == null) {
      final BootstrapInfo bootstrapInfo;
      try {
        bootstrapInfo = bootstrapper.readBootstrap();
      } catch (Exception e) {
        helper.updateBalancingState(
            TRANSIENT_FAILURE,
            new ErrorPicker(
                Status.UNAVAILABLE.withDescription("Failed to bootstrap").withCause(e)));
        return;
      }

      final List<ServerInfo> serverList = bootstrapInfo.getServers();
      final Node node = bootstrapInfo.getNode();
      if (serverList.isEmpty()) {
        helper.updateBalancingState(
            TRANSIENT_FAILURE,
            new ErrorPicker(
                Status.UNAVAILABLE
                    .withDescription("No management server provided by bootstrap")));
        return;
      }
      XdsClientFactory xdsClientFactory = new XdsClientFactory() {
        @Override
        XdsClient createXdsClient() {
          return
              new XdsClientImpl(
                  helper.getAuthority(),
                  serverList,
                  channelFactory,
                  node,
                  helper.getSynchronizationContext(),
                  helper.getScheduledExecutorService(),
                  new ExponentialBackoffPolicy.Provider(),
                  GrpcUtil.STOPWATCH_SUPPLIER);
        }
      };
      xdsClientPool = new RefCountedXdsClientObjectPool(xdsClientFactory);
    } else {
      logger.log(XdsLogLevel.INFO, "Use xDS client from channel");
    }
    xdsClient = xdsClientPool.getObject();
  }

  // Note: childPolicy change will be handled in LocalityStore, to be implemented.
  // If edsServiceName in XdsConfig is changed, do a graceful switch.
  if (firstUpdate || !Objects.equals(newEdsConfig.edsServiceName, edsServiceName)) {
    LoadBalancer.Factory clusterEndpointsLoadBalancerFactory =
        new ClusterEndpointsBalancerFactory(newEdsConfig.edsServiceName);
    switchingLoadBalancer.switchTo(clusterEndpointsLoadBalancerFactory);
  }
  switchingLoadBalancer.handleResolvedAddresses(resolvedAddresses);
  this.edsServiceName = newEdsConfig.edsServiceName;
}
 
Example #9
Source File: HealthCheckingLoadBalancerUtil.java    From grpc-nebula-java with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a health-checking-capable LoadBalancer.  This method is used to implement
 * health-checking-capable {@link Factory}s, which will typically written this way:
 *
 * <pre>
 * public class HealthCheckingFooLbFactory extends LoadBalancer.Factory {
 *   // This is the original balancer implementation that doesn't have health checking
 *   private final LoadBalancer.Factory fooLbFactory;
 *
 *   ...
 *
 *   // Returns the health-checking-capable version of FooLb   
 *   public LoadBalancer newLoadBalancer(Helper helper) {
 *     return HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer(fooLbFactory, helper);
 *   }
 * }
 * </pre>
 *
 * <p>As a requirement for the original LoadBalancer, it must call
 * {@code Helper.createSubchannel()} from the {@link
 * io.grpc.LoadBalancer.Helper#getSynchronizationContext() Synchronization Context}, or
 * {@code createSubchannel()} will throw.
 *
 * @param factory the original factory that implements load-balancing logic without health
 *        checking
 * @param helper the helper passed to the resulting health-checking LoadBalancer.
 */
public static LoadBalancer newHealthCheckingLoadBalancer(Factory factory, Helper helper) {
  HealthCheckingLoadBalancerFactory hcFactory =
      new HealthCheckingLoadBalancerFactory(
          factory, new ExponentialBackoffPolicy.Provider(), TimeProvider.SYSTEM_TIME_PROVIDER);
  return hcFactory.newLoadBalancer(helper);
}
 
Example #10
Source File: HealthCheckingLoadBalancerUtil.java    From grpc-java with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a health-checking-capable LoadBalancer.  This method is used to implement
 * health-checking-capable {@link Factory}s, which will typically written this way:
 *
 * <pre>
 * public class HealthCheckingFooLbFactory extends LoadBalancer.Factory {
 *   // This is the original balancer implementation that doesn't have health checking
 *   private final LoadBalancer.Factory fooLbFactory;
 *
 *   ...
 *
 *   // Returns the health-checking-capable version of FooLb   
 *   public LoadBalancer newLoadBalancer(Helper helper) {
 *     return HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer(fooLbFactory, helper);
 *   }
 * }
 * </pre>
 *
 * <p>As a requirement for the original LoadBalancer, it must call
 * {@code Helper.createSubchannel()} from the {@link
 * io.grpc.LoadBalancer.Helper#getSynchronizationContext() Synchronization Context}, or
 * {@code createSubchannel()} will throw.
 *
 * @param factory the original factory that implements load-balancing logic without health
 *        checking
 * @param helper the helper passed to the resulting health-checking LoadBalancer.
 */
public static LoadBalancer newHealthCheckingLoadBalancer(Factory factory, Helper helper) {
  HealthCheckingLoadBalancerFactory hcFactory =
      new HealthCheckingLoadBalancerFactory(
          factory, new ExponentialBackoffPolicy.Provider(),
          GrpcUtil.STOPWATCH_SUPPLIER);
  return hcFactory.newLoadBalancer(helper);
}