Class RetryPolicy


  • public final class RetryPolicy
    extends java.lang.Object
    A declarative retry policy that can be configured for activity or sub-orchestration calls.
    • Constructor Summary

      Constructors 
      Constructor Description
      RetryPolicy​(int maxNumberOfAttempts, java.time.Duration firstRetryInterval)
      Creates a new RetryPolicy object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double getBackoffCoefficient()
      Gets the configured exponential backoff coefficient used to determine the delay between subsequent retries.
      java.time.Duration getFirstRetryInterval()
      Gets the configured amount of time to delay between the first and second attempt.
      int getMaxNumberOfAttempts()
      Gets the configured maximum number of task invocation attempts.
      java.time.Duration getMaxRetryInterval()
      Gets the configured maximum time to delay between attempts.
      java.time.Duration getRetryTimeout()
      Gets the configured overall timeout for retries.
      RetryPolicy setBackoffCoefficient​(double backoffCoefficient)
      Sets the exponential backoff coefficient used to determine the delay between subsequent retries.
      RetryPolicy setFirstRetryInterval​(java.time.Duration firstRetryInterval)
      Sets the amount of time to delay between the first and second attempt.
      RetryPolicy setMaxNumberOfAttempts​(int maxNumberOfAttempts)
      Sets the maximum number of task invocation attempts; must be 1 or greater.
      RetryPolicy setMaxRetryInterval​(java.time.Duration maxRetryInterval)
      Sets the maximum time to delay between attempts.
      RetryPolicy setRetryTimeout​(java.time.Duration retryTimeout)
      Sets the overall timeout for retries, regardless of the retry count.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RetryPolicy

        public RetryPolicy​(int maxNumberOfAttempts,
                           java.time.Duration firstRetryInterval)
        Creates a new RetryPolicy object.
        Parameters:
        maxNumberOfAttempts - the maximum number of task invocation attempts; must be 1 or greater
        firstRetryInterval - the amount of time to delay between the first and second attempt
        Throws:
        java.lang.IllegalArgumentException - if maxNumberOfAttempts is zero or negative
    • Method Detail

      • setMaxNumberOfAttempts

        public RetryPolicy setMaxNumberOfAttempts​(int maxNumberOfAttempts)
        Sets the maximum number of task invocation attempts; must be 1 or greater.

        This value represents the number of times to attempt to execute the task. It does not represent the maximum number of times to retry the task. This is why the number must be 1 or greater.

        Parameters:
        maxNumberOfAttempts - the maximum number of attempts; must be 1 or greater
        Returns:
        this retry policy object
        Throws:
        java.lang.IllegalArgumentException - if maxNumberOfAttempts is zero or negative
      • setFirstRetryInterval

        public RetryPolicy setFirstRetryInterval​(java.time.Duration firstRetryInterval)
        Sets the amount of time to delay between the first and second attempt.
        Parameters:
        firstRetryInterval - the amount of time to delay between the first and second attempt
        Returns:
        this retry policy object
        Throws:
        java.lang.IllegalArgumentException - if firstRetryInterval is null, zero, or negative.
      • setBackoffCoefficient

        public RetryPolicy setBackoffCoefficient​(double backoffCoefficient)
        Sets the exponential backoff coefficient used to determine the delay between subsequent retries. Must be 1.0 or greater.

        To avoid extremely long delays between retries, consider also specifying a maximum retry interval using the setMaxRetryInterval(java.time.Duration) method.

        Parameters:
        backoffCoefficient - the exponential backoff coefficient
        Returns:
        this retry policy object
        Throws:
        java.lang.IllegalArgumentException - if backoffCoefficient is less than 1.0
      • setMaxRetryInterval

        public RetryPolicy setMaxRetryInterval​(@Nullable
                                               java.time.Duration maxRetryInterval)
        Sets the maximum time to delay between attempts.

        It's recommended to set a maximum retry interval whenever using a backoff coefficient that's greater than the default of 1.0.

        Parameters:
        maxRetryInterval - the maximum time to delay between attempts or null to remove the maximum retry interval
        Returns:
        this retry policy object
      • setRetryTimeout

        public RetryPolicy setRetryTimeout​(java.time.Duration retryTimeout)
        Sets the overall timeout for retries, regardless of the retry count.
        Parameters:
        retryTimeout - the overall timeout for retries
        Returns:
        this retry policy object
      • getMaxNumberOfAttempts

        public int getMaxNumberOfAttempts()
        Gets the configured maximum number of task invocation attempts.
        Returns:
        the configured maximum number of task invocation attempts.
      • getFirstRetryInterval

        public java.time.Duration getFirstRetryInterval()
        Gets the configured amount of time to delay between the first and second attempt.
        Returns:
        the configured amount of time to delay between the first and second attempt
      • getBackoffCoefficient

        public double getBackoffCoefficient()
        Gets the configured exponential backoff coefficient used to determine the delay between subsequent retries.
        Returns:
        the configured exponential backoff coefficient used to determine the delay between subsequent retries
      • getMaxRetryInterval

        public java.time.Duration getMaxRetryInterval()
        Gets the configured maximum time to delay between attempts.
        Returns:
        the configured maximum time to delay between attempts
      • getRetryTimeout

        public java.time.Duration getRetryTimeout()
        Gets the configured overall timeout for retries.
        Returns:
        the configured overall timeout for retries