io.quarkus.runtime.RuntimeValue Java Examples

The following examples show how to use io.quarkus.runtime.RuntimeValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringCloudConfigClientRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<ConfigSourceProvider> create(SpringCloudConfigClientConfig springCloudConfigClientConfig,
        ApplicationConfig applicationConfig) {
    if (!springCloudConfigClientConfig.enabled) {
        log.debug(
                "No attempt will be made to obtain configuration from the Spring Cloud Config Server because the functionality has been disabled via configuration");
        return emptyRuntimeValue();
    }

    if (!applicationConfig.name.isPresent()) {
        log.warn(
                "No attempt will be made to obtain configuration from the Spring Cloud Config Server because the application name has not been set. Consider setting it via 'quarkus.application.name'");
        return emptyRuntimeValue();
    }

    return new RuntimeValue<>(new SpringCloudConfigServerClientConfigSourceProvider(
            springCloudConfigClientConfig, applicationConfig.name.get(), ProfileManager.getActiveProfile()));
}
 
Example #2
Source File: LoggingJsonRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<Optional<Formatter>> initializeJsonLogging(final JsonConfig config) {
    if (!config.enable) {
        return new RuntimeValue<>(Optional.empty());
    }
    final JsonFormatter formatter = new JsonFormatter();
    formatter.setPrettyPrint(config.prettyPrint);
    final String dateFormat = config.dateFormat;
    if (!dateFormat.equals("default")) {
        formatter.setDateFormat(dateFormat);
    }
    formatter.setExceptionOutputType(config.exceptionOutputType);
    formatter.setPrintDetails(config.printDetails);
    config.recordDelimiter.ifPresent(formatter::setRecordDelimiter);
    final String zoneId = config.zoneId;
    if (!zoneId.equals("default")) {
        formatter.setZoneId(zoneId);
    }
    return new RuntimeValue<>(Optional.of(formatter));
}
 
Example #3
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<ServletInfo> registerServlet(RuntimeValue<DeploymentInfo> deploymentInfo,
        String name,
        Class<?> servletClass,
        boolean asyncSupported,
        int loadOnStartup,
        BeanContainer beanContainer,
        InstanceFactory<? extends Servlet> instanceFactory) throws Exception {

    InstanceFactory<? extends Servlet> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(servletClass));
    ServletInfo servletInfo = new ServletInfo(name, (Class<? extends Servlet>) servletClass,
            factory);
    deploymentInfo.getValue().addServlet(servletInfo);
    servletInfo.setAsyncSupported(asyncSupported);
    if (loadOnStartup > 0) {
        servletInfo.setLoadOnStartup(loadOnStartup);
    }
    return new RuntimeValue<>(servletInfo);
}
 
Example #4
Source File: PgPoolRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<PgPool> configurePgPool(RuntimeValue<Vertx> vertx,
        DataSourcesRuntimeConfig dataSourcesRuntimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactivePostgreSQLConfig dataSourceReactivePostgreSQLConfig,
        LegacyDataSourcesRuntimeConfig legacyDataSourcesRuntimeConfig,
        LegacyDataSourceReactivePostgreSQLConfig legacyDataSourceReactivePostgreSQLConfig,
        boolean isLegacy,
        ShutdownContext shutdown) {

    PgPool pgPool;
    if (!isLegacy) {
        pgPool = initialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
                dataSourceReactiveRuntimeConfig,
                dataSourceReactivePostgreSQLConfig);
    } else {
        pgPool = legacyInitialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
                legacyDataSourcesRuntimeConfig.defaultDataSource, legacyDataSourceReactivePostgreSQLConfig);
    }

    shutdown.addShutdownTask(pgPool::close);
    return new RuntimeValue<>(pgPool);
}
 
