- java.lang.Object
-
- aeonics.entity.Entity
-
- aeonics.manager.Manager.Type
-
- aeonics.manager.Executor
-
- All Implemented Interfaces:
Exportable
,Snapshotable
public abstract class Executor extends Manager.Type
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Executor.Task<T>
This class represents a task that is running, is done or will run in the future.
-
Constructor Summary
Constructors Constructor Description Executor()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static Executor.Task<java.lang.Void>
all(java.util.List<Executor.Task<?>> tasks, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.all(List, java.util.concurrent.Executor)
protected static <U> Executor.Task<U>
async(Functions.Supplier<U> task, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.async(aeonics.util.Functions.Supplier, java.util.concurrent.Executor)
Executor.Task<java.lang.Void>
background(Functions.Runnable task)
Schedules the specified task to run in the background.abstract <T> Executor.Task<T>
background(Functions.Supplier<T> task)
Schedules the specified task to run in the background.abstract Executor.Task<java.lang.Void>
background(java.util.List<Executor.Task<?>> tasks)
Returns a new background task that completes when all tasks are completed (successfully or not).abstract Executor.Task<java.lang.Void>
backgroundFailed(java.lang.Throwable error)
Create a failed background task.abstract <T> Executor.Task<T>
backgroundResolved(T value)
Create an already resolved background task.protected static <T> Executor.Task<T>
completed(T value, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.completed(Object, java.util.concurrent.Executor)
protected static Executor.Task<java.lang.Void>
failed(java.lang.Throwable value, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.failed(Throwable, java.util.concurrent.Executor)
Executor.Task<java.lang.Void>
io(Functions.Runnable task)
Schedules the specified I/O task to run.abstract <T> Executor.Task<T>
io(Functions.Supplier<T> task)
Schedules the specified I/O task to run.abstract Executor.Task<java.lang.Void>
io(java.util.List<Executor.Task<?>> tasks)
Returns a new io task that completes when all tasks are completed (successfully or not).abstract Executor.Task<java.lang.Void>
ioFailed(java.lang.Throwable error)
Create a failed io task.abstract <T> Executor.Task<T>
ioResolved(T value)
Create an already resolved io task.boolean
isBackground()
Returns true if the current thread is a background thread managed by this executor.abstract boolean
isBackground(java.lang.Thread thread)
Returns true if the specified thread is a background thread managed by this executor.boolean
isIo()
Returns true if the current thread is an io thread managed by this executor.abstract boolean
isIo(java.lang.Thread thread)
Returns true if the specified thread is an io thread managed by this executor.boolean
isNormal()
Returns true if the current thread is a normal thread managed by this executor.abstract boolean
isNormal(java.lang.Thread thread)
Returns true if the specified thread is a normal thread managed by this executor.boolean
isPriority()
Returns true if the current thread is a priority thread managed by this executor.abstract boolean
isPriority(java.lang.Thread thread)
Returns true if the specified thread is a priority thread managed by this executor.java.lang.Class<? extends Manager.Type>
manager()
Hardcoded manager typeExecutor.Task<java.lang.Void>
normal(Functions.Runnable task)
Schedules the specified task to run.abstract <T> Executor.Task<T>
normal(Functions.Supplier<T> task)
Schedules the specified task to run.abstract Executor.Task<java.lang.Void>
normal(java.util.List<Executor.Task<?>> tasks)
Returns a new normal task that completes when all tasks are completed (successfully or not).abstract Executor.Task<java.lang.Void>
normalFailed(java.lang.Throwable error)
Create a failed normal task.abstract <T> Executor.Task<T>
normalResolved(T value)
Create an already resolved normal task.Executor.Task<java.lang.Void>
priority(Functions.Runnable task)
Schedules the specified task to run in priority.abstract <T> Executor.Task<T>
priority(Functions.Supplier<T> task)
Schedules the specified task to run in priority.abstract Executor.Task<java.lang.Void>
priority(java.util.List<Executor.Task<?>> tasks)
Returns a new priority task that completes when all tasks are completed (successfully or not).abstract Executor.Task<java.lang.Void>
priorityFailed(java.lang.Throwable error)
Create a failed priority task.abstract <T> Executor.Task<T>
priorityResolved(T value)
Create an already resolved priority task.protected static <U> Executor.Task<U>
sync(Functions.Supplier<U> task, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.sync(aeonics.util.Functions.Supplier, java.util.concurrent.Executor)
-
Methods inherited from class aeonics.manager.Manager.Type
category, internal
-
Methods inherited from class aeonics.entity.Entity
addRelation, addRelation, addRelation, cast, clearRelation, config, defineRelation, equals, export, firstRelation, hashCode, hasRelation, id, name, name, onCreate, onRemove, onUpdate, parameter, relations, relationships, removeRelation, snapshot, type, valueOf, valueOf
-
-
-
-
Method Detail
-
manager
public final java.lang.Class<? extends Manager.Type> manager()
Hardcoded manager type- Specified by:
manager
in classManager.Type
- Returns:
- the type of manager
-
priority
public Executor.Task<java.lang.Void> priority(Functions.Runnable task)
Schedules the specified task to run in priority. There are no guarantees in terms of execution speed although it shall attempt to run before other tasks. This method may block or not depending on the implementation. It may reject a task or enqueue it depending on specific conditions.- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
priorityResolved
public abstract <T> Executor.Task<T> priorityResolved(T value)
Create an already resolved priority task.- Type Parameters:
T
- the task return type- Parameters:
value
- the resolved value- Returns:
- the task object to eventually chain operations
-
priorityFailed
public abstract Executor.Task<java.lang.Void> priorityFailed(java.lang.Throwable error)
Create a failed priority task.- Parameters:
error
- the cause of failure- Returns:
- the task object to eventually chain operations
-
priority
public abstract Executor.Task<java.lang.Void> priority(java.util.List<Executor.Task<?>> tasks)
Returns a new priority task that completes when all tasks are completed (successfully or not).- Parameters:
tasks
- the list of other tasks- Returns:
- the task object to eventually chain operations
- See Also:
Executor.Task.all(List, java.util.concurrent.Executor)
-
priority
public abstract <T> Executor.Task<T> priority(Functions.Supplier<T> task)
Schedules the specified task to run in priority. There are no guarantees in terms of execution speed although it shall attempt to run before other tasks. This method may block or not depending on the implementation. It may reject a task or enqueue it depending on specific conditions.- Type Parameters:
T
- the task return type- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
isPriority
public abstract boolean isPriority(java.lang.Thread thread)
Returns true if the specified thread is a priority thread managed by this executor.- Parameters:
thread
- the thread- Returns:
- true if the specified thread is a priority thread managed by this executor
-
isPriority
public boolean isPriority()
Returns true if the current thread is a priority thread managed by this executor.- Returns:
- true if the current thread is a priority thread managed by this executor
-
normal
public Executor.Task<java.lang.Void> normal(Functions.Runnable task)
Schedules the specified task to run. This method may block or not depending on the implementation. It may reject a task or enqueue it depending on specific conditions.- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
normalResolved
public abstract <T> Executor.Task<T> normalResolved(T value)
Create an already resolved normal task.- Type Parameters:
T
- the task return type- Parameters:
value
- the resolved value- Returns:
- the task object to eventually chain operations
-
normalFailed
public abstract Executor.Task<java.lang.Void> normalFailed(java.lang.Throwable error)
Create a failed normal task.- Parameters:
error
- the cause of failure- Returns:
- the task object to eventually chain operations
-
normal
public abstract Executor.Task<java.lang.Void> normal(java.util.List<Executor.Task<?>> tasks)
Returns a new normal task that completes when all tasks are completed (successfully or not).- Parameters:
tasks
- the list of other tasks- Returns:
- the task object to eventually chain operations
- See Also:
Executor.Task.all(List, java.util.concurrent.Executor)
-
normal
public abstract <T> Executor.Task<T> normal(Functions.Supplier<T> task)
Schedules the specified task to run. This method may block or not depending on the implementation. It may reject a task or enqueue it depending on specific conditions.- Type Parameters:
T
- the task return type- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
isNormal
public abstract boolean isNormal(java.lang.Thread thread)
Returns true if the specified thread is a normal thread managed by this executor.- Parameters:
thread
- the thread- Returns:
- true if the specified thread is a normal thread managed by this executor
-
isNormal
public boolean isNormal()
Returns true if the current thread is a normal thread managed by this executor.- Returns:
- true if the current thread is a normal thread managed by this executor
-
background
public Executor.Task<java.lang.Void> background(Functions.Runnable task)
Schedules the specified task to run in the background. This method is usually used for long-lasting tasks with a lower priority. This method should not block and should not enqueue tasks as all background tasks should run in parallel.- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
backgroundResolved
public abstract <T> Executor.Task<T> backgroundResolved(T value)
Create an already resolved background task.- Type Parameters:
T
- the task return type- Parameters:
value
- the resolved value- Returns:
- the task object to eventually chain operations
-
backgroundFailed
public abstract Executor.Task<java.lang.Void> backgroundFailed(java.lang.Throwable error)
Create a failed background task.- Parameters:
error
- the cause of failure- Returns:
- the task object to eventually chain operations
-
background
public abstract Executor.Task<java.lang.Void> background(java.util.List<Executor.Task<?>> tasks)
Returns a new background task that completes when all tasks are completed (successfully or not).- Parameters:
tasks
- the list of other tasks- Returns:
- the task object to eventually chain operations
- See Also:
Executor.Task.all(List, java.util.concurrent.Executor)
-
background
public abstract <T> Executor.Task<T> background(Functions.Supplier<T> task)
Schedules the specified task to run in the background. This method is usually used for long-lasting tasks with a lower priority. This method should not block and should not enqueue tasks as all background tasks should run in parallel.- Type Parameters:
T
- the task return type- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
isBackground
public abstract boolean isBackground(java.lang.Thread thread)
Returns true if the specified thread is a background thread managed by this executor.- Parameters:
thread
- the thread- Returns:
- true if the specified thread is a background thread managed by this executor
-
isBackground
public boolean isBackground()
Returns true if the current thread is a background thread managed by this executor.- Returns:
- true if the current thread is a background thread managed by this executor
-
io
public Executor.Task<java.lang.Void> io(Functions.Runnable task)
Schedules the specified I/O task to run. This method is usually used for slower I/O tasks that do not consume much CPU and spend most of their time waiting for the I/O. This method may block or not depending on the implementation. It may reject a task or enqueue it depending on specific conditions.- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
ioResolved
public abstract <T> Executor.Task<T> ioResolved(T value)
Create an already resolved io task.- Type Parameters:
T
- the task return type- Parameters:
value
- the resolved value- Returns:
- the task object to eventually chain operations
-
ioFailed
public abstract Executor.Task<java.lang.Void> ioFailed(java.lang.Throwable error)
Create a failed io task.- Parameters:
error
- the cause of failure- Returns:
- the task object to eventually chain operations
-
io
public abstract Executor.Task<java.lang.Void> io(java.util.List<Executor.Task<?>> tasks)
Returns a new io task that completes when all tasks are completed (successfully or not).- Parameters:
tasks
- the list of other tasks- Returns:
- the task object to eventually chain operations
- See Also:
Executor.Task.all(List, java.util.concurrent.Executor)
-
io
public abstract <T> Executor.Task<T> io(Functions.Supplier<T> task)
Schedules the specified I/O task to run. This method is usually used for slower I/O tasks that do not consume much CPU and spend most of their time waiting for the I/O. This method may block or not depending on the implementation. It may reject a task or enqueue it depending on specific conditions.- Type Parameters:
T
- the task return type- Parameters:
task
- the task to run- Returns:
- the task object to eventually chain or cancel operations
-
isIo
public abstract boolean isIo(java.lang.Thread thread)
Returns true if the specified thread is an io thread managed by this executor.- Parameters:
thread
- the thread- Returns:
- true if the specified thread is an io thread managed by this executor
-
isIo
public boolean isIo()
Returns true if the current thread is an io thread managed by this executor.- Returns:
- true if the current thread is an io thread managed by this executor
-
completed
protected static <T> Executor.Task<T> completed(T value, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.completed(Object, java.util.concurrent.Executor)
- Type Parameters:
T
- the return type- Parameters:
value
- the completion valueexecutor
- the executor in which subsequent tasks should run- Returns:
- an already completed task
-
failed
protected static Executor.Task<java.lang.Void> failed(java.lang.Throwable value, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.failed(Throwable, java.util.concurrent.Executor)
- Parameters:
value
- the failure causeexecutor
- the executor in which subsequent tasks should run- Returns:
- an already failed task
-
all
protected static Executor.Task<java.lang.Void> all(java.util.List<Executor.Task<?>> tasks, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.all(List, java.util.concurrent.Executor)
- Parameters:
tasks
- the list of tasks to group togetherexecutor
- the executor in which subsequent tasks should run- Returns:
- a new task that completes when all tasks are completed
-
sync
protected static <U> Executor.Task<U> sync(Functions.Supplier<U> task, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.sync(aeonics.util.Functions.Supplier, java.util.concurrent.Executor)
- Type Parameters:
U
- the return type of the task- Parameters:
task
- the task to runexecutor
- the executor in which the task should run- Returns:
- the task object to eventually chain or cancel operations
-
async
protected static <U> Executor.Task<U> async(Functions.Supplier<U> task, java.util.concurrent.Executor executor)
Protected accessor toExecutor.Task.async(aeonics.util.Functions.Supplier, java.util.concurrent.Executor)
- Type Parameters:
U
- the return type of the task- Parameters:
task
- the task to runexecutor
- the executor in which the task should run- Returns:
- the task object to eventually chain or cancel operations
-
-