Class SimplifiedEnhancedExecutor

java.lang.Object
space.arim.omnibus.util.concurrent.impl.SimplifiedEnhancedExecutor
All Implemented Interfaces:
Executor, EnhancedExecutor

public abstract class SimplifiedEnhancedExecutor extends Object implements EnhancedExecutor
Abstract implementation of EnhancedExecutor which handles its own scheduling and delegates execution to subclasses' execute(Runnable) methods.

Uses the system wide internal scheduler (CompletableFuture.delayedExecutor(long, TimeUnit, Executor)) to provide scheduling.
Author:
A248
  • Constructor Details

    • SimplifiedEnhancedExecutor

      protected SimplifiedEnhancedExecutor()
      Creates an instance
  • Method Details

    • execute

      public abstract void execute(Runnable command)
      Runs the specified command.

      It may run anywhere except the calling thread.
      Specified by:
      execute in interface EnhancedExecutor
      Specified by:
      execute in interface Executor
      Parameters:
      command - the command
    • submit

      public CompletableFuture<?> submit(Runnable command)
      Description copied from interface: EnhancedExecutor
      Execute an asynchronous action using this executor.

      The returned future provides the ability to listen for completion or block until complete.
      Specified by:
      submit in interface EnhancedExecutor
      Parameters:
      command - the Runnable to run
      Returns:
      a future completed when the command is run
    • supply

      public <T> CompletableFuture<T> supply(Supplier<T> supplier)
      Description copied from interface: EnhancedExecutor
      Supplies a value asynchronously using this executor.
      Specified by:
      supply in interface EnhancedExecutor
      Type Parameters:
      T - the type of the supplier
      Parameters:
      supplier - the supplier
      Returns:
      a future which yields the result of the supplier
    • scheduleOnce

      public ScheduledTask scheduleOnce(Runnable command, Duration delay)
      Description copied from interface: EnhancedExecutor
      Schedules a delayed task
      Specified by:
      scheduleOnce in interface EnhancedExecutor
      Parameters:
      command - the runnable to run
      delay - the duration after which to commence execution
      Returns:
      a scheduled task for the delayed work, which may be cancelled before execution begins
    • scheduleRepeating

      public ScheduledTask scheduleRepeating(Runnable command, Duration initialDelay, DelayCalculator delayCalculator)
      Description copied from interface: EnhancedExecutor
      Schedules a repeating task
      Specified by:
      scheduleRepeating in interface EnhancedExecutor
      Parameters:
      command - the runnable to run
      initialDelay - the initial delay before the first execution begins
      delayCalculator - the delay calculator to calculate repeated delays
      Returns:
      a scheduled task for the repeating work, which may be cancelled
    • scheduleRepeating

      public ScheduledTask scheduleRepeating(Consumer<? super ScheduledTask> command, Duration initialDelay, DelayCalculator delayCalculator)
      Description copied from interface: EnhancedExecutor
      Schedules a repeating task
      Specified by:
      scheduleRepeating in interface EnhancedExecutor
      Parameters:
      command - the consumer to run
      initialDelay - the initial delay before the first execution begins
      delayCalculator - the delay calculator to calculate repeated delays
      Returns:
      a scheduled task representing the repeating work, which may be cancelled