Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Reconcile RetrySettings & Clock (google-cloud-java part) (#1738)
Browse files Browse the repository at this point in the history
Reconcile RetrySettings & Clock (google-cloud-java part)

Reconcile RetrySettings in GAX with RetryParams in google-cloud-java
googleapis/google-cloud-java#1574
Reconcile NanoClock in GAX with Clock in google-cloud-java
googleapis/google-cloud-java#1575
  • Loading branch information
vam-google authored Mar 21, 2017
1 parent c453dea commit 76fee5b
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 1,104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,9 @@ private static String message(IOException exception) {
return exception.getMessage();
}

protected static void translateAndPropagateIfPossible(RetryHelper.RetryHelperException ex) {
protected static void translate(RetryHelper.RetryHelperException ex) {
if (ex.getCause() instanceof BaseServiceException) {
throw (BaseServiceException) ex.getCause();
}
if (ex instanceof RetryHelper.RetryInterruptedException) {
RetryHelper.RetryInterruptedException.propagate();
}
}
}
59 changes: 0 additions & 59 deletions google-cloud-core/src/main/java/com/google/cloud/Clock.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.gax.retrying.ExceptionRetryAlgorithm;
import com.google.api.gax.retrying.TimedAttemptSettings;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand All @@ -31,9 +33,9 @@
import java.util.concurrent.Callable;

/**
* Exception handling used by {@link RetryHelper}.
* Exception retry algorithm implementation used by {@link RetryHelper}.
*/
public final class ExceptionHandler implements Serializable {
public final class ExceptionHandler implements ExceptionRetryAlgorithm, Serializable {

private static final long serialVersionUID = -2460707015779532919L;

Expand Down Expand Up @@ -233,17 +235,12 @@ void verifyCaller(Callable<?> callable) {
}
}


public Set<Class<? extends Exception>> getRetriableExceptions() {
return retriableExceptions;
}


public Set<Class<? extends Exception>> getNonRetriableExceptions() {
return nonRetriableExceptions;
}

boolean shouldRetry(Exception ex) {
@Override
public boolean accept(Throwable prevThrowable) {
if(!(prevThrowable instanceof Exception)) {
return false;
}
Exception ex = (Exception) prevThrowable;
for (Interceptor interceptor : interceptors) {
Interceptor.RetryResult retryResult = checkNotNull(interceptor.beforeEval(ex));
if (retryResult != Interceptor.RetryResult.CONTINUE_EVALUATION) {
Expand All @@ -263,6 +260,14 @@ boolean shouldRetry(Exception ex) {
return retryResult == Interceptor.RetryResult.RETRY;
}

@Override
public TimedAttemptSettings createNextAttempt(Throwable prevThrowable,
TimedAttemptSettings prevSettings) {
// Return null to indicate that this implementaiton does not provide any specific attempt
// settings, so by default the TimedRetryAlgorithm options can be used instead.
return null;
}

@Override
public int hashCode() {
return Objects.hash(interceptors, retriableExceptions, nonRetriableExceptions, retryInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.joda.time.Duration;

/**
* Class representing service options for those services that use gRPC as the transport
Expand Down Expand Up @@ -206,18 +205,8 @@ public ExecutorFactory<ScheduledExecutorService> getExecutorFactory() {
/**
* Returns a builder for API call settings.
*/
public UnaryCallSettings.Builder getApiCallSettings(RetryParams retryParams) {
// todo(mziccard): specify timeout these settings:
// retryParams().retryMaxAttempts(), retryParams().retryMinAttempts()
final RetrySettings.Builder builder = RetrySettings.newBuilder()
.setTotalTimeout(Duration.millis(retryParams.getTotalRetryPeriodMillis()))
.setInitialRpcTimeout(Duration.millis(getInitialTimeout()))
.setRpcTimeoutMultiplier(getTimeoutMultiplier())
.setMaxRpcTimeout(Duration.millis(getMaxTimeout()))
.setInitialRetryDelay(Duration.millis(retryParams.getInitialRetryDelayMillis()))
.setRetryDelayMultiplier(retryParams.getRetryDelayBackoffFactor())
.setMaxRetryDelay(Duration.millis(retryParams.getMaxRetryDelayMillis()));
return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(builder);
public UnaryCallSettings.Builder getApiCallSettings(RetrySettings retrySettings) {
return UnaryCallSettings.newBuilder().setRetrySettingsBuilder(retrySettings.toBuilder());
}

/**
Expand Down
Loading

0 comments on commit 76fee5b

Please sign in to comment.