Search in sources :

Example 1 with ShutdownListenerBuildItem

use of io.quarkus.deployment.builditem.ShutdownListenerBuildItem in project quarkus by quarkusio.

the class VertxHttpProcessor method finalizeRouter.

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
ServiceStartBuildItem finalizeRouter(VertxHttpRecorder recorder, BeanContainerBuildItem beanContainer, CoreVertxBuildItem vertx, LaunchModeBuildItem launchMode, List<DefaultRouteBuildItem> defaultRoutes, List<FilterBuildItem> filters, VertxWebRouterBuildItem httpRouteRouter, HttpRootPathBuildItem httpRootPathBuildItem, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, HttpBuildTimeConfig httpBuildTimeConfig, List<RequireBodyHandlerBuildItem> requireBodyHandlerBuildItems, BodyHandlerBuildItem bodyHandlerBuildItem, BuildProducer<ShutdownListenerBuildItem> shutdownListenerBuildItemBuildProducer, ShutdownConfig shutdownConfig, LiveReloadConfig lrc, // Injected to be sure that Vert.x has been produced before calling this method.
CoreVertxBuildItem core, ExecutorBuildItem executorBuildItem) throws BuildException, IOException {
    Optional<DefaultRouteBuildItem> defaultRoute;
    if (defaultRoutes == null || defaultRoutes.isEmpty()) {
        defaultRoute = Optional.empty();
    } else {
        if (defaultRoutes.size() > 1) {
            // this should never happen
            throw new BuildException("Too many default routes.", Collections.emptyList());
        } else {
            defaultRoute = Optional.of(defaultRoutes.get(0));
        }
    }
    HttpRemoteDevClientProvider.liveReloadConfig = lrc;
    GracefulShutdownFilter gracefulShutdownFilter = recorder.createGracefulShutdownHandler();
    shutdownListenerBuildItemBuildProducer.produce(new ShutdownListenerBuildItem(gracefulShutdownFilter));
    List<Filter> listOfFilters = filters.stream().filter(f -> f.getHandler() != null).map(FilterBuildItem::toFilter).collect(Collectors.toList());
    // if the body handler is required then we know it is installed for all routes, so we don't need to register it here
    Handler<RoutingContext> bodyHandler = !requireBodyHandlerBuildItems.isEmpty() ? bodyHandlerBuildItem.getHandler() : null;
    Optional<RuntimeValue<Router>> mainRouter = httpRouteRouter.getMainRouter() != null ? Optional.of(httpRouteRouter.getMainRouter()) : Optional.empty();
    if (httpRouteRouter.getFrameworkRouter() != null) {
        if (nonApplicationRootPathBuildItem.isAttachedToMainRouter()) {
            // Mount nested framework router
            recorder.mountFrameworkRouter(httpRouteRouter.getHttpRouter(), httpRouteRouter.getFrameworkRouter(), nonApplicationRootPathBuildItem.getVertxRouterPath());
        } else {
            // Create main router, not mounted under application router
            if (!mainRouter.isPresent()) {
                mainRouter = Optional.of(recorder.initializeRouter(vertx.getVertx()));
            }
            // Mount independent framework router under new main router
            recorder.mountFrameworkRouter(mainRouter.get(), httpRouteRouter.getFrameworkRouter(), nonApplicationRootPathBuildItem.getVertxRouterPath());
        }
    }
    recorder.finalizeRouter(beanContainer.getValue(), defaultRoute.map(DefaultRouteBuildItem::getRoute).orElse(null), listOfFilters, vertx.getVertx(), lrc, mainRouter, httpRouteRouter.getHttpRouter(), httpRouteRouter.getMutinyRouter(), httpRootPathBuildItem.getRootPath(), launchMode.getLaunchMode(), !requireBodyHandlerBuildItems.isEmpty(), bodyHandler, gracefulShutdownFilter, shutdownConfig, executorBuildItem.getExecutorProxy());
    return new ServiceStartBuildItem("vertx-http");
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) GracefulShutdownFilter(io.quarkus.vertx.http.runtime.filters.GracefulShutdownFilter) Filter(io.quarkus.vertx.http.runtime.filters.Filter) ShutdownListenerBuildItem(io.quarkus.deployment.builditem.ShutdownListenerBuildItem) GracefulShutdownFilter(io.quarkus.vertx.http.runtime.filters.GracefulShutdownFilter) RuntimeValue(io.quarkus.runtime.RuntimeValue) BuildException(io.quarkus.builder.BuildException) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Aggregations

BuildException (io.quarkus.builder.BuildException)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Record (io.quarkus.deployment.annotations.Record)1 ServiceStartBuildItem (io.quarkus.deployment.builditem.ServiceStartBuildItem)1 ShutdownListenerBuildItem (io.quarkus.deployment.builditem.ShutdownListenerBuildItem)1 RuntimeValue (io.quarkus.runtime.RuntimeValue)1 Filter (io.quarkus.vertx.http.runtime.filters.Filter)1 GracefulShutdownFilter (io.quarkus.vertx.http.runtime.filters.GracefulShutdownFilter)1 RoutingContext (io.vertx.ext.web.RoutingContext)1