Package ratpack.exec

Interface ExecController

  • All Superinterfaces:
    AutoCloseable

    public interface ExecController
    extends AutoCloseable
    The exec controller manages the execution of operations.

    The instance for an application can be obtained via the server registry.

    • Method Detail

      • current

        static Optional<ExecController> current()
        Returns the execution controller bound to the current thread, if this is a Ratpack managed compute thread.

        If called on a non Ratpack compute thread, the returned optional will be empty.

        Returns:
        the execution controller for the current thread
      • require

        static ExecController require()
                               throws UnmanagedThreadException
        Returns the execution controller bound to the current thread, or throws an exception if called on a non Ratpack managed compute thread.

        If called on a non Ratpack compute thread, the returned optional will be empty.

        Returns:
        the execution controller for the current thread
        Throws:
        UnmanagedThreadException - when called from a non Ratpack managed thread
      • fork

        ExecStarter fork()
        Create a new Execution from this controller that is bound to the computation threads.
        Returns:
        a builder for the execution
      • getExecutor

        ScheduledExecutorService getExecutor()
        The event loop (i.e. computation) executor.

        This executor wraps Netty's event loop executor to provide callback features by way of Guava's executor extensions.

        It is generally preferable to use fork() to submit computation work rather than this method, which properly initialises Ratpack's execution infrastructure.

        Returns:
        the executor that performs computation
      • getBlockingExecutor

        ExecutorService getBlockingExecutor()
        The blocking (i.e. I/O) executor service.

        This executor service provides a thread pool which can be used to schedule work such that it does not block the computation threads.

        The result of work executed on this thread should typically be returned to a continuation on a compute thread

        Returns:
        the default blocking executor service
        See Also:
        Blocking.get(ratpack.func.Factory<T>)
      • getEventLoopGroup

        io.netty.channel.EventLoopGroup getEventLoopGroup()
        The event loop group used by Netty for this application.

        Generally there is no need to access this unless you are doing something directly with Netty.

        Returns:
        the event loop group
      • close

        void close()
        Shuts down this controller, terminating the event loop and blocking threads.

        This method returns immediately, not waiting for the actual shutdown to occur.

        Generally, the only time it is necessary to call this method is when using an exec controller directly during testing.

        Specified by:
        close in interface AutoCloseable
      • of

        static ExecController of​(Action<? super ExecControllerSpec> definition)
                          throws Exception
        Construct a new execution controller from the provided specification.
        Parameters:
        definition - the configuration of the execution controller.
        Returns:
        an execution controller
        Throws:
        Exception - if any exception is thrown when applying the configuration.
        Since:
        2.0
      • onClose

        boolean onClose​(Block block)
        Registers a block to be executed when this controller closes.

        This method is additive.

        Parameters:
        block - the code block to execute on shutdown
        Returns:
        false if the controller is already closed and the block is not added, true otherwise.
        Since:
        2.0