Class AbstractRetryScheduler.Builder<B extends AbstractRetryScheduler.Builder>

java.lang.Object
org.axonframework.commandhandling.gateway.AbstractRetryScheduler.Builder<B>
Direct Known Subclasses:
ExponentialBackOffIntervalRetryScheduler.Builder, IntervalRetryScheduler.Builder
Enclosing class:
AbstractRetryScheduler

public abstract static class AbstractRetryScheduler.Builder<B extends AbstractRetryScheduler.Builder> extends Object
A builder class for the RetryScheduler implementations.

The default for maxRetryCount is set to a single retry and the nonTransientFailurePredicate defaults to AxonNonTransientExceptionClassesPredicate. The ScheduledExecutorService is a hard requirement and as such should be provided.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • retryExecutor

      public B retryExecutor(@Nonnull ScheduledExecutorService retryExecutor)
      Sets the ScheduledExecutorService used to schedule a command retry.
      Parameters:
      retryExecutor - a ScheduledExecutorService used to schedule a command retry
      Returns:
      the current Builder instance, for fluent interfacing
    • nonTransientFailurePredicate

      public B nonTransientFailurePredicate(@Nonnull Predicate<Throwable> nonTransientFailurePredicate)
      Resets the Predicate chain used for checking non-transiency of a failure. Throws away any previously existing predicate chain and replaces it with the provided predicate.

      Provided nonTransientFailurePredicate checks whether a failure is transient (predicate returns false) or not (predicate returns true). Non-transient failures are never retried.

      Parameters:
      nonTransientFailurePredicate - a Predicate (accepting a Throwable parameter) used for testing transiency of provided failure
      Returns:
      the current Builder instance, for fluent interfacing
    • nonTransientFailurePredicate

      public <E extends Throwable> B nonTransientFailurePredicate(@Nonnull Class<E> failureType, @Nonnull Predicate<? super E> nonTransientFailurePredicate)
      Resets the Predicate chain used for checking non-transiency of a failure. Throws away any previously existing predicate chain and replaces it with the provided predicate.

      Provided nonTransientFailurePredicate checks whether a failure is transient (predicate returns false) or not (predicate returns true). Non-transient failures are never retried.

      In essence, this is just a failure typed variant of nonTransientFailurePredicate(Predicate) method.

      Type Parameters:
      E - type of the failure to handle
      Parameters:
      failureType - concrete class of the failure to handle
      nonTransientFailurePredicate - a Predicate (accepting a failureType parameter) used for testing transiency of provided failure
      Returns:
      the current Builder instance, for fluent interfacing
    • addNonTransientFailurePredicate

      public B addNonTransientFailurePredicate(@Nonnull Predicate<Throwable> nonTransientFailurePredicate)
      Adds additional predicate into the predicate chain for checking non-transiency of a failure.

      Provided nonTransientFailurePredicate is set on the beginning of the predicate chain with the Predicate#or operator.

      Parameters:
      nonTransientFailurePredicate - an additional Predicate (accepting a Throwable parameter) to be added into the predicate chain used for testing transiency of provided failure
      Returns:
      the current Builder instance, for fluent interfacing
    • addNonTransientFailurePredicate

      public <E extends Throwable> B addNonTransientFailurePredicate(@Nonnull Class<E> failureType, @Nonnull Predicate<? super E> nonTransientFailurePredicate)
      Adds additional predicate into the predicate chain for checking non-transiency of a failure.

      Provided nonTransientFailurePredicate is set on the beginning of the predicate chain with or operator.

      In essence, this is just a failure typed variant of addNonTransientFailurePredicate(Predicate) method.

      Type Parameters:
      E - type of the failure to handle
      Parameters:
      failureType - concrete class of the failure to handle
      nonTransientFailurePredicate - an additional Predicate (accepting a failure parameter) to be added into the predicate chain used for testing transiency of provided failure
      Returns:
      the current Builder instance, for fluent interfacing
    • maxRetryCount

      public B maxRetryCount(int maxRetryCount)
      Sets the maximum number of retries allowed for a single command. Defaults to 1.
      Parameters:
      maxRetryCount - an int specifying the maximum number of retries allowed for a single command
      Returns:
      the current Builder instance, for fluent interfacing
    • validate

      protected void validate() throws AxonConfigurationException
      Validate the fields. This method is called in the AbstractRetryScheduler's constructor.
      Throws:
      AxonConfigurationException - if validation fails.