Interface ExecController
-
- All Superinterfaces:
java.lang.AutoCloseable
public interface ExecController extends java.lang.AutoCloseableThe 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 voidaddInitializers(java.lang.Iterable<? extends ExecInitializer> initializers)Adds the given initializers to this controller.voidaddInterceptors(java.lang.Iterable<? extends ExecInterceptor> interceptors)Adds the given interceptors to this controller.static ExecControllerBuilderbuilder()Creates a new builder.voidclose()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.ExecStarterfork()java.util.concurrent.ExecutorServicegetBlockingExecutor()The executor for blocking work.io.netty.channel.EventLoopGroupgetEventLoopGroup()The event loop group used by Netty for this application.java.util.concurrent.ScheduledExecutorServicegetExecutor()The event loop (i.e.java.util.List<? extends ExecInitializer>getInitializers()The registered initializers for this controller.java.util.List<? extends ExecInterceptor>getInterceptors()The registered interceptors for this controller.intgetNumThreads()The number of threads that will be used for computation.booleanonClose(Block block)Adds a callback to run when stopping this exec controller.static ExecControllerrequire()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
-
builder
static ExecControllerBuilder builder()
Creates a new builder.- Returns:
- a new builder
-
fork
ExecStarter fork()
-
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()
The executor for blocking work.- Returns:
- the executor for blocking work.
-
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
-
onClose
boolean onClose(Block block)
Adds a callback to run when stopping this exec controller.- Parameters:
block- the callback to execute when stopping this controller- Returns:
- false if the controller is stopped or stopping and the block will not be executed, otherwise true
- Since:
- 1.10
-
getInterceptors
java.util.List<? extends ExecInterceptor> getInterceptors()
The registered interceptors for this controller.The returned list is immutable and will not contain any future additions.
- Returns:
- the registered interceptors for this controller
- Since:
- 1.10
-
getInitializers
java.util.List<? extends ExecInitializer> getInitializers()
The registered initializers for this controller.The returned list is immutable and will not contain any future additions.
- Returns:
- the registered initializers for this controller
- Since:
- 1.10
-
addInterceptors
void addInterceptors(java.lang.Iterable<? extends ExecInterceptor> interceptors)
Adds the given interceptors to this controller.- Parameters:
interceptors- the given interceptors to this controller- Since:
- 1.10
-
addInitializers
void addInitializers(java.lang.Iterable<? extends ExecInitializer> initializers)
Adds the given initializers to this controller.- Parameters:
initializers- the given interceptors to this controller- Since:
- 1.10
-
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:
closein interfacejava.lang.AutoCloseable
-
-