Record Class RetryPolicy

java.lang.Object
java.lang.Record
io.axoniq.framework.workflow.dsl.api.retry.RetryPolicy
Record Components:
maxRetries - maximum number of retry attempts.
onRetryHandler - handler invoked before each retry event is published.
backoffStrategy - backoff strategy between retry attempts.
retryPredicate - predicate evaluated on each retry; returns true to continue retrying, false to stop. Checked in addition to maxRetries.

public record RetryPolicy(int maxRetries, RetryHandler onRetryHandler, BackoffStrategy backoffStrategy, Predicate<RetryContext> retryPredicate) extends Record
Retry policy for execute steps. maxRetries is the number of retry attempts (not counting the initial attempt). maxRetries=3 means up to 4 total executions.
Since:
5.4.0
Author:
Stefan Dragisic
  • Field Details

    • NONE

      public static final RetryPolicy NONE
      Constant retry policy that disables retries entirely.
  • Constructor Details

    • RetryPolicy

      public RetryPolicy(int maxRetries, RetryHandler onRetryHandler, BackoffStrategy backoffStrategy)
      Creates a retry policy with explicit retry count, retry hook, and backoff strategy.
      Parameters:
      maxRetries - maximum number of retry attempts
      onRetryHandler - handler invoked before each retry event is published
      backoffStrategy - backoff strategy between retry attempts
    • RetryPolicy

      public RetryPolicy(int maxRetries, RetryHandler onRetryHandler)
      Creates a retry policy with explicit retry count and retry hook, using no backoff.
      Parameters:
      maxRetries - maximum number of retry attempts
      onRetryHandler - handler invoked before each retry event is published
    • RetryPolicy

      public RetryPolicy(int maxRetries, RetryHandler onRetryHandler, BackoffStrategy backoffStrategy, Predicate<RetryContext> retryPredicate)
      Creates an instance of a RetryPolicy record class.
      Parameters:
      maxRetries - the value for the maxRetries record component
      onRetryHandler - the value for the onRetryHandler record component
      backoffStrategy - the value for the backoffStrategy record component
      retryPredicate - the value for the retryPredicate record component
  • Method Details

    • maxRetries

      public static RetryPolicy maxRetries(int maxRetries)
      Creates a retry policy with the provided retry count and no-op retry handling.
      Parameters:
      maxRetries - maximum number of retry attempts
      Returns:
      retry policy with the provided retry count
    • onRetry

      public RetryPolicy onRetry(RetryHandler handler)
      Returns a copy of this retry policy with the provided retry handler.
      Parameters:
      handler - handler invoked before each retry event is published
      Returns:
      copied retry policy with updated retry handler
    • withBackoff

      public RetryPolicy withBackoff(BackoffStrategy strategy)
      Returns a copy of this retry policy with the provided backoff strategy.
      Parameters:
      strategy - backoff strategy between retry attempts
      Returns:
      copied retry policy with updated backoff strategy
    • retryWhile

      public RetryPolicy retryWhile(Predicate<RetryContext> predicate)
      Returns a copy of this retry policy with the provided retry predicate.
      Parameters:
      predicate - predicate controlling whether retrying may continue
      Returns:
      copied retry policy with updated retry predicate
    • shouldRetry

      public boolean shouldRetry(RetryContext context)
      Evaluates whether the supplied retry context permits another retry attempt.
      Parameters:
      context - retry context for the current failure
      Returns:
      true when retrying should continue, otherwise false
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • maxRetries

      public int maxRetries()
      Returns the value of the maxRetries record component.
      Returns:
      the value of the maxRetries record component
    • onRetryHandler

      public RetryHandler onRetryHandler()
      Returns the value of the onRetryHandler record component.
      Returns:
      the value of the onRetryHandler record component
    • backoffStrategy

      public BackoffStrategy backoffStrategy()
      Returns the value of the backoffStrategy record component.
      Returns:
      the value of the backoffStrategy record component
    • retryPredicate

      public Predicate<RetryContext> retryPredicate()
      Returns the value of the retryPredicate record component.
      Returns:
      the value of the retryPredicate record component