Search in sources :

Example 1 with ServiceStartBuildItem

use of io.quarkus.deployment.builditem.ServiceStartBuildItem 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)

Example 2 with ServiceStartBuildItem

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

the class VertxProcessor method build.

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
VertxBuildItem build(CoreVertxBuildItem vertx, VertxRecorder recorder, List<EventConsumerBusinessMethodItem> messageConsumerBusinessMethods, BuildProducer<GeneratedClassBuildItem> generatedClass, AnnotationProxyBuildItem annotationProxy, LaunchModeBuildItem launchMode, ShutdownContextBuildItem shutdown, BuildProducer<ServiceStartBuildItem> serviceStart, BuildProducer<ReflectiveClassBuildItem> reflectiveClass, List<MessageCodecBuildItem> codecs, RecorderContext recorderContext) {
    Map<String, ConsumeEvent> messageConsumerConfigurations = new HashMap<>();
    ClassOutput classOutput = new GeneratedClassGizmoAdaptor(generatedClass, true);
    for (EventConsumerBusinessMethodItem businessMethod : messageConsumerBusinessMethods) {
        String invokerClass = EventBusConsumer.generateInvoker(businessMethod.getBean(), businessMethod.getMethod(), businessMethod.getConsumeEvent(), classOutput);
        messageConsumerConfigurations.put(invokerClass, annotationProxy.builder(businessMethod.getConsumeEvent(), ConsumeEvent.class).withDefaultValue("value", businessMethod.getBean().getBeanClass().toString()).build(classOutput));
        reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, invokerClass));
    }
    Map<Class<?>, Class<?>> codecByClass = new HashMap<>();
    for (MessageCodecBuildItem messageCodecItem : codecs) {
        codecByClass.put(recorderContext.classProxy(messageCodecItem.getType()), recorderContext.classProxy(messageCodecItem.getCodec()));
    }
    recorder.configureVertx(vertx.getVertx(), messageConsumerConfigurations, launchMode.getLaunchMode(), shutdown, codecByClass);
    serviceStart.produce(new ServiceStartBuildItem("vertx"));
    return new VertxBuildItem(recorder.forceStart(vertx.getVertx()));
}
Also used : ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) HashMap(java.util.HashMap) GeneratedClassGizmoAdaptor(io.quarkus.deployment.GeneratedClassGizmoAdaptor) CoreVertxBuildItem(io.quarkus.vertx.core.deployment.CoreVertxBuildItem) ClassOutput(io.quarkus.gizmo.ClassOutput) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) ConsumeEvent(io.quarkus.vertx.ConsumeEvent) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Example 3 with ServiceStartBuildItem

use of io.quarkus.deployment.builditem.ServiceStartBuildItem in project kogito-apps by kiegroup.

the class InmemoryPostgreSQLProcessor method startService.

@BuildStep
@Record(RUNTIME_INIT)
ServiceStartBuildItem startService(InmemoryPostgreSQLRecorder recorder, BuildProducer<RunTimeConfigurationSourceValueBuildItem> configSourceValueBuildItem) throws IOException {
    RuntimeValue<Integer> port = recorder.startPostgres();
    configSourceValueBuildItem.produce(new RunTimeConfigurationSourceValueBuildItem(recorder.configSources(port)));
    return new ServiceStartBuildItem(FEATURE);
}
Also used : ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) RunTimeConfigurationSourceValueBuildItem(io.quarkus.deployment.builditem.RunTimeConfigurationSourceValueBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Example 4 with ServiceStartBuildItem

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

the class FlywayProcessor method createBeansAndStartActions.

@BuildStep
@Consume(LoggingSetupBuildItem.class)
@Record(ExecutionTime.RUNTIME_INIT)
ServiceStartBuildItem createBeansAndStartActions(FlywayRecorder recorder, List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems, List<JdbcInitialSQLGeneratorBuildItem> sqlGeneratorBuildItems, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer, BuildProducer<JdbcDataSourceSchemaReadyBuildItem> schemaReadyBuildItem, MigrationStateBuildItem migrationsBuildItem) {
    // make a FlywayContainerProducer bean
    additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClasses(FlywayContainerProducer.class).setUnremovable().setDefaultScope(DotNames.SINGLETON).build());
    // add the @FlywayDataSource class otherwise it won't registered as a qualifier
    additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(FlywayDataSource.class).build());
    recorder.resetFlywayContainers();
    Collection<String> dataSourceNames = getDataSourceNames(jdbcDataSourceBuildItems);
    for (String dataSourceName : dataSourceNames) {
        boolean hasMigrations = migrationsBuildItem.hasMigrations.contains(dataSourceName);
        boolean createPossible = false;
        if (!hasMigrations) {
            createPossible = sqlGeneratorBuildItems.stream().anyMatch(s -> s.getDatabaseName().equals(dataSourceName));
        }
        SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem.configure(Flyway.class).scope(// this is what the existing code does, but it doesn't seem reasonable
        Dependent.class).setRuntimeInit().unremovable().supplier(recorder.flywaySupplier(dataSourceName, hasMigrations, createPossible));
        if (DataSourceUtil.isDefault(dataSourceName)) {
            configurator.addQualifier(Default.class);
        } else {
            String beanName = FLYWAY_BEAN_NAME_PREFIX + dataSourceName;
            configurator.name(beanName);
            configurator.addQualifier().annotation(DotNames.NAMED).addValue("value", beanName).done();
            configurator.addQualifier().annotation(FlywayDataSource.class).addValue("value", dataSourceName).done();
        }
        syntheticBeanBuildItemBuildProducer.produce(configurator.done());
    }
    // will actually run the actions at runtime
    recorder.doStartActions();
    // once we are done running the migrations, we produce a build item indicating that the
    // schema is "ready"
    schemaReadyBuildItem.produce(new JdbcDataSourceSchemaReadyBuildItem(migrationsBuildItem.hasMigrations));
    return new ServiceStartBuildItem("flyway");
}
Also used : DotNames(io.quarkus.arc.processor.DotNames) JavaMigration(org.flywaydb.core.api.migration.JavaMigration) ClassPathUtils(io.quarkus.runtime.util.ClassPathUtils) ClassInfo(org.jboss.jandex.ClassInfo) RecorderContext(io.quarkus.deployment.recording.RecorderContext) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) AbstractCollection(java.util.AbstractCollection) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) Map(java.util.Map) LoggingSetupBuildItem(io.quarkus.deployment.logging.LoggingSetupBuildItem) Path(java.nio.file.Path) JdbcInitialSQLGeneratorBuildItem(io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem) Consume(io.quarkus.deployment.annotations.Consume) STATIC_INIT(io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) Collectors(java.util.stream.Collectors) Location(org.flywaydb.core.api.Location) FlywayBuildTimeConfig(io.quarkus.flyway.runtime.FlywayBuildTimeConfig) Feature(io.quarkus.deployment.Feature) List(java.util.List) Stream(java.util.stream.Stream) Modifier(java.lang.reflect.Modifier) Callback(org.flywaydb.core.api.callback.Callback) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Record(io.quarkus.deployment.annotations.Record) Logger(org.jboss.logging.Logger) DotName(org.jboss.jandex.DotName) FlywayContainerProducer(io.quarkus.flyway.runtime.FlywayContainerProducer) RuntimeReinitializedClassBuildItem(io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem) HashMap(java.util.HashMap) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) HashSet(java.util.HashSet) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) DataSourceUtil(io.quarkus.datasource.common.runtime.DataSourceUtil) LinkedHashSet(java.util.LinkedHashSet) Default(javax.enterprise.inject.Default) Files(java.nio.file.Files) IOException(java.io.IOException) JdbcDataSourceSchemaReadyBuildItem(io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem) JdbcDataSourceBuildItem(io.quarkus.agroal.spi.JdbcDataSourceBuildItem) Paths(java.nio.file.Paths) Dependent(javax.enterprise.context.Dependent) FlywayRecorder(io.quarkus.flyway.runtime.FlywayRecorder) Flyway(org.flywaydb.core.Flyway) JdbcDataSourceSchemaReadyBuildItem(io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem) ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) Dependent(javax.enterprise.context.Dependent) Consume(io.quarkus.deployment.annotations.Consume) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Example 5 with ServiceStartBuildItem

