Class MCRProcessableSupplier<R>

Type Parameters:
R - the result of the task
All Implemented Interfaces:
Supplier<R>, MCRListenableProgressable, MCRProcessable, MCRProgressable

public class MCRProcessableSupplier<R> extends MCRProcessableTask<Callable<R>> implements Supplier<R>
A processable supplier combines a Supplier and a MCRProcessable. The supplier will be executed with the help of an CompletableFuture. To get the future call getFuture().
Author:
Matthias Eichner
  • Field Details

  • Method Details

    • of

      public static <T> MCRProcessableSupplier<T> of(Callable<T> task, CompletableFuture<T> future)
      Creates a new MCRProcessableSupplier by the already committed task and its future.
      Parameters:
      task - the task which should be executed
      future - the future
      Returns:
      a new processable supplier
    • of

      public static <T> MCRProcessableSupplier<T> of(Callable<T> task, ExecutorService executorService, Integer priority)
      Creates a new MCRProcessableSupplier by submitting the task to the executorService with the given priority.
      Parameters:
      task - the task to submit
      executorService - the executor service
      priority - the priority
      Returns:
      a new processable supplier
    • get

      public R get()
      Gets the result of the task. Will usually be called by the executor service and should not be executed directly.
      Specified by:
      get in interface Supplier<R>
    • getFuture

      public CompletableFuture<R> getFuture()
      The future the task is assigned to.
      Returns:
      the future
    • isFutureDone

      public boolean isFutureDone()
      Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.
      Returns:
      true if this task completed
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Parameters:
      mayInterruptIfRunning - true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete
      Returns:
      false if the task could not be cancelled, typically because it has already completed normally; true otherwise
    • getProgress

      public Integer getProgress()
      Returns an integer between 0-100 indicating the progress of the processable. Can return null if the task is not started yet or the task is not an instance of MCRProgressable.
      Specified by:
      getProgress in interface MCRProgressable
      Overrides:
      getProgress in class MCRAbstractProgressable
      Returns:
      the progress between 0-100 or null
    • getProgressText

      public String getProgressText()
      Returns a human readable text indicating the state of the progress.
      Specified by:
      getProgressText in interface MCRProgressable
      Overrides:
      getProgressText in class MCRAbstractProgressable
      Returns:
      progress text
    • getName

      public String getName()
      Returns the name of this process. If no name is set this returns the simplified class name of the task.
      Specified by:
      getName in interface MCRProcessable
      Overrides:
      getName in class MCRAbstractProcessable
      Returns:
      a human readable name of this processable task