Package com.glitchybyte.glib.concurrent
Interface GTaskRunner
- All Superinterfaces:
Executor
- All Known Implementing Classes:
GTaskRunnerService
A task runner facility to run
GTask tasks.
Classes ending in 'Task' in the concurrent package must be started with
a GTaskRunner.
This runner is also capable of running standalone Runnables and
Callables. This avoids having to create, or keep track of, a separate
ExecutorService. Keep in mind this class uses platform threads.
-
Method Summary
Modifier and TypeMethodDescription<V> CompletableFuture<V> Submits aCallableto execute concurrently.<V> List<CompletableFuture<V>> callAll(Collection<Callable<V>> callables) Submits a collection ofCallableto execute concurrently.<V> List<CompletableFuture<V>> Submits an array ofCallableto execute concurrently.Submits aRunnableto execute concurrently.Submits an array ofRunnableto execute concurrently.runAll(Collection<Runnable> runnables) Submits a collection ofRunnableto execute concurrently.<T extends GTask>
Tstart(T task) Submits a task to be run concurrently.<T extends GTask>
TSubmits a task to execute concurrently.
-
Method Details
-
run
Submits aRunnableto execute concurrently.- Parameters:
runnable- ARunnableto execute.- Returns:
- A
CompletableFuture<Void>representing pending completion of the task. - Throws:
RejectedExecutionException- If the task cannot be scheduled for execution.
-
runAll
List<CompletableFuture<Void>> runAll(Collection<Runnable> runnables) throws RejectedExecutionException Submits a collection ofRunnableto execute concurrently.- Parameters:
runnables- A collection ofRunnableto execute.- Returns:
- A list of
CompletableFuture<Void>representing pending completion of the tasks. - Throws:
RejectedExecutionException- If one the tasks cannot be scheduled for execution.
-
runAll
Submits an array ofRunnableto execute concurrently.- Parameters:
runnables- An array ofRunnableto execute.- Returns:
- A list of
CompletableFuture<Void>representing pending completion of the tasks. - Throws:
RejectedExecutionException- If one the tasks cannot be scheduled for execution.
-
call
Submits aCallableto execute concurrently.- Type Parameters:
V- Type of task result.- Parameters:
callable- ACallableto execute.- Returns:
- A
CompletableFuturerepresenting pending completion of the task. - Throws:
RejectedExecutionException- If the task cannot be scheduled for execution.
-
callAll
<V> List<CompletableFuture<V>> callAll(Collection<Callable<V>> callables) throws RejectedExecutionException Submits a collection ofCallableto execute concurrently.- Type Parameters:
V- Type of task result.- Parameters:
callables- A collection ofCallableto execute.- Returns:
- A list of
CompletableFuturerepresenting pending completion of the tasks. - Throws:
RejectedExecutionException- If one of the tasks cannot be scheduled for execution.
-
callAll
Submits an array ofCallableto execute concurrently.- Type Parameters:
V- Type of task result.- Parameters:
callables- An array ofCallableto execute.- Returns:
- A list of
CompletableFuturerepresenting pending completion of the tasks. - Throws:
RejectedExecutionException- If one the tasks cannot be scheduled for execution.
-
start
<T extends GTask> T start(T task, Duration timeout) throws InterruptedException, RejectedExecutionException Submits a task to execute concurrently.If the task does not start within the given timeout, an
IllegalStateExceptionwill be raised as this is considered a bug in the task implementation.This method blocks until the task has started.
- Type Parameters:
T- Task type.- Parameters:
task- Task to start.timeout- Time given to the task to start.- Returns:
- The started task.
- Throws:
InterruptedException- If the thread is interrupted while waiting for the task to start.RejectedExecutionException- If the task cannot be scheduled for execution.
-
start
Submits a task to be run concurrently.If the task does not start within 5 seconds, an
IllegalStateExceptionwill be raised as this is considered a bug in the task implementation.This method blocks until the task has started.
- Type Parameters:
T- Task type.- Parameters:
task- Task to start.- Returns:
- The started task.
- Throws:
InterruptedException- If the thread is interrupted while waiting for the task to start.RejectedExecutionException- If the task cannot be scheduled for execution.
-