Skip to content

Commit

Permalink
Merge 07e467c into 29b1ea5
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkannan committed Apr 6, 2016
2 parents 29b1ea5 + 07e467c commit 60f42a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public final class RetryParams implements Serializable {

private static final long serialVersionUID = -8492751576749007700L;

/**
* Note that App Engine Standard Environment front-end modules have a 60 second deadline for HTTP
* requests. For that reason, we set the default total retry period to less than 60 seconds.
*/
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;
public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3;
public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6;
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 250L;
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 10_000L;
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 1000L;
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 32_000L;
public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0;
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;

private final int retryMinAttempts;
private final int retryMaxAttempts;
Expand All @@ -62,6 +66,9 @@ public final class RetryParams implements Serializable {
private final double retryDelayBackoffFactor;
private final long totalRetryPeriodMillis;

// Some services may have different backoff requirements listed in their SLAs. Be sure to override
// ServiceOptions.defaultRetryParams() in options subclasses when the service's backoff
// requirement differs from the default parameters used here.
private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder());
private static final RetryParams NO_RETRIES =
builder().retryMaxAttempts(1).retryMinAttempts(1).build();
Expand Down Expand Up @@ -156,7 +163,9 @@ public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) {
}

/**
* Sets totalRetryPeriodMillis.
* Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have
* a 60 second deadline for HTTP requests. For that reason, you should set the total retry
* period to under 60 seconds if you are using the App Engine front-end module.
*
* @param totalRetryPeriodMillis the totalRetryPeriodMillis to set
* @return the Builder for chaining
Expand Down Expand Up @@ -295,4 +304,8 @@ public String toString() {
public static Builder builder() {
return new Builder();
}

public Builder toBuilder() {
return new Builder(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
authCredentials =
builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials();
authCredentialsState = authCredentials != null ? authCredentials.capture() : null;
retryParams = firstNonNull(builder.retryParams, RetryParams.defaultInstance());
retryParams = firstNonNull(builder.retryParams, defaultRetryParams());
serviceFactory = firstNonNull(builder.serviceFactory,
getFromServiceLoader(serviceFactoryClass, defaultServiceFactory()));
serviceFactoryClassName = serviceFactory.getClass().getName();
Expand Down Expand Up @@ -655,6 +655,10 @@ private static <T> T newInstance(String className) throws IOException, ClassNotF

public abstract <B extends Builder<ServiceT, ServiceRpcT, OptionsT, B>> B toBuilder();

protected RetryParams defaultRetryParams() {
return RetryParams.defaultInstance();
}

private static <T> T getFromServiceLoader(Class<? extends T> clazz, T defaultInstance) {
return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance);
}
Expand Down

0 comments on commit 60f42a5

Please sign in to comment.