Search in sources :

Example 1 with InternalRatpackError

use of ratpack.util.internal.InternalRatpackError in project ratpack by ratpack.

the class DefaultExecController method fork.

@Override
public ExecStarter fork() {
    return new ExecStarter() {

        private Action<? super Throwable> onError = LOG_UNCAUGHT;

        private Action<? super Execution> onComplete = noop();

        private Action<? super Execution> onStart = noop();

        private Action<? super RegistrySpec> registry = noop();

        private EventLoop eventLoop = getEventLoopGroup().next();

        @Override
        public ExecStarter eventLoop(EventLoop eventLoop) {
            this.eventLoop = eventLoop;
            return this;
        }

        @Override
        public ExecStarter onError(Action<? super Throwable> onError) {
            this.onError = onError;
            return this;
        }

        @Override
        public ExecStarter onComplete(Action<? super Execution> onComplete) {
            this.onComplete = onComplete;
            return this;
        }

        @Override
        public ExecStarter onStart(Action<? super Execution> onStart) {
            this.onStart = onStart;
            return this;
        }

        @Override
        public ExecStarter register(Action<? super RegistrySpec> action) {
            this.registry = action;
            return this;
        }

        @Override
        public void start(Action<? super Execution> initialExecutionSegment) {
            DefaultExecution current = DefaultExecution.get();
            DefaultExecution execution = createExecution(initialExecutionSegment, current == null ? null : current.getRef());
            if (eventLoop.inEventLoop() && current == null) {
                execution.drain();
            } else {
                eventLoop.submit(execution::drain);
            }
        }

        private DefaultExecution createExecution(Action<? super Execution> initialExecutionSegment, ExecutionRef parentRef) {
            try {
                return new DefaultExecution(DefaultExecController.this, parentRef, eventLoop, registry, initialExecutionSegment, onError, onStart, onComplete);
            } catch (Throwable e) {
                throw new InternalRatpackError("could not start execution", e);
            }
        }
    };
}
Also used : Action(ratpack.func.Action) EventLoop(io.netty.channel.EventLoop) InternalRatpackError(ratpack.util.internal.InternalRatpackError) RegistrySpec(ratpack.registry.RegistrySpec)

Aggregations

EventLoop (io.netty.channel.EventLoop)1 Action (ratpack.func.Action)1 RegistrySpec (ratpack.registry.RegistrySpec)1 InternalRatpackError (ratpack.util.internal.InternalRatpackError)1