Interface FactoryOfTheFuture

All Superinterfaces:
Executor, SynchronousExecutor
All Known Implementing Classes:
AbstractFactoryOfTheFuture, IndifferentFactoryOfTheFuture

public interface FactoryOfTheFuture extends Executor, SynchronousExecutor
Concurrent executor and producer of CentralisedFuture. Intended to manage both asynchronous execution and synchronisation to the main thread.
Author:
A248
  • Method Details

    • execute

      void execute(Runnable command)
      Executes a Runnable asynchronously.
      Specified by:
      execute in interface Executor
      Parameters:
      command - the command
    • executeSync

      void executeSync(Runnable command)
      Runs the Runnable on the main thread, if the application has a main thread, else executes it in a thread pool suitable for computational work such as ForkJoinPool.commonPool()
      Specified by:
      executeSync in interface SynchronousExecutor
      Parameters:
      command - the runnable to run synchronously with the main thread
    • runAsync

      CentralisedFuture<?> runAsync(Runnable command)
      Runs a Runnable asynchronously and returns a future indicating its progress.
      Parameters:
      command - the runnable to run
      Returns:
      a centralised future representing the runnable's progress
      Throws:
      NullPointerException - if command is null
    • runAsync

      CentralisedFuture<?> runAsync(Runnable command, Executor executor)
      Runs a Runnable asynchronously using the provided Executor and returns a future indicating its progress.
      Parameters:
      command - the runnable to run
      executor - the executor on which to run the runnable
      Returns:
      a centralised future representing the runnable's progress
      Throws:
      NullPointerException - if command or executor is null
    • runSync

      CentralisedFuture<?> runSync(Runnable command)
      Runs a Runnable on the main thread if a main thread exists, else appropriately, per the specifications of SynchronousExecutor.executeSync(Runnable).
      Parameters:
      command - the runnable to run
      Returns:
      a centralised future representing the runnable's progress
      Throws:
      NullPointerException - if command is null
    • supplyAsync

      <T> CentralisedFuture<T> supplyAsync(Supplier<T> supplier)
      Supplies a value asynchronously and returns a future indicating its progress.
      Type Parameters:
      T - the return type of the supplier
      Parameters:
      supplier - the supplier to run
      Returns:
      a centralised future representing the supplier's progress
      Throws:
      NullPointerException - if supplier is null
    • supplyAsync

      <T> CentralisedFuture<T> supplyAsync(Supplier<T> supplier, Executor executor)
      Supplies a value asynchronously using the provided Executor and returns a future indicating its progress.
      Type Parameters:
      T - the return type of the supplier
      Parameters:
      supplier - the supplier to run
      executor - the executor on which to run the supplier
      Returns:
      a centralised future representing the supplier's progress
      Throws:
      NullPointerException - if supplier or executor is null
    • supplySync

      <T> CentralisedFuture<T> supplySync(Supplier<T> supplier)
      Supplies a value on the main thread if a main thread exists, else appropriately, per the specifications of SynchronousExecutor.executeSync(Runnable).
      Type Parameters:
      T - the return type of the supplier
      Parameters:
      supplier - the supplier to run
      Returns:
      a centralised future representing the supplier's progress
      Throws:
      NullPointerException - if supplier is null
    • completedFuture

      <T> CentralisedFuture<T> completedFuture(T value)
      Creates a precompleted future which has completed normally with the given value.
      Type Parameters:
      T - the result type of the future
      Parameters:
      value - the value with which to complete the future
      Returns:
      a future completed normally with the given value
    • completedStage

      <T> ReactionStage<T> completedStage(T value)
      Creates a precompleted stage which has completed normally with the given value.
      Type Parameters:
      T - the result type of the stage
      Parameters:
      value - the value with which to complete the stage
      Returns:
      a stage completed normally with the given value
    • failedFuture

      <T> CentralisedFuture<T> failedFuture(Throwable ex)
      Creates a precompleted future which has completed exceptionally with the given exception.
      Type Parameters:
      T - the result type of the future
      Parameters:
      ex - the exception with which to complete the future
      Returns:
      a future completeld exceptionally with the given exception
    • failedStage

      <T> ReactionStage<T> failedStage(Throwable ex)
      Creates a precompleted stage which has completed exceptionally with the given exception.
      Type Parameters:
      T - the result type of the stage
      Parameters:
      ex - the exception with which to complete the stage
      Returns:
      a stage completeld exceptionally with the given exception
    • newIncompleteFuture

      <T> CentralisedFuture<T> newIncompleteFuture()
      Creates an incomplete future.
      Type Parameters:
      T - the result type of the future
      Returns:
      an incomplete future
    • copyFuture

      <T> CentralisedFuture<T> copyFuture(CompletableFuture<T> completableFuture)
      Copies a CompletableFuture to a CentralisedFuture.
      When the completable future completes, if it does so normally, the centralised future is also completed normally with the same result. Else, if the former completes exceptionally, the latter is also completed exceptionally with the same exception.
      Type Parameters:
      T - the result type of the future
      Parameters:
      completableFuture - the completable future
      Returns:
      a centralised future completed in the same way as the original completable future
      Throws:
      NullPointerException - if completableFuture is null
    • copyStage

      <T> ReactionStage<T> copyStage(CompletionStage<T> completionStage)
      Copies a CompletionStage to a ReactionStage.
      When the completable future completes, if it does so normally, the reaction stage is also completed normally with the same result. Else, if the former completes exceptionally, the latter is also completed exceptionally with the same exception.
      Type Parameters:
      T - the result type of the stage
      Parameters:
      completionStage - the completion stage
      Returns:
      a reaction stage completed in the same way as the original completion stage
      Throws:
      NullPointerException - if completionStage is null
    • allOf

      CentralisedFuture<?> allOf(CentralisedFuture<?>... futures)
      Creates a future which completes when all of the specified futures complete. If all do so normally, the combined future completes normally, else exceptionally with the exception.

      If no futures are provided, returns an already completed future.

      Note that the completed value of the combined future, if it completes normally, is not meaningful.
      Parameters:
      futures - the futures to combine
      Returns:
      a future completed combining the specified futures
      Throws:
      NullPointerException - if futures or an element in it is null
    • allOf

      <T> CentralisedFuture<?> allOf(Collection<? extends CentralisedFuture<T>> futures)
      Creates a future which completes when all of the specified futures complete. If all do so normally, the combined future completes normally, else exceptionally with the exception.

      If no futures are provided, returns an already completed future.

      Note that the completed value of the combined future, if it completes normally, is not meaningful.
      Type Parameters:
      T - the type of object yielded by the futures
      Parameters:
      futures - the futures to combine
      Returns:
      a future completed combining the specified futures
      Throws:
      NullPointerException - if futures or an element in it is null