public interface ExecContext extends ExecControl
An “execution” is a logical unit of work (e.g. handling a request, performing a background job).
As execution in Ratpack is asynchronous, the execution may actually span multiple threads.
This type provides control primitives (i.e. blocking(Callable)
, promise(Action)
) that facilitate a logical execution executing asynchronously.
Modifier and Type | Interface and Description |
---|---|
static interface |
ExecContext.Supplier
Supplies the current effective context of the execution at any given time.
|
Modifier and Type | Method and Description |
---|---|
<T> Promise<T> |
blocking(Callable<T> blockingOperation)
Performs a blocking operation on a separate thread, returning a promise for its value.
|
void |
error(Exception exception)
Terminate this execution with the given exception.
|
ExecContext |
getContext()
Returns
this . |
ExecController |
getExecController()
The execution controller.
|
HttpClient |
getHttpClient() |
List<ExecInterceptor> |
getInterceptors()
The execution interceptors.
|
LaunchConfig |
getLaunchConfig()
The application launch config.
|
ExecContext.Supplier |
getSupplier()
The supplier of the effective context for the current execution.
|
<T> Promise<T> |
promise(Action<? super Fulfiller<T>> action)
Creates a promise for an asynchronously created value.
|
ExecContext getContext()
this
.this
.ExecContext.Supplier getSupplier()
ExecContext.Supplier
@NonBlocking void error(Exception exception)
Generally, it is preferable to just throw an exception rather than using this method. Such an exception will be caught by the infrastructure, then forwarded to this method.
This method MUST NOT throw exceptions. Care should be taken to ensure that any exceptions are dealt with.
exception
- the exception that should terminate the executionExecController getExecController()
List<ExecInterceptor> getInterceptors()
LaunchConfig getLaunchConfig()
<T> Promise<T> blocking(Callable<T> blockingOperation)
blocking
in interface ExecControl
T
- the type of value created by the operationblockingOperation
- the operation to perform that performs blocking IO<T> Promise<T> promise(Action<? super Fulfiller<T>> action)
This method can be used to integrate with APIs that produce values asynchronously.
The asynchronous API should be invoked during the execute method of the action given to this method.
The result of the asynchronous call is then given to the Fulfiller
that the action is given.
promise
in interface ExecControl
T
- the type of valueaction
- an action that invokes an asynchronous API, forwarding the result to the given fulfiller.Fulfiller
,
Fulfillment
HttpClient getHttpClient()