Package ratpack.exec

Interface ExecStarter

    • Method Detail

      • start

        @NonBlocking
        void start​(Action<? super Execution> initialExecutionSegment)
        Starts the execution, with the given action as the initial segment.
        Parameters:
        initialExecutionSegment - the initial execution segment of the execution
      • start

        @NonBlocking
        default void start​(Operation operation)
        Starts the execution, and executes the given operation.
        Parameters:
        operation - the operation to execute
        Since:
        1.4
      • onError

        ExecStarter 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");
           }
         }
         
        Specified by:
        onError in interface ExecSpec
        Parameters:
        onError - the top level error handler for the execution
        Returns:
        this
      • onComplete

        ExecStarter 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.

        Specified by:
        onComplete in interface ExecSpec
        Parameters:
        onComplete - the action to invoke when the execution completes.
        Returns:
        this
      • onStart

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

        The action will be invoked after ExecSpec.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.

        Specified by:
        onStart in interface ExecSpec
        Parameters:
        onStart - the action to invoke just before the execution starts
        Returns:
        this
      • register

        ExecStarter 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.

        Specified by:
        register in interface ExecSpec
        Parameters:
        action - the initial contents of the execution's registry.
        Returns:
        this
      • eventLoop

        ExecStarter 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.

        Specified by:
        eventLoop in interface ExecSpec
        Parameters:
        eventLoop - the event loop to use for the execution
        Returns:
        this