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");
}
Aggregations