Skip to content

Commit

Permalink
add RetryParams to ServiceApiSettings for programmatic access
Browse files Browse the repository at this point in the history
  • Loading branch information
pongad committed Feb 11, 2016
1 parent e1c71e0 commit 257cbbe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
22 changes: 0 additions & 22 deletions src/main/java/com/google/api/gax/core/RetryParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@
*/
@AutoValue
public abstract class RetryParams {
// TODO(pongad): deprecate DEFAULT in favor of code-generation-time config
private static final BackoffParams DEFAULT_RETRY_BACKOFF =
BackoffParams.newBuilder()
.setInitialDelayMillis(10L)
.setDelayMultiplier(1.2)
.setMaxDelayMillis(1000L)
.build();

private static final BackoffParams DEFAULT_TIMEOUT_BACKOFF =
BackoffParams.newBuilder()
.setInitialDelayMillis(3000L)
.setDelayMultiplier(1.2)
.setMaxDelayMillis(10000L)
.build();

public static final RetryParams DEFAULT =
RetryParams.newBuilder()
.setRetryBackoff(DEFAULT_RETRY_BACKOFF)
.setTimeoutBackoff(DEFAULT_TIMEOUT_BACKOFF)
.setTotalTimeout(30000L)
.build();

public abstract BackoffParams getRetryBackoff();

public abstract BackoffParams getTimeoutBackoff();
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/google/api/gax/grpc/ApiCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,6 @@ public ApiCallable<RequestT, ResponseT> retrying(RetryParams retryParams) {
new RetryingCallable<RequestT, ResponseT>(callable, retryParams));
}

/**
* Same as {@link #retrying(RetryParams)} but with {@link RetryParams#DEFAULT}.
*/
public ApiCallable<RequestT, ResponseT> retrying() {
return retrying(RetryParams.DEFAULT);
}

/**
* Returns a callable which streams the resources obtained from a series of calls to a method
* implementing the pagination pattern.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/google/api/gax/grpc/ServiceApiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

package com.google.api.gax.grpc;

import com.google.api.gax.core.RetryParams;
import com.google.auth.Credentials;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
Expand All @@ -57,6 +58,11 @@ public abstract class ServiceApiSettings<MethodId> {
*/
public abstract ImmutableMap<MethodId, ImmutableSet<Status.Code>> getRetryableCodes();

/**
* Retry/backoff configuration for each method
*/
public abstract ImmutableMap<MethodId, RetryParams> getRetryParams();

/**
* Credentials to use in order to call the service.
* The default is to acquire credentials using GoogleCredentials.getApplicationDefault().
Expand Down Expand Up @@ -86,6 +92,7 @@ public abstract class ServiceApiSettings<MethodId> {
public static <MethodId> Builder<MethodId> builder() {
return new AutoValue_ServiceApiSettings.Builder()
.setRetryableCodes(ImmutableMap.<MethodId, ImmutableSet<Status.Code>>of())
.setRetryParams(ImmutableMap.<MethodId, RetryParams>of())
.setPort(0);
}

Expand All @@ -98,6 +105,9 @@ public abstract static class Builder<MethodId> {
public abstract Builder<MethodId> setRetryableCodes(
ImmutableMap<MethodId, ImmutableSet<Status.Code>> codes);

public abstract Builder<MethodId> setRetryParams(
ImmutableMap<MethodId, RetryParams> retryParams);

public abstract Builder<MethodId> setCredentials(Credentials credentials);

public abstract Builder<MethodId> setServiceAddress(String serviceAddress);
Expand Down

0 comments on commit 257cbbe

Please sign in to comment.