Package ratpack.exec

Interface ExecController

  • All Superinterfaces:
    java.lang.AutoCloseable

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

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

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Shuts down this controller, terminating the event loop and blocking threads.
      static java.util.Optional<ExecController> current()
      Returns the execution controller bound to the current thread, if this is a Ratpack managed compute thread.
      ExecStarter fork()  
      java.util.concurrent.ExecutorService getBlockingExecutor()  
      io.netty.channel.EventLoopGroup getEventLoopGroup()
      The event loop group used by Netty for this application.
      java.util.concurrent.ScheduledExecutorService getExecutor()
      The event loop (i.e.
      int getNumThreads()
      The number of threads that will be used for computation.
      static ExecController require()
      Returns the execution controller bound to the current thread, or throws an exception if called on a non Ratpack managed compute thread.
    • Method Detail

      • current

        static java.util.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
      • getExecutor

        java.util.concurrent.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

        java.util.concurrent.ExecutorService getBlockingExecutor()
      • 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
      • getNumThreads

        int getNumThreads()
        The number of threads that will be used for computation.

        This is determined by the ServerConfig.getThreads() value of the launch config that created this controller.

        Returns:
        the number of threads that will be used for computation
      • 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. Calling RatpackServer.stop() will inherently call this method.

        Specified by:
        close in interface java.lang.AutoCloseable