Example #5
Source File: ElytronDeploymentProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Create the deployment SecurityDomain using the SecurityRealm build items that have been created.
 *
 * @param recorder - the runtime recorder class used to access runtime behaviors
 * @param realms - the previously created SecurityRealm runtime values
 * @return the SecurityDomain runtime value build item
 * @throws Exception
 */
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
SecurityDomainBuildItem build(ElytronRecorder recorder, List<SecurityRealmBuildItem> realms)
        throws Exception {
    if (realms.size() > 0) {
        // Configure the SecurityDomain.Builder from the main realm
        SecurityRealmBuildItem realmBuildItem = realms.get(0);
        RuntimeValue<SecurityDomain.Builder> securityDomainBuilder = recorder
                .configureDomainBuilder(realmBuildItem.getName(), realmBuildItem.getRealm());
        // Add any additional SecurityRealms
        for (int n = 1; n < realms.size(); n++) {
            realmBuildItem = realms.get(n);
            RuntimeValue<SecurityRealm> realm = realmBuildItem.getRealm();
            recorder.addRealm(securityDomainBuilder, realmBuildItem.getName(), realm);
        }
        // Actually build the runtime value for the SecurityDomain
        RuntimeValue<SecurityDomain> securityDomain = recorder.buildDomain(securityDomainBuilder);

        // Return the build item for the SecurityDomain runtime value
        return new SecurityDomainBuildItem(securityDomain);
    }
    return null;
}
 
Example #6
Source File: LoggingSetupRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static Map<String, Handler> createNamedHandlers(LogConfig config,
        List<RuntimeValue<Optional<Formatter>>> possibleFormatters, ErrorManager errorManager,
        List<LogCleanupFilterElement> filterElements) {
    Map<String, Handler> namedHandlers = new HashMap<>();
    for (Entry<String, ConsoleConfig> consoleConfigEntry : config.consoleHandlers.entrySet()) {
        final Handler consoleHandler = configureConsoleHandler(consoleConfigEntry.getValue(), errorManager, filterElements,
                possibleFormatters, null);
        addToNamedHandlers(namedHandlers, consoleHandler, consoleConfigEntry.getKey());
    }
    for (Entry<String, FileConfig> fileConfigEntry : config.fileHandlers.entrySet()) {
        final Handler fileHandler = configureFileHandler(fileConfigEntry.getValue(), errorManager, filterElements);
        addToNamedHandlers(namedHandlers, fileHandler, fileConfigEntry.getKey());
    }
    for (Entry<String, SyslogConfig> sysLogConfigEntry : config.syslogHandlers.entrySet()) {
        final Handler syslogHandler = configureSyslogHandler(sysLogConfigEntry.getValue(), errorManager, filterElements);
        if (syslogHandler != null) {
            addToNamedHandlers(namedHandlers, syslogHandler, sysLogConfigEntry.getKey());
        }
    }
    return namedHandlers;
}
 
Example #7
Source File: LdapRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Create a runtime value for a {@linkplain LdapSecurityRealm}
 *
 * @param config - the realm config
 * @return - runtime value wrapper for the SecurityRealm
 */
public RuntimeValue<SecurityRealm> createRealm(LdapSecurityRealmConfig config) {
    LdapSecurityRealmBuilder builder = LdapSecurityRealmBuilder.builder()
            .setDirContextSupplier(createDirContextSupplier(config.dirContext))
            .identityMapping()
            .map(createAttributeMappings(config.identityMapping))
            .setRdnIdentifier(config.identityMapping.rdnIdentifier)
            .setSearchDn(config.identityMapping.searchBaseDn)
            .build();

    if (config.directVerification) {
        builder.addDirectEvidenceVerification(false);
    }

    return new RuntimeValue<>(builder.build());
}
 
