public interface ExecStarter
Execution
.Execution.fork()
Modifier and Type | Method and Description |
---|---|
ExecStarter |
eventLoop(EventLoop eventLoop)
Specifies that the execution must run on the given event loop.
|
ExecStarter |
onComplete(Action<? super Execution> onComplete)
Specifies the completion callback for the execution.
|
ExecStarter |
onError(Action<? super Throwable> onError)
Specify the top level error handler for the execution.
|
ExecStarter |
onStart(Action<? super Execution> onStart)
Specifies an action to be taken just before the execution starts.
|
ExecStarter |
register(Action<? super RegistrySpec> action)
Populates the execution's registry.
|
void |
start(Action<? super Execution> initialExecutionSegment)
Starts the execution, with the given action as the initial segment.
|
ExecStarter onError(Action<? super Throwable> onError)
The given action will be invoked with any exceptions that are thrown and not handled.
import org.junit.Assert;
import ratpack.exec.Execution;
import ratpack.exec.Promise;
import ratpack.test.exec.ExecHarness;
public class Example {
public static void main(String... args) throws Exception {
String value = ExecHarness.<String>yieldSingle(e -> Promise.async(d ->
Execution.fork()
.onError(t -> d.success("global error handler"))
.start(e1 ->
Promise.error(new RuntimeException("bang1"))
.then(v -> d.success("should not be called"))
)
)).getValue();
Assert.assertEquals("global error handler", value);
}
}
onError
- the top level error handler for the executionthis
ExecStarter onComplete(Action<? super Execution> onComplete)
The given action will effectively execute outside of the execution. The action is expected to be synchronous and cannot perform async operations. During its execution, there will be no thread bound execution or execution control. Any exceptions raised will be logged.
This method should be used as a last resort.
The action will be invoked regardless of whether the execution completed with an error or not. If the execution did complete with an error, the given action will be invoked after the error handler.
This method is not additive. That is, any subsequent calls replace the previous value.
onComplete
- the action to invoke when the execution completes.this
ExecStarter onStart(Action<? super Execution> onStart)
The action will be invoked after the execution registry has been populated.
This method is not additive. That is, any subsequent calls replace the previous value.
onStart
- the action to invoke just before the execution startsthis
ExecStarter register(Action<? super RegistrySpec> action)
This method is not additive. That is, any subsequent calls replace the previous value.
action
- the initial contents of the execution's registry.this
ExecStarter eventLoop(EventLoop eventLoop)
If this method is not called, an event loop will be automatically assigned from the exec controller's event loop group
.
It is generally not required, or desirable, to call this method.
eventLoop
- the event loop to use for the executionthis
@NonBlocking void start(Action<? super Execution> initialExecutionSegment)
initialExecutionSegment
- the initial execution segment of the execution