- 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 untilunpaused
by another thread. - Any thread may
interrupt()
allpaused
threads. - Any thread may
join
the task thread to be notified when the task iscomplete
. - Completed tasks must report
success
orerror
status.
-
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.void
boolean
Determines if task is completed.boolean
Determines if task was still executing when the timeout interval expired; the task may havecompleted successfully
after expiring.boolean
Determines if the task completed successfully.void
join()
Waits for task execution to complete.void
pause()
Pauses the current thread untilunpaused
or until the task is completed or expired.void
unpause()
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 successfully
after expiring.Attempting to
join()
anexpired
task should result inTimeoutException
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 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 untilunpaused
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 invokedpause()
on this task. -
join
Waits for task execution to complete.Attempting to
join()
anexpired
task should result inTimeoutException
being thrown.- Throws:
ExecutionException
- If anyThrowable
is 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()
-