public interface ExecController extends AutoCloseable
The instance for an application can be obtained via the launch config's LaunchConfig.getExecController()
method.
Modifier and Type | Method and Description |
---|---|
void |
close()
Shuts down this controller, terminating the event loop and blocking threads.
|
ExecControl |
getControl()
A singleton that can be used from any managed thread to perform asynchronous or blocking operations.
|
EventLoopGroup |
getEventLoopGroup()
The event loop group used by Netty for this application.
|
Execution |
getExecution()
Provides the current execution that is bound to the current thread.
|
ListeningScheduledExecutorService |
getExecutor()
The event loop (i.e.
|
int |
getNumThreads()
The number of threads that will be used for computation.
|
boolean |
isManagedThread()
Indicates whether the current thread is managed by this execution controller.
|
void |
start(Action<? super Execution> action)
Initiates a new execution with the given action.
|
@NonBlocking void start(Action<? super Execution> action)
The action is guaranteed to be executed on a Ratpack event loop thread. Therefore, it may not be executed in the calling thread.
If the action raises an uncaught exception, it will be forwarded to the execution object's error handler
.
The default implementation just logs the error so it is usually a good idea to call the Execution.setErrorHandler(ratpack.func.Action)
method
with an error handler immediately in the action implementation.
See Execution
for more information about what an execution is in Ratpack.
action
- the initial execution segment of the new execution.Execution getExecution() throws ExecutionException
If the current thread has no bound execution, this method will throw an ExecutionException
.
The most likely scenario for this to occur is when the current thread is not managed by Ratpack,
which is indicated by the isManagedThread()
method.
There's generally no need to call this method in normal application programming. It is provided to aid integrating execution related tools (e.g. RxJava).
ExecutionException
- if this method is called from a thread that is not performing request processingboolean isManagedThread()
This will return true
if the current thread is either part of the event loop thread pool or blocking thread pool of the
application that is backed by this execution controller.
ExecControl getControl()
The control is typically used by services that are not inherently tied to any specific execution to perform execution operations such as blocking and forking.
If you are using the Guice integration, an instance of this type can be injected.
ListeningScheduledExecutorService getExecutor()
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 start(ratpack.func.Action)
to submit computation work rather than this method,
which properly initialises Ratpack's execution infrastructure.
EventLoopGroup getEventLoopGroup()
Generally there is no need to access this unless you are doing something directly with Netty.
int getNumThreads()
This is determined by the LaunchConfig.getThreads()
value of the launch config that created this controller.
void close()
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.
close
in interface AutoCloseable