Interface ServiceExecutor

  • All Superinterfaces:
    Executor

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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close​(Runnable closeTask)
      Closes the service, executing the specified task, first waiting for any concurrent executions to complete.
      <R> Optional<R> execute​(Supplier<R> executeTask)
      Executes the specified task, but only if the service was not already closed.
      <E extends Exception>
      void
      execute​(org.wildfly.common.function.ExceptionRunnable<E> runner)
      Executes the specified runner.
      <R,​E extends Exception>
      Optional<R>
      execute​(org.wildfly.common.function.ExceptionSupplier<R,​E> executeTask)
      Executes the specified task, but only if the service was not already closed.
    • Method Detail

      • execute

        <E extends Exception> void execute​(org.wildfly.common.function.ExceptionRunnable<E> runner)
                                    throws E extends Exception
        Executes the specified runner.
        Type Parameters:
        E - the exception type
        Parameters:
        runner - a runnable task
        Throws:
        E - if execution fails
        E extends Exception
      • 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.
        Parameters:
        executeTask - a task to execute
        Returns:
        an optional value that is present only if the specified task was run.
      • execute

        <R,​E extends ExceptionOptional<R> execute​(org.wildfly.common.function.ExceptionSupplier<R,​E> executeTask)
                                                   throws E extends 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.
        Parameters:
        executeTask - a task to execute
        Returns:
        an optional value that is present only if the specified task was run.
        Throws:
        E - if the task execution failed
        E extends Exception
      • close

        void close​(Runnable closeTask)
        Closes the service, executing the specified task, first waiting for any concurrent executions to complete. The specified task will only execute once, irrespective on subsequent close(Runnable) invocations.
        Parameters:
        closeTask - a task which closes the service