Interface BlockingExecutor

All Superinterfaces:
AutoCloseable, Executor

public interface BlockingExecutor extends Executor, AutoCloseable
Allows safe invocation of tasks that require resources not otherwise available after close() to block a service from stopping.
Author:
Paul Ferraro
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    <R> Optional<R>
    execute(Callable<R> executeTask)
    Executes the specified task, but only if the service was not already closed.
    <R> Optional<R>
    execute(Supplier<R> executeTask)
    Executes the specified task, but only if the service was not already closed.
    newInstance(Runnable closeTask)
    Creates new blocking executor that runs the specified task upon close().

    Methods inherited from interface Executor

    execute
  • Method Details

    • execute

      <R> Optional<R> execute(Supplier<R> executeTask)
      Executes the specified task, but only if the service was not already closed. If service is already closed, the task is not run. If executed, the specified task must return a non-null value, to be distinguishable from a non-execution.
      Type Parameters:
      R - the return type of the specified task
      Parameters:
      executeTask - a task to execute
      Returns:
      an optional value that is present only if the specified task was run.
    • execute

      <R> Optional<R> execute(Callable<R> executeTask) throws Exception
      Executes the specified task, but only if the service was not already closed. If service is already closed, the task is not run. If executed, the specified task must return a non-null value, to be distinguishable from a non-execution.
      Type Parameters:
      R - the return type of the specified task
      Parameters:
      executeTask - a task to execute
      Returns:
      an optional value that is present only if the specified task was run.
      Throws:
      Exception - if the specified task fails to execute
    • close

      void close()
      Specified by:
      close in interface AutoCloseable
    • newInstance

      static BlockingExecutor newInstance(Runnable closeTask)
      Creates new blocking executor that runs the specified task upon close(). The specified task will only execute once, upon the first close() invocation.
      Parameters:
      closeTask - a task to run when this executor is closed.
      Returns:
      a new blocking executor