Package hudson.util

Class Retrier.Builder<V>

  • Type Parameters:
    V - The return type of the action to perform.
    Enclosing class:
    Retrier<V>

    public static class Retrier.Builder<V>
    extends Object
    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 Detail

      • 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 perform
        checkResult - Method to check if the result of the action was a success
        action - name of the action to perform, for messages purposes.
    • Method Detail

      • withAttempts

        @NonNull
        public Retrier.Builder<V> withAttempts​(int attempts)
        Set the number of attempts trying to perform the action.
        Parameters:
        attempts - number of attempts
        Returns:
        this builder
      • withDelay

        @NonNull
        public Retrier.Builder<V> withDelay​(long millis)
        Set the time in milliseconds to wait for the next attempt.
        Parameters:
        millis - milliseconds to wait
        Returns:
        this builder
      • withDuringActionExceptions

        @NonNull
        public Retrier.Builder<V> withDuringActionExceptions​(@CheckForNull
                                                             Class<?>[] exceptions)
        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

        @NonNull
        public Retrier<V> build()
        Create a Retrier object with the specification set in this builder.
        Returns:
        the retrier