use of com.google.api.gax.retrying.ExponentialRetryAlgorithm in project google-cloud-java by GoogleCloudPlatform.
the class RetryHelper method runWithRetries.
public static <V> V runWithRetries(Callable<V> callable, RetrySettings retrySettings, ExceptionHandler exceptionRetryAlgorithm, ApiClock clock) throws RetryHelperException {
try {
RetryAlgorithm retryAlgorithm = new RetryAlgorithm(exceptionRetryAlgorithm, new ExponentialRetryAlgorithm(retrySettings, clock));
RetryingExecutor<V> executor = new DirectRetryingExecutor<>(retryAlgorithm);
RetryingFuture<V> retryingFuture = executor.createFuture(callable);
executor.submit(retryingFuture);
return retryingFuture.get();
} catch (Exception e) {
throw new RetryHelperException(e.getCause());
}
}
use of com.google.api.gax.retrying.ExponentialRetryAlgorithm in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createMutateRowsBaseCallable.
/**
* Internal helper to create the base MutateRows callable chain. The chain is responsible for
* retrying individual entry in case of error.
*
* <p>NOTE: the caller is responsible for adding tracing & metrics.
*
* @see MutateRowsRetryingCallable for more details
*/
private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() {
ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> base = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<MutateRowsRequest, MutateRowsResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getMutateRowsMethod()).setParamsExtractor(new RequestParamsExtractor<MutateRowsRequest>() {
@Override
public Map<String, String> extract(MutateRowsRequest mutateRowsRequest) {
return ImmutableMap.of("table_name", mutateRowsRequest.getTableName(), "app_profile_id", mutateRowsRequest.getAppProfileId());
}
}).build(), settings.bulkMutateRowsSettings().getRetryableCodes());
ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> withStatsHeaders = new StatsHeadersServerStreamingCallable<>(base);
RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>(new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm(settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock()));
RetryingExecutorWithContext<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor());
return new MutateRowsRetryingCallable(clientContext.getDefaultCallContext(), withStatsHeaders, retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes());
}
Aggregations