Search in sources :

Example 6 with Action

use of ratpack.func.Action in project ratpack by ratpack.

the class DefaultContext method start.

public static void start(EventLoop eventLoop, final RequestConstants requestConstants, Registry registry, Handler[] handlers, Action<? super Execution> onComplete) {
    ChainIndex index = new ChainIndex(handlers, registry, true);
    requestConstants.indexes.push(index);
    DefaultContext context = new DefaultContext(requestConstants);
    requestConstants.context = context;
    context.pathBindings = new PathBindingStorage(new RootPathBinding(requestConstants.request.getPath()));
    requestConstants.applicationConstants.execController.fork().onError(throwable -> requestConstants.context.error(throwable instanceof HandlerException ? throwable.getCause() : throwable)).onComplete(onComplete).register(s -> s.add(Context.TYPE, context).add(Request.TYPE, requestConstants.request).add(Response.TYPE, requestConstants.response).add(PathBindingStorage.TYPE, context.pathBindings).addLazy(RequestId.TYPE, () -> registry.get(RequestId.Generator.TYPE).generate(requestConstants.request))).eventLoop(eventLoop).onStart(e -> DefaultRequest.setDelegateRegistry(requestConstants.request, e)).start(e -> {
        requestConstants.execution = e;
        context.joinedRegistry = new ContextRegistry(context).join(requestConstants.execution);
        context.next();
    });
}
Also used : RootPathBinding(ratpack.path.internal.RootPathBinding) ClientErrorHandler(ratpack.error.ClientErrorHandler) DirectChannelAccess(ratpack.handling.direct.DirectChannelAccess) java.util(java.util) Types(ratpack.util.Types) FileSystemBinding(ratpack.file.FileSystemBinding) RootPathBinding(ratpack.path.internal.RootPathBinding) Execution(ratpack.exec.Execution) ResponseTransmitter(ratpack.file.internal.ResponseTransmitter) Status(ratpack.http.Status) LoggerFactory(org.slf4j.LoggerFactory) Exceptions.uncheck(ratpack.util.Exceptions.uncheck) TypeToken(com.google.common.reflect.TypeToken) Parser(ratpack.parse.Parser) TypedData(ratpack.http.TypedData) NoSuchParserException(ratpack.parse.NoSuchParserException) TypeCaching(ratpack.registry.internal.TypeCaching) Request(ratpack.http.Request) Lists(com.google.common.collect.Lists) PathBindingStorage(ratpack.path.internal.PathBindingStorage) NoSuchRendererException(ratpack.render.NoSuchRendererException) ServerConfig(ratpack.server.ServerConfig) Registry(ratpack.registry.Registry) DefaultRequest(ratpack.http.internal.DefaultRequest) Parse(ratpack.parse.Parse) ratpack.handling(ratpack.handling) Path(java.nio.file.Path) HttpHeaderConstants(ratpack.http.internal.HttpHeaderConstants) Function(ratpack.func.Function) ServerErrorHandler(ratpack.error.ServerErrorHandler) RenderController(ratpack.render.internal.RenderController) Logger(org.slf4j.Logger) NotInRegistryException(ratpack.registry.NotInRegistryException) Promise(ratpack.exec.Promise) EventLoop(io.netty.channel.EventLoop) Block(ratpack.func.Block) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) InvalidPathEncodingException(ratpack.path.InvalidPathEncodingException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IF_MODIFIED_SINCE(io.netty.handler.codec.http.HttpHeaderNames.IF_MODIFIED_SINCE) Channel(io.netty.channel.Channel) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) Response(ratpack.http.Response) Action(ratpack.func.Action) Exceptions(ratpack.util.Exceptions) PathBinding(ratpack.path.PathBinding) ExecController(ratpack.exec.ExecController) PathBindingStorage(ratpack.path.internal.PathBindingStorage)

Example 7 with Action

use of ratpack.func.Action in project ratpack by ratpack.

the class ChainConfigurers method execute.

@Override
public void execute(Chain chain) throws Exception {
    List<Action<Chain>> delegates = new ArrayList<>(this.delegates);
    for (RatpackServerCustomizer customizer : customizers) {
        delegates.addAll(customizer.getHandlers());
    }
    if (handlers.size() == 1 || delegates.isEmpty()) {
        delegates.add(singleHandlerAction());
    }
    delegates.add(staticResourcesAction(chain.getServerConfig()));
    AnnotationAwareOrderComparator.sort(delegates);
    for (Action<Chain> delegate : delegates) {
        if (!(delegate instanceof ChainConfigurers)) {
            delegate.execute(chain);
        }
    }
}
Also used : Chain(ratpack.handling.Chain) Action(ratpack.func.Action) ArrayList(java.util.ArrayList) RatpackServerCustomizer(ratpack.spring.config.RatpackServerCustomizer)

Aggregations

Action (ratpack.func.Action)7 Function (ratpack.func.Function)5 Lists (com.google.common.collect.Lists)2 Instant (java.time.Instant)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ratpack.exec (ratpack.exec)2 ExecController (ratpack.exec.ExecController)2 ResultBackedExecResult (ratpack.exec.internal.ResultBackedExecResult)2 Handler (ratpack.handling.Handler)2 Registry (ratpack.registry.Registry)2 RegistrySpec (ratpack.registry.RegistrySpec)2 ServerConfig (ratpack.server.ServerConfig)2 ExecHarness (ratpack.test.exec.ExecHarness)2 Exceptions (ratpack.util.Exceptions)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 Maps (com.google.common.collect.Maps)1 TypeToken (com.google.common.reflect.TypeToken)1