Package com.google.api.gax.retrying
Class RetryAlgorithm<ResponseT>
- java.lang.Object
-
- com.google.api.gax.retrying.RetryAlgorithm<ResponseT>
-
- Type Parameters:
ResponseT- response type
- Direct Known Subclasses:
StreamingRetryAlgorithm
public class RetryAlgorithm<ResponseT> extends java.lang.ObjectThe retry algorithm, which makes decision based either on the thrown exception or the returned response, and the execution time settings of the previous attempt.This class is thread-safe.
-
-
Constructor Summary
Constructors Constructor Description RetryAlgorithm(ResultRetryAlgorithm<ResponseT> resultAlgorithm, TimedRetryAlgorithm timedAlgorithm)Deprecated.RetryAlgorithm(ResultRetryAlgorithmWithContext<ResponseT> resultAlgorithm, TimedRetryAlgorithmWithContext timedAlgorithm)Creates a new retry algorithm instance, which uses thrown exception or returned response and timed algorithms to make a decision.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TimedAttemptSettingscreateFirstAttempt()Deprecated.usecreateFirstAttempt(RetryingContext)insteadTimedAttemptSettingscreateFirstAttempt(RetryingContext context)Creates a first attemptTimedAttemptSettings.TimedAttemptSettingscreateNextAttempt(RetryingContext context, java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings previousSettings)Creates a next attemptTimedAttemptSettings.TimedAttemptSettingscreateNextAttempt(java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings previousSettings)Deprecated.ResultRetryAlgorithm<ResponseT>getResultAlgorithm()TimedRetryAlgorithmgetTimedAlgorithm()booleanshouldRetry(RetryingContext context, java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings nextAttemptSettings)Returnstrueif another attempt should be made, orfalseotherwise.booleanshouldRetry(java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings nextAttemptSettings)Deprecated.
-
-
-
Constructor Detail
-
RetryAlgorithm
@Deprecated public RetryAlgorithm(ResultRetryAlgorithm<ResponseT> resultAlgorithm, TimedRetryAlgorithm timedAlgorithm)
Deprecated.Creates a new retry algorithm instance, which uses thrown exception or returned response and timed algorithms to make a decision. The result algorithm has higher priority than the timed algorithm.Instances that are created using this constructor will ignore the
RetryingContextthat is passed in to the retrying methods. UseRetryAlgorithm(ResultRetryAlgorithmWithContext, TimedRetryAlgorithmWithContext)to create an instance that will respect theRetryingContext.- Parameters:
resultAlgorithm- result algorithm to usetimedAlgorithm- timed algorithm to use
-
RetryAlgorithm
public RetryAlgorithm(ResultRetryAlgorithmWithContext<ResponseT> resultAlgorithm, TimedRetryAlgorithmWithContext timedAlgorithm)
Creates a new retry algorithm instance, which uses thrown exception or returned response and timed algorithms to make a decision. The result algorithm has higher priority than the timed algorithm.- Parameters:
resultAlgorithm- result algorithm to usetimedAlgorithm- timed algorithm to use
-
-
Method Detail
-
createFirstAttempt
@Deprecated public TimedAttemptSettings createFirstAttempt()
Deprecated.usecreateFirstAttempt(RetryingContext)insteadCreates a first attemptTimedAttemptSettings.- Returns:
- first attempt settings
-
createFirstAttempt
public TimedAttemptSettings createFirstAttempt(RetryingContext context)
Creates a first attemptTimedAttemptSettings.- Parameters:
context- theRetryingContextthat can be used to get the initialRetrySettings- Returns:
- first attempt settings
-
createNextAttempt
@Deprecated public TimedAttemptSettings createNextAttempt(java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings previousSettings)
Deprecated.Creates a next attemptTimedAttemptSettings. This method will return first non-null value, returned by either result or timed retry algorithms in that particular order.- Parameters:
previousThrowable- exception thrown by the previous attempt or null if a result was returned insteadpreviousResponse- response returned by the previous attempt or null if an exception was thrown insteadpreviousSettings- previous attempt settings- Returns:
- next attempt settings, can be
null, if no there should be no new attempt
-
createNextAttempt
public TimedAttemptSettings createNextAttempt(RetryingContext context, java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings previousSettings)
Creates a next attemptTimedAttemptSettings. This method will return first non-null value, returned by either result or timed retry algorithms in that particular order.- Parameters:
context- theRetryingContextthat can be used to determine theRetrySettingsfor the next attemptpreviousThrowable- exception thrown by the previous attempt or null if a result was returned insteadpreviousResponse- response returned by the previous attempt or null if an exception was thrown insteadpreviousSettings- previous attempt settings- Returns:
- next attempt settings, can be
null, if there should be no new attempt
-
shouldRetry
@Deprecated public boolean shouldRetry(java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings nextAttemptSettings) throws java.util.concurrent.CancellationExceptionDeprecated.Returnstrueif another attempt should be made, orfalseotherwise.- Parameters:
previousThrowable- exception thrown by the previous attempt or null if a result was returned insteadpreviousResponse- response returned by the previous attempt or null if an exception was thrown insteadnextAttemptSettings- attempt settings, which will be used for the next attempt, if accepted- Returns:
trueif another attempt should be made, orfalseotherwise- Throws:
java.util.concurrent.CancellationException- if the retrying process should be canceled
-
shouldRetry
public boolean shouldRetry(RetryingContext context, java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings nextAttemptSettings) throws java.util.concurrent.CancellationException
Returnstrueif another attempt should be made, orfalseotherwise.- Parameters:
context- theRetryingContextthat can be used to determine whether another attempt should be madepreviousThrowable- exception thrown by the previous attempt or null if a result was returned insteadpreviousResponse- response returned by the previous attempt or null if an exception was thrown insteadnextAttemptSettings- attempt settings, which will be used for the next attempt, if accepted- Returns:
trueif another attempt should be made, orfalseotherwise- Throws:
java.util.concurrent.CancellationException- if the retrying process should be cancelled
-
getResultAlgorithm
@BetaApi("Surface for inspecting the a RetryAlgorithm is not yet stable") public ResultRetryAlgorithm<ResponseT> getResultAlgorithm()
-
getTimedAlgorithm
@BetaApi("Surface for inspecting the a RetryAlgorithm is not yet stable") public TimedRetryAlgorithm getTimedAlgorithm()
-
-