- 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
- Any thread may
pause()execution untilunpausedby another thread. - Any thread may
interrupt()allpausedthreads. - Any thread may
jointhe task thread to be notified when the task iscomplete. - Completed tasks must report
successorerrorstatus.
-
Method Summary
Modifier and TypeMethodDescriptionGets time elapsed since the task started.getError()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.getStart()Gets task execution start time.voidbooleanDetermines if task is completed.booleanDetermines if task was still executing when the timeout interval expired; the task may havecompleted successfullyafter expiring.booleanDetermines if the task completed successfully.voidjoin()Waits for task execution to complete.voidpause()Pauses the current thread untilunpausedor until the task is completed or expired.voidunpause()Unpauses all threads that invokedpause()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 havecompleted successfullyafter expiring.Attempting to
join()anexpiredtask should result inTimeoutExceptionbeing 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 orgetError()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 untilunpausedor 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 invokedpause()on this task. -
join
Waits for task execution to complete.Attempting to
join()anexpiredtask should result inTimeoutExceptionbeing thrown.- Throws:
ExecutionException- If anyThrowableis thrown from the task; the thrown value will be the causeInterruptedException- If the task is interrupted.TimeoutException- If the timeout interval expires.
-
interrupt
void interrupt()
-