Example #8
Source File: S3Recorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createAsyncBuilder(S3Config config,
        RuntimeValue<SdkAsyncHttpClient.Builder> transport) {

    S3AsyncClientBuilder builder = S3AsyncClient.builder();
    configureS3Client(builder, config);

    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #9
Source File: SnsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createSyncBuilder(SnsConfig config, RuntimeValue<Builder> transport) {
    SnsClientBuilder builder = SnsClient.builder();

    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #10
Source File: BraintreeRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Always disable the {@link org.apache.camel.component.braintree.internal.BraintreeLogHandler}.
 *
 * It's not desirable to configure this where an existing JUL - SLF4J bridge exists on the classpath.
 */
public RuntimeValue<BraintreeComponent> configureBraintreeComponent() {
    BraintreeComponent component = new BraintreeComponent();
    BraintreeConfiguration configuration = new BraintreeConfiguration();
    configuration.setLogHandlerEnabled(false);
    component.setConfiguration(configuration);
    return new RuntimeValue<>(component);
}
 
Example #11
Source File: CamelOpenTracingRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<OpenTracingTracer> createCamelOpenTracingTracer(CamelOpenTracingConfig camelOpenTracingConfig,
        BeanContainer beanContainer) {
    Tracer tracer = beanContainer.instance(Tracer.class);
    OpenTracingTracer openTracingTracer = new OpenTracingTracer();
    if (tracer != null) {
        openTracingTracer.setTracer(tracer);
        openTracingTracer.setEncoding(camelOpenTracingConfig.encoding);
        if (camelOpenTracingConfig.excludePatterns.isPresent()) {
            openTracingTracer.setExcludePatterns(new LinkedHashSet<>(camelOpenTracingConfig.excludePatterns.get()));
        }
    }
    return new RuntimeValue<>(openTracingTracer);
}
 
Example #12
Source File: CamelMainRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelRuntime> createRuntime(BeanContainer beanContainer, RuntimeValue<CamelMain> main) {
    final CamelRuntime runtime = new CamelMainRuntime(main.getValue());

    // register to the container
    beanContainer.instance(CamelProducers.class).setRuntime(runtime);

    return new RuntimeValue<>(runtime);
}
 
Example #13
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<FilterInfo> registerFilter(RuntimeValue<DeploymentInfo> info,
        String name, Class<?> filterClass,
        boolean asyncSupported,
        BeanContainer beanContainer,
        InstanceFactory<? extends Filter> instanceFactory) throws Exception {

    InstanceFactory<? extends Filter> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(filterClass));
    FilterInfo filterInfo = new FilterInfo(name, (Class<? extends Filter>) filterClass, factory);
    info.getValue().addFilter(filterInfo);
    filterInfo.setAsyncSupported(asyncSupported);
    return new RuntimeValue<>(filterInfo);
}
 
Example #14
Source File: CamelRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void bind(
        RuntimeValue<Registry> runtime,
        String name,
        Class<?> type) {

    try {
        runtime.getValue().bind(name, type, type.newInstance());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #15
Source File: CamelQuteRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<QuteComponent> createQuteComponent(BeanContainer beanContainer) {
    Engine quteEngine = beanContainer.instance(Engine.class);

    QuteComponent component = new QuteComponent();
    component.setQuteEngine(quteEngine);

    return new RuntimeValue<>(component);
}
 
Example #16
Source File: ConsulConfigRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<ConfigSourceProvider> configSources(ConsulConfig consulConfig) {
    if (!consulConfig.enabled) {
        log.debug(
                "No attempt will be made to obtain configuration from Consul because the functionality has been disabled via configuration");
        return emptyRuntimeValue();
    }

    return new RuntimeValue<>(
            new ConsulConfigSourceProvider(consulConfig));
}
 
Example #17
Source File: DynamodbRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<DynamoDbClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    DynamodbClientProducer producer = beanContainer.instance(DynamodbClientProducer.class);
    producer.setSyncConfiguredBuilder((DynamoDbClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #18
Source File: DB2PoolRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<DB2Pool> configureDB2Pool(RuntimeValue<Vertx> vertx,
        DataSourcesRuntimeConfig dataSourcesRuntimeConfig,
        DataSourceReactiveRuntimeConfig dataSourceReactiveRuntimeConfig,
        DataSourceReactiveDB2Config dataSourceReactiveDB2Config,
        ShutdownContext shutdown) {

    DB2Pool pool = initialize(vertx.getValue(), dataSourcesRuntimeConfig.defaultDataSource,
            dataSourceReactiveRuntimeConfig,
            dataSourceReactiveDB2Config);

    shutdown.addShutdownTask(pool::close);
    return new RuntimeValue<>(pool);
}
 
Example #19
Source File: AttachmentsRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<UploadAttacher> creatUploadAttacher() {
    return new RuntimeValue<>((File localFile, String fileName, Message message) -> {
        LOG.tracef("Attaching file %s to message %s", fileName, message);
        final AttachmentMessage am = message.getExchange().getMessage(AttachmentMessage.class);
        am.addAttachment(fileName, new DataHandler(new CamelFileDataSource(localFile, fileName)));
    });
}
 
Example #20
Source File: OAuth2DeploymentProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * Configure a TokenSecurityRealm if enabled
 *
 * @param recorder - runtime OAuth2 security recorder
 * @param securityRealm - the producer factory for the SecurityRealmBuildItem
 * @return the AuthConfigBuildItem for the realm authentication mechanism if there was an enabled PropertiesRealmConfig,
 *         null otherwise
 * @throws Exception - on any failure
 */
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
AdditionalBeanBuildItem configureOauth2RealmAuthConfig(OAuth2Recorder recorder,
        BuildProducer<SecurityRealmBuildItem> securityRealm) throws Exception {
    if (oauth2.enabled) {
        RuntimeValue<SecurityRealm> realm = recorder.createRealm(oauth2);
        securityRealm.produce(new SecurityRealmBuildItem(realm, REALM_NAME, null));
        return AdditionalBeanBuildItem.unremovableOf(OAuth2AuthMechanism.class);
    }
    return null;
}
 
Example #21
Source File: KmsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createAsyncBuilder(KmsConfig config,
        RuntimeValue<SdkAsyncHttpClient.Builder> transport) {

    KmsAsyncClientBuilder builder = KmsAsyncClient.builder();
    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #22
Source File: BytecodeRecorderTestCase.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewInstance() throws Exception {
    runTest(generator -> {
        RuntimeValue<TestJavaBean> instance = generator.newInstance(TestJavaBean.class.getName());
        TestRecorder recorder = generator.getRecordingProxy(TestRecorder.class);
        recorder.add(instance);
        recorder.add(instance);
        recorder.result(instance);
    }, new TestJavaBean(null, 2));
}
 
Example #23
Source File: SqsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SqsClient> buildClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SqsClientProducer producer = beanContainer.instance(SqsClientProducer.class);
    producer.setSyncConfiguredBuilder((SqsClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.client());
}
 
Example #24
Source File: SesRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createAsyncBuilder(SesConfig config,
        RuntimeValue<SdkAsyncHttpClient.Builder> transport) {

    SesAsyncClientBuilder builder = SesAsyncClient.builder();
    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #25
Source File: CamelContextRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void addRoutesFromContainer(RuntimeValue<CamelContext> context) {
    try {
        for (RoutesBuilder builder : context.getValue().getRegistry().findByType(RoutesBuilder.class)) {
            context.getValue().addRoutes(builder);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #26
Source File: CamelContextRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void addRoutes(RuntimeValue<CamelContext> context, Class<? extends RoutesBuilder> type) {
    try {
        context.getValue().addRoutes(
                context.getValue().getInjector().newInstance(type));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #27
Source File: S3Recorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createSyncBuilder(S3Config config, RuntimeValue<Builder> transport) {
    S3ClientBuilder builder = S3Client.builder();
    configureS3Client(builder, config);

    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #28
Source File: CamelRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public void bind(
        RuntimeValue<Registry> runtime,
        String name,
        Class<?> type,
        RuntimeValue<?> instance) {

    runtime.getValue().bind(name, type, instance.getValue());
}
 
Example #29
Source File: S3Recorder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<SyncHttpClientConfig> getSyncConfig(S3Config config) {
    return new RuntimeValue<>(config.syncClient);
}
 
Example #30
Source File: ResteasyInjectionReadyBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<InjectorFactory> getInjectorFactory() {
    return injectorFactory;
}