Package com.google.api.gax.retrying
Class StreamingRetryAlgorithm<ResponseT>
- java.lang.Object
-
- com.google.api.gax.retrying.RetryAlgorithm<ResponseT>
-
- com.google.api.gax.retrying.StreamingRetryAlgorithm<ResponseT>
-
@InternalApi("For internal use only") public final class StreamingRetryAlgorithm<ResponseT> extends RetryAlgorithm<ResponseT>
The streaming retry algorithm, which makes decision based either on the thrown exception and the execution time settings of the previous attempt. This extendsRetryAlgorithm
to take additional information (provided byServerStreamingAttemptCallable
) into account.This class is thread-safe.
Internal use only - public for technical reasons.
-
-
Constructor Summary
Constructors Constructor Description StreamingRetryAlgorithm(ResultRetryAlgorithm<ResponseT> resultAlgorithm, TimedRetryAlgorithm timedAlgorithm)
Deprecated.StreamingRetryAlgorithm(ResultRetryAlgorithmWithContext<ResponseT> resultAlgorithm, TimedRetryAlgorithmWithContext timedAlgorithm)
Creates aStreamingRetryAlgorithm
that will use the settings (if any) in theRetryingContext
that is passed in to the retrying methods.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
Creates a next attemptTimedAttemptSettings
.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)
Returnstrue
if another attempt should be made, orfalse
otherwise.-
Methods inherited from class com.google.api.gax.retrying.RetryAlgorithm
createFirstAttempt, createFirstAttempt, getResultAlgorithm, getTimedAlgorithm
-
-
-
-
Constructor Detail
-
StreamingRetryAlgorithm
@Deprecated public StreamingRetryAlgorithm(ResultRetryAlgorithm<ResponseT> resultAlgorithm, TimedRetryAlgorithm timedAlgorithm)
Deprecated.Instances that are created using this constructor will ignore theRetryingContext
that is passed in to the retrying methods. UseStreamingRetryAlgorithm(ResultRetryAlgorithmWithContext, TimedRetryAlgorithmWithContext)
to create an instance that will respect theRetryingContext
.
-
StreamingRetryAlgorithm
public StreamingRetryAlgorithm(ResultRetryAlgorithmWithContext<ResponseT> resultAlgorithm, TimedRetryAlgorithmWithContext timedAlgorithm)
Creates aStreamingRetryAlgorithm
that will use the settings (if any) in theRetryingContext
that is passed in to the retrying methods.
-
-
Method Detail
-
createNextAttempt
public TimedAttemptSettings createNextAttempt(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.The attempt settings will be reset if the stream attempt produced any messages.
- Overrides:
createNextAttempt
in classRetryAlgorithm<ResponseT>
- 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.The attempt settings will be reset if the stream attempt produced any messages.
- Overrides:
createNextAttempt
in classRetryAlgorithm<ResponseT>
- 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
public boolean shouldRetry(java.lang.Throwable previousThrowable, ResponseT previousResponse, TimedAttemptSettings nextAttemptSettings) throws java.util.concurrent.CancellationException
Returnstrue
if another attempt should be made, orfalse
otherwise.Ensures retries are only scheduled if the
StreamResumptionStrategy
in theServerStreamingAttemptCallable
supports it.- Overrides:
shouldRetry
in classRetryAlgorithm<ResponseT>
- 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.Schedules retries only if the
StreamResumptionStrategy
in theServerStreamingAttemptCallable
supports it.- Overrides:
shouldRetry
in classRetryAlgorithm<ResponseT>
- 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
-
-