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.Object
The 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 TimedAttemptSettings
createFirstAttempt()
Deprecated.usecreateFirstAttempt(RetryingContext)
insteadTimedAttemptSettings
createFirstAttempt(RetryingContext context)
Creates a first attemptTimedAttemptSettings
.TimedAttemptSettings
createNextAttempt(RetryingContext context, java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings previousSettings)
Creates a next attemptTimedAttemptSettings
.TimedAttemptSettings
createNextAttempt(java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings previousSettings)
Deprecated.ResultRetryAlgorithm<ResponseT>
getResultAlgorithm()
TimedRetryAlgorithm
getTimedAlgorithm()
boolean
shouldRetry(RetryingContext context, java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings nextAttemptSettings)
Returnstrue
if another attempt should be made, orfalse
otherwise.boolean
shouldRetry(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
RetryingContext
that 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
- theRetryingContext
that 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
- theRetryingContext
that can be used to determine theRetrySettings
for 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.CancellationException
Deprecated.Returnstrue
if another attempt should be made, orfalse
otherwise.- 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:
true
if another attempt should be made, orfalse
otherwise- 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
Returnstrue
if another attempt should be made, orfalse
otherwise.- Parameters:
context
- theRetryingContext
that 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:
true
if another attempt should be made, orfalse
otherwise- 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()
-
-