Class RetryTask

  • All Implemented Interfaces:

    
    public abstract class RetryTask
    
                        

    Class describes a retry task executed by RetryStrategy. It has the following properties:

    initialDelay - specifies the time before this task is launched for the first timeretryDelay - tells how much time we wait before next retry attempt. Subclass can override getRetryDelay in order to provide dynamic value which can be different for each retrygetCallable - a Callable which is the job to be executed by retry strategy. The task will be retried as long as it returns true or until the job is cancelled. retryAfterException - indicates if retries should be continued after uncaught exception is thrown by retry callable task cancelled - indicates if RetryStrategy and this task has been cancelled using cancel. This does not interrupt currently executing task.
    Author:

    Pawel Domas

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final long initialDelay
      public final long retryDelay
    • Constructor Summary

      Constructors 
      Constructor Description
      RetryTask(long initialDelay, long retryDelay, boolean retryOnException) Initializes new instance of RetryTask.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      long getInitialDelay() Returns the time in ms before this task is launched for the first time.
      long getRetryDelay() Returns the delay in ms that we wait before next retry attempt.
      abstract Callable<Boolean> getCallable() Returns a Callable which is the job to be executed by retry strategy.
      boolean willRetryAfterException() Indicates if we're going to continue retry task scheduling after the callable throws unexpected exception.
      boolean isCancelled() Returns true if this task has been cancelled.
      void setRetryAfterException(boolean retryAfterException) Should we continue retries after the callable throws unexpected exception ?
      void setCancelled(boolean cancelled) Method is called by RetryStrategy when it gets cancelled.
      • Methods inherited from class java.lang.Object

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

      • RetryTask

        RetryTask(long initialDelay, long retryDelay, boolean retryOnException)
        Initializes new instance of RetryTask.
        Parameters:
        initialDelay - how long we're going to wait before running task callable for the first time(in ms).
        retryDelay - how often are we going to retry(in ms).
        retryOnException - should we continue retry after callable throws unexpected Exception.
    • Method Detail

      • getInitialDelay

         long getInitialDelay()

        Returns the time in ms before this task is launched for the first time.

      • getRetryDelay

         long getRetryDelay()

        Returns the delay in ms that we wait before next retry attempt.

      • getCallable

         abstract Callable<Boolean> getCallable()

        Returns a Callable which is the job to be executed by retry strategy. The task will be retried as long as it returns true or until the job is cancelled.

      • willRetryAfterException

         boolean willRetryAfterException()

        Indicates if we're going to continue retry task scheduling after the callable throws unexpected exception.

      • isCancelled

         boolean isCancelled()

        Returns true if this task has been cancelled.

      • setRetryAfterException

         void setRetryAfterException(boolean retryAfterException)

        Should we continue retries after the callable throws unexpected exception ?

        Parameters:
        retryAfterException - true to continue retries even though unexpected exception is thrown by the callable, otherwise retry strategy will be cancelled when that happens.
      • setCancelled

         void setCancelled(boolean cancelled)

        Method is called by RetryStrategy when it gets cancelled.

        Parameters:
        cancelled - true when this task is being cancelled.