Package hudson.util
Class Retrier.Builder<V>
java.lang.Object
hudson.util.Retrier.Builder<V>
- Type Parameters:
V
- The return type of the action to perform.
Builder to create a Retrier object. The action to perform, the way of check whether is was
successful and the name of the action are required.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Create a Retrier object with the specification set in this builder.withAttempts
(int attempts) Set the number of attempts trying to perform the action.withDelay
(long millis) Set the time in milliseconds to wait for the next attempt.withDuringActionExceptionListener
(BiFunction<Integer, Exception, V> exceptionListener) Set the listener to be executed when an allowed exception is raised when performing the action.withDuringActionExceptions
(Class<?>[] exceptions) Set all the exceptions that are allowed and indicate that the action was failed.
-
Constructor Details
-
Builder
public Builder(@NonNull Callable<V> callable, @NonNull BiPredicate<Integer, V> checkResult, @NonNull String action) Constructor of the builder with the required parameters.- Parameters:
callable
- Action to performcheckResult
- Method to check if the result of the action was a successaction
- name of the action to perform, for messages purposes.
-
-
Method Details
-
withAttempts
Set the number of attempts trying to perform the action.- Parameters:
attempts
- number of attempts- Returns:
- this builder
-
withDelay
Set the time in milliseconds to wait for the next attempt.- Parameters:
millis
- milliseconds to wait- Returns:
- this builder
-
withDuringActionExceptions
Set all the exceptions that are allowed and indicate that the action was failed. When an exception of this type or a child type is raised, a listener can be called (withDuringActionExceptionListener(BiFunction)
). In any case, the retrier continues its process, retrying to perform the action again, as it was a normal failure.- Parameters:
exceptions
- exceptions that indicate that the action was failed.- Returns:
- this builder
-
withDuringActionExceptionListener
@NonNull public Retrier.Builder<V> withDuringActionExceptionListener(@NonNull BiFunction<Integer, Exception, V> exceptionListener) Set the listener to be executed when an allowed exception is raised when performing the action. The listener could even change the result of the action if needed.- Parameters:
exceptionListener
- the listener to call to- Returns:
- this builder
-
build
Create a Retrier object with the specification set in this builder.- Returns:
- the retrier
-