use of io.quarkus.deployment.builditem.ServiceStartBuildItem in project camel-quarkus by apache.

the class CamelBootstrapProcessor method boot.

/**
 * Starts the given {@link CamelRuntimeBuildItem}.
 *
 * @param recorder             the recorder.
 * @param runtime              a reference to the {@link CamelRuntimeBuildItem}.
 * @param commandLineArguments a reference to the raw command line arguments as they were passed to the application.
 * @param shutdown             a reference to a {@link ShutdownContext} used tor register the Camel's related shutdown
 *                             tasks.
 */
@BuildStep
@Record(value = ExecutionTime.RUNTIME_INIT)
@Produce(CamelBootstrapCompletedBuildItem.class)
void boot(CamelBootstrapRecorder recorder, CamelRuntimeBuildItem runtime, RawCommandLineArgumentsBuildItem commandLineArguments, ShutdownContextBuildItem shutdown, BuildProducer<ServiceStartBuildItem> serviceStartBuildItems) {
    recorder.addShutdownTask(shutdown, runtime.runtime());
    if (runtime.isAutoStartup()) {
        recorder.start(runtime.runtime(), commandLineArguments);
    }
    /* Make sure that Quarkus orders this method before starting to serve HTTP endpoints.
         * Otherwise first requests might reach Camel context in a non-yet-started state. */
    serviceStartBuildItems.produce(new ServiceStartBuildItem("camel-runtime"));
}
Also used : ServiceStartBuildItem(io.quarkus.deployment.builditem.ServiceStartBuildItem) Produce(io.quarkus.deployment.annotations.Produce) BuildStep(io.quarkus.deployment.annotations.BuildStep) Record(io.quarkus.deployment.annotations.Record)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)6 Record (io.quarkus.deployment.annotations.Record)6 ServiceStartBuildItem (io.quarkus.deployment.builditem.ServiceStartBuildItem)6 JdbcDataSourceSchemaReadyBuildItem (io.quarkus.agroal.spi.JdbcDataSourceSchemaReadyBuildItem)2 Consume (io.quarkus.deployment.annotations.Consume)2 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)2 HashMap (java.util.HashMap)2 JdbcDataSourceBuildItem (io.quarkus.agroal.spi.JdbcDataSourceBuildItem)1 JdbcInitialSQLGeneratorBuildItem (io.quarkus.agroal.spi.JdbcInitialSQLGeneratorBuildItem)1 AdditionalBeanBuildItem (io.quarkus.arc.deployment.AdditionalBeanBuildItem)1 SyntheticBeanBuildItem (io.quarkus.arc.deployment.SyntheticBeanBuildItem)1 DotNames (io.quarkus.arc.processor.DotNames)1 BuildException (io.quarkus.builder.BuildException)1 SimpleBuildItem (io.quarkus.builder.item.SimpleBuildItem)1 DataSourceUtil (io.quarkus.datasource.common.runtime.DataSourceUtil)1 Feature (io.quarkus.deployment.Feature)1 GeneratedClassGizmoAdaptor (io.quarkus.deployment.GeneratedClassGizmoAdaptor)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 STATIC_INIT (io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT)1