Class RetryableAction<T>
- java.lang.Object
-
- com.google.gerrit.server.update.RetryableAction<T>
-
- Direct Known Subclasses:
RetryableChangeAction
,RetryableIndexQueryAction
public class RetryableAction<T> extends Object
An action that is executed with retrying.Instances of this class are created via
RetryHelper
(seeRetryHelper.action(ActionType, String, Action)
,RetryHelper.accountUpdate(String, Action)
,RetryHelper.changeUpdate(String, Action)
,RetryHelper.groupUpdate(String, Action)
,RetryHelper.pluginUpdate(String, Action)
).Which exceptions cause a retry is controlled by
ExceptionHook.shouldRetry(String, String, Throwable)
. In addition callers can specify additional exception that should cause a retry viaretryOn(Predicate)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RetryableAction.Action<T>
static class
RetryableAction.ActionType
Type of an retryable action.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
call()
Executes this action with retry.RetryableAction<T>
defaultTimeoutMultiplier(int multiplier)
Increases the default timeout by the given multiplier.RetryableAction<T>
listener(com.github.rholder.retry.RetryListener retryListener)
Sets a listener that is invoked when the action is retried.RetryableAction<T>
onAutoTrace(Consumer<String> traceIdConsumer)
Sets a callback that is invoked when auto-retry with tracing is triggered.RetryableAction<T>
retryOn(Predicate<Throwable> exceptionPredicate)
Adds an additional condition that should trigger retries.RetryableAction<T>
retryWithTrace(Predicate<Throwable> exceptionPredicate)
Sets a condition that should trigger auto-retry with tracing.
-
-
-
Method Detail
-
retryOn
public RetryableAction<T> retryOn(Predicate<Throwable> exceptionPredicate)
Adds an additional condition that should trigger retries.For some exceptions retrying is enabled globally (see
ExceptionHook.shouldRetry(String, String, Throwable)
). Conditions for those exceptions do not need to be specified here again.This method can be invoked multiple times to add further conditions that should trigger retries.
- Parameters:
exceptionPredicate
- predicate that decides if the action should be retried for a given exception- Returns:
- this instance to enable chaining of calls
-
retryWithTrace
public RetryableAction<T> retryWithTrace(Predicate<Throwable> exceptionPredicate)
Sets a condition that should trigger auto-retry with tracing.This condition is only relevant if an exception occurs that doesn't trigger (normal) retry.
Auto-retry with tracing automatically captures traces for unexpected exceptions so that they can be investigated.
Every call of this method overwrites any previously set condition for auto-retry with tracing.
- Parameters:
exceptionPredicate
- predicate that decides if the action should be retried with tracing for a given exception- Returns:
- this instance to enable chaining of calls
-
onAutoTrace
public RetryableAction<T> onAutoTrace(Consumer<String> traceIdConsumer)
Sets a callback that is invoked when auto-retry with tracing is triggered.Via the callback callers can find out with trace ID was used for the retry.
Every call of this method overwrites any previously set trace ID consumer.
- Parameters:
traceIdConsumer
- trace ID consumer- Returns:
- this instance to enable chaining of calls
-
listener
public RetryableAction<T> listener(com.github.rholder.retry.RetryListener retryListener)
Sets a listener that is invoked when the action is retried.Every call of this method overwrites any previously set listener.
- Parameters:
retryListener
- retry listener- Returns:
- this instance to enable chaining of calls
-
defaultTimeoutMultiplier
public RetryableAction<T> defaultTimeoutMultiplier(int multiplier)
Increases the default timeout by the given multiplier.Every call of this method overwrites any previously set timeout.
- Parameters:
multiplier
- multiplier for the default timeout- Returns:
- this instance to enable chaining of calls
-
-