Module iu.util
Package edu.iu

Interface IuTaskController

All Known Implementing Classes:
IuRateLimitter

public interface IuTaskController
Controls an asynchronous task.

Tasks are managed, e.g., by IuParallelWorkloadController, which provides a single IuTaskController instance to both the controlling thread and a managed task thread. Either thread may distribute this IuTaskController instance freely to other controlling threads threads and may use the interface directly to influence execution of the task thread

UML Sequence Diagram
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets time elapsed since the task started.
    Gets an error thrown by the task.
    Gets the point in time the timeout interval expires, or expired.
    Gets time remaining until the task expires.
    Gets task execution start time.
    void
    Interrupts all threads that invoked pause() or join() on this task.
    boolean
    Determines if task is completed.
    boolean
    Determines if task was still executing when the timeout interval expired; the task may have completed successfully after expiring.
    boolean
    Determines if the task completed successfully.
    void
    Waits for task execution to complete.
    void
    Pauses the current thread until unpaused or until the task is completed or expired.
    void
    Unpauses all threads that invoked pause() on this task.
  • Method Details

    • getStart

      Instant getStart()
      Gets task execution start time.
      Returns:
      start time; null if the task has not started executing
    • getElapsed

      Duration getElapsed()
      Gets time elapsed since the task started.
      Returns:
      elapsed time; execution time if the task is completed, null if the task has not started
    • getRemaining

      Duration getRemaining()
      Gets time remaining until the task expires.
      Returns:
      remaining time until the task expires; zero if the task completed within the timeout interval, negative to represent post-expiration processing time if expired and incomplete or completed after the timeout interval.
    • getExpires

      Instant getExpires()
      Gets the point in time the timeout interval expires, or expired.
      Returns:
      Instant
    • isExpired

      boolean isExpired()
      Determines if task was still executing when the timeout interval expired; the task may have completed successfully after expiring.

      Attempting to join() an expired task should result in TimeoutException being thrown.

      Returns:
      true if the task was still executing when the timeout interval expired; else false, the task completed or is still executing and the interval hasn't expired.
    • isComplete

      boolean isComplete()
      Determines if task is completed.
      Returns:
      true if the task has completed: either isSuccess() will returns true or getError() returns a non-null value; false indicates the task has not started or is still executing.
    • isSuccess

      boolean isSuccess()
      Determines if the task completed successfully.
      Returns:
      true if the task completed successfully.
    • getError

      Throwable getError()
      Gets an error thrown by the task.
      Returns:
      error, if thrown by the task; else null
    • pause

      Pauses the current thread until unpaused or until the task is completed or expired.

      The state of the current thread is not guaranteed upon completion. The application using this interface is responsible for inspecting and/or updating after the pause is complete.

      Throws:
      TimeoutException - If the timeout interval is reached while paused.
      InterruptedException - If the current thread is interrupted while paused.
    • unpause

      void unpause()
      Unpauses all threads that invoked pause() on this task.
    • join

      Waits for task execution to complete.

      Attempting to join() an expired task should result in TimeoutException being thrown.

      Throws:
      ExecutionException - If any Throwable is thrown from the task; the thrown value will be the cause
      InterruptedException - If the task is interrupted.
      TimeoutException - If the timeout interval expires.
    • interrupt

      void interrupt()
      Interrupts all threads that invoked pause() or join() on this task.