Package ratpack.exec

Interface ExecSpec

    • Method Detail

      • onError

        ExecSpec onError​(Action<? super Throwable> onError)
        Specify the top level error handler for the execution.

        The given action will be invoked with any exceptions that are thrown and not handled.

        
         import ratpack.exec.Execution;
         import ratpack.exec.Promise;
         import ratpack.test.exec.ExecHarness;
        
         import static org.junit.jupiter.api.Assertions.assertEquals;
        
         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();
        
             assertEquals(value, "global error handler");
           }
         }
         
        Parameters:
        onError - the top level error handler for the execution
        Returns:
        this
      • onComplete

        ExecSpec onComplete​(Action<? super Execution> onComplete)
        Specifies the completion callback for the execution.

        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.

        Parameters:
        onComplete - the action to invoke when the execution completes.
        Returns:
        this
      • onStart

        ExecSpec onStart​(Action<? super Execution> onStart)
        Specifies an action to be taken just before the execution starts.

        The action will be invoked after register(Action) and any ExecInitializer's.

        The current execution during the given callback is the parent execution of the new execution being started. If the execution is being created from outside of an execution, there will be no current execution during the callback.

        This method is not additive. That is, any subsequent calls replace the previous value.

        Parameters:
        onStart - the action to invoke just before the execution starts
        Returns:
        this
      • register

        ExecSpec register​(Action<? super RegistrySpec> action)
        Populates the execution's registry.

        The current execution during the given callback is the parent execution of the new execution being started. If the execution is being created from outside of an execution, there will be no current execution during the callback.

        This method is not additive. That is, any subsequent calls replace the previous value.

        Parameters:
        action - the initial contents of the execution's registry.
        Returns:
        this
      • eventLoop

        ExecSpec eventLoop​(io.netty.channel.EventLoop eventLoop)
        Specifies that the execution must run on the given event loop.

        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.

        Parameters:
        eventLoop - the event loop to use for the execution
        Returns:
        this