Module aeonics.core

Class Executor

  • All Implemented Interfaces:
    Exportable, Snapshotable

    public abstract class Executor
    extends Manager.Type
    Manages the execution of tasks accross the system. There are three type of execution mode:
    • Normal: for regular tasks
    • Background: for long lasting background tasks, typically an Origin entity or another Manager
    • Priority: for thasks that should execute asap
    • Constructor Detail

      • Executor

        public Executor()
    • Method Detail

      • manager

        public final java.lang.Class<? extends Manager.Type> manager()
        Hardcoded manager type
        Specified by:
        manager in class Manager.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 <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 <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 <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 <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)
        Type Parameters:
        T - the return type
        Parameters:
        value - the completion value
        executor - the executor in which subsequent tasks should run
        Returns:
        an already completed task
      • all

        protected static Executor.Task<java.lang.Void> all​(java.util.List<Executor.Task<?>> tasks,
                                                           java.util.concurrent.Executor executor)
        Parameters:
        tasks - the list of tasks to group together
        executor - the executor in which subsequent tasks should run
        Returns:
        a new task that completes when all tasks are completed