Java Code Examples for io.quarkus.runtime.RuntimeValue#getValue()

The following examples show how to use io.quarkus.runtime.RuntimeValue#getValue() . 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: CamelMainRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelMain> createCamelMain(
        RuntimeValue<CamelContext> runtime,
        RuntimeValue<RoutesCollector> routesCollector,
        BeanContainer container) {
    CamelMain main = new CamelMain(runtime.getValue());
    main.setRoutesCollector(routesCollector.getValue());
    main.addMainListener(new CamelMainEventBridge());

    // autowire only non null values as components may have configured
    // through CDI or from a Build Item thus those values should not be
    // overridden
    main.configure().setAutowireComponentPropertiesNonNullOnly(true);

    // properties are loaded through MicroProfile Config so there's
    // no need to look for sources.
    main.setDefaultPropertyPlaceholderLocation("false");

    // xml rest/routes should be explicitly configured as an
    // additional dependency is required thus, disable auto
    // discovery
    main.configure().setXmlRoutes("false");
    main.configure().setXmlRests("false");

    // register to the container
    container.instance(CamelMainProducers.class).setMain(main);

    return new RuntimeValue<>(main);
}
 
Example 2
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 3
Source File: CamelContextRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelContext> createContext(
        RuntimeValue<Registry> registry,
        RuntimeValue<TypeConverterRegistry> typeConverterRegistry,
        RuntimeValue<ModelJAXBContextFactory> contextFactory,
        RuntimeValue<XMLRoutesDefinitionLoader> xmlLoader,
        RuntimeValue<ModelToXMLDumper> xmlModelDumper,
        RuntimeValue<FactoryFinderResolver> factoryFinderResolver,
        BeanContainer beanContainer,
        String version,
        CamelConfig config) {

    FastCamelContext context = new FastCamelContext(
            factoryFinderResolver.getValue(),
            version,
            xmlLoader.getValue(),
            xmlModelDumper.getValue());

    context.setDefaultExtension(RuntimeCamelCatalog.class, () -> new CamelRuntimeCatalog(config.runtimeCatalog));
    context.setRegistry(registry.getValue());
    context.setTypeConverterRegistry(typeConverterRegistry.getValue());
    context.setLoadTypeConverters(false);
    context.setModelJAXBContextFactory(contextFactory.getValue());
    context.build();
    context.addLifecycleStrategy(new CamelLifecycleEventBridge());
    context.getManagementStrategy().addEventNotifier(new CamelManagementEventBridge());

    // register to the container
    beanContainer.instance(CamelProducers.class).setContext(context);

    return new RuntimeValue<>(context);
}
 
Example 4
Source File: CamelContextRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<CamelRuntime> createRuntime(BeanContainer beanContainer, RuntimeValue<CamelContext> context) {
    final CamelRuntime runtime = new CamelContextRuntime(context.getValue());

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

    return new RuntimeValue<>(runtime);
}
 
Example 5
Source File: ArcRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public Supplier<Object> createSupplier(RuntimeValue<?> value) {
    return new Supplier<Object>() {
        @Override
        public Object get() {
            return value.getValue();
        }
    };
}
 
Example 6
Source File: RestClientRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void initializeResteasyProviderFactory(RuntimeValue<InjectorFactory> ifc, boolean useBuiltIn,
        Set<String> providersToRegister,
        Set<String> contributedProviders) {
    ResteasyProviderFactory clientProviderFactory = new ResteasyProviderFactoryImpl(RuntimeType.CLIENT,
            new ResteasyProviderFactoryImpl()) {
        @Override
        public RuntimeType getRuntimeType() {
            return RuntimeType.CLIENT;
        }

        @Override
        public InjectorFactory getInjectorFactory() {
            return ifc.getValue();
        }
    };

    if (useBuiltIn) {
        RegisterBuiltin.register(clientProviderFactory);
        registerProviders(clientProviderFactory, contributedProviders, false);
    } else {
        providersToRegister.removeAll(contributedProviders);
        registerProviders(clientProviderFactory, providersToRegister, true);
        registerProviders(clientProviderFactory, contributedProviders, false);
    }

    RestClientBuilderImpl.setProviderFactory(clientProviderFactory);
    providerFactory = clientProviderFactory;
}
 
Example 7
Source File: AmazonClientRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> configure(RuntimeValue<? extends AwsClientBuilder> clientBuilder,
        RuntimeValue<AwsConfig> awsConfig, RuntimeValue<SdkConfig> sdkConfig, SdkBuildTimeConfig sdkBuildTimeConfig,
        String awsServiceName) {
    AwsClientBuilder builder = clientBuilder.getValue();

    initAwsClient(builder, awsServiceName, awsConfig.getValue());
    initSdkClient(builder, awsServiceName, sdkConfig.getValue(), sdkBuildTimeConfig);

    return new RuntimeValue<>(builder);
}
 
Example 8
Source File: CamelMainRecorder.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<RoutesCollector> newRoutesCollector(
        RuntimeValue<RegistryRoutesLoader> registryRoutesLoader,
        RuntimeValue<XMLRoutesDefinitionLoader> xmlRoutesLoader) {

    return new RuntimeValue<>(new CamelMainRoutesCollector(registryRoutesLoader.getValue(), xmlRoutesLoader.getValue()));
}
 
Example 9
Source File: ReactiveStreamsRecorder.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<ReactiveStreamsComponent> createReactiveStreamsComponent(
        RuntimeValue<CamelReactiveStreamsServiceFactory> serviceFactory) {
    return new RuntimeValue<>(new QuarkusReactiveStreamsComponent(serviceFactory.getValue()));
}
 
Example 10
Source File: PlatformHttpRecorder.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<PlatformHttpEngine> createEngine(
        RuntimeValue<Router> router,
        List<Handler<RoutingContext>> handlers,
        RuntimeValue<UploadAttacher> uploadAttacher) {
    return new RuntimeValue<>(new QuarkusPlatformHttpEngine(router.getValue(), handlers, uploadAttacher.getValue()));
}
 
Example 11
Source File: AmazonClientTransportRecorder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public RuntimeValue<SdkAsyncHttpClient.Builder> configureAsync(String clientName,
        RuntimeValue<NettyHttpClientConfig> asyncConfigRuntime) {
    NettyNioAsyncHttpClient.Builder builder = NettyNioAsyncHttpClient.builder();
    NettyHttpClientConfig asyncConfig = asyncConfigRuntime.getValue();
    validateNettyClientConfig(clientName, asyncConfig);

    builder.connectionAcquisitionTimeout(asyncConfig.connectionAcquisitionTimeout);
    builder.connectionMaxIdleTime(asyncConfig.connectionMaxIdleTime);
    builder.connectionTimeout(asyncConfig.connectionTimeout);
    asyncConfig.connectionTimeToLive.ifPresent(builder::connectionTimeToLive);
    builder.maxConcurrency(asyncConfig.maxConcurrency);
    builder.maxPendingConnectionAcquires(asyncConfig.maxPendingConnectionAcquires);
    builder.protocol(asyncConfig.protocol);
    builder.readTimeout(asyncConfig.readTimeout);
    builder.writeTimeout(asyncConfig.writeTimeout);
    asyncConfig.sslProvider.ifPresent(builder::sslProvider);
    builder.useIdleConnectionReaper(asyncConfig.useIdleConnectionReaper);

    if (asyncConfig.http2.initialWindowSize.isPresent() || asyncConfig.http2.maxStreams.isPresent()) {
        Http2Configuration.Builder http2Builder = Http2Configuration.builder();
        asyncConfig.http2.initialWindowSize.ifPresent(http2Builder::initialWindowSize);
        asyncConfig.http2.maxStreams.ifPresent(http2Builder::maxStreams);
        asyncConfig.http2.healthCheckPingPeriod.ifPresent(http2Builder::healthCheckPingPeriod);
        builder.http2Configuration(http2Builder.build());
    }

    if (asyncConfig.proxy.enabled && asyncConfig.proxy.endpoint.isPresent()) {
        software.amazon.awssdk.http.nio.netty.ProxyConfiguration.Builder proxyBuilder = software.amazon.awssdk.http.nio.netty.ProxyConfiguration
                .builder().scheme(asyncConfig.proxy.endpoint.get().getScheme())
                .host(asyncConfig.proxy.endpoint.get().getHost())
                .nonProxyHosts(new HashSet<>(asyncConfig.proxy.nonProxyHosts.orElse(Collections.emptyList())));

        if (asyncConfig.proxy.endpoint.get().getPort() != -1) {
            proxyBuilder.port(asyncConfig.proxy.endpoint.get().getPort());
        }
        builder.proxyConfiguration(proxyBuilder.build());
    }

    getTlsKeyManagersProvider(asyncConfig.tlsManagersProvider).ifPresent(builder::tlsKeyManagersProvider);

    if (asyncConfig.eventLoop.override) {
        SdkEventLoopGroup.Builder eventLoopBuilder = SdkEventLoopGroup.builder();
        asyncConfig.eventLoop.numberOfThreads.ifPresent(eventLoopBuilder::numberOfThreads);
        if (asyncConfig.eventLoop.threadNamePrefix.isPresent()) {
            eventLoopBuilder.threadFactory(
                    new ThreadFactoryBuilder().threadNamePrefix(asyncConfig.eventLoop.threadNamePrefix.get()).build());
        }
        builder.eventLoopGroupBuilder(eventLoopBuilder);
    }

    return new RuntimeValue<>(builder);
}
 
Example 12
Source File: LoggingSetupRecorder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static Handler configureConsoleHandler(final ConsoleConfig config, final ErrorManager defaultErrorManager,
        final List<LogCleanupFilterElement> filterElements,
        final List<RuntimeValue<Optional<Formatter>>> possibleFormatters,
        final RuntimeValue<Optional<Supplier<String>>> possibleBannerSupplier) {
    Formatter formatter = null;
    boolean formatterWarning = false;

    for (RuntimeValue<Optional<Formatter>> value : possibleFormatters) {
        if (formatter != null) {
            formatterWarning = true;
        }
        final Optional<Formatter> val = value.getValue();
        if (val.isPresent()) {
            formatter = val.get();
        }
    }
    if (formatter == null) {
        Supplier<String> bannerSupplier = null;
        if (possibleBannerSupplier != null && possibleBannerSupplier.getValue().isPresent()) {
            bannerSupplier = possibleBannerSupplier.getValue().get();
        }
        if (config.color.orElse(hasColorSupport())) {
            ColorPatternFormatter colorPatternFormatter = new ColorPatternFormatter(config.darken,
                    config.format);
            if (bannerSupplier != null) {
                formatter = new BannerFormatter(colorPatternFormatter, true, bannerSupplier);
            } else {
                formatter = colorPatternFormatter;
            }
        } else {
            PatternFormatter patternFormatter = new PatternFormatter(config.format);
            if (bannerSupplier != null) {
                formatter = new BannerFormatter(patternFormatter, false, bannerSupplier);
            } else {
                formatter = patternFormatter;
            }
        }
    }
    final ConsoleHandler consoleHandler = new ConsoleHandler(formatter);
    consoleHandler.setLevel(config.level);
    consoleHandler.setErrorManager(defaultErrorManager);
    consoleHandler.setFilter(new LogCleanupFilter(filterElements));

    final Handler handler = config.async.enable ? createAsyncHandler(config.async, config.level, consoleHandler)
            : consoleHandler;

    if (formatterWarning) {
        handler.getErrorManager().error("Multiple formatters were activated", null, ErrorManager.GENERIC_FAILURE);
    }

    return handler;
}
 
Example 13
Source File: TestRecorder.java    From quarkus with Apache License 2.0 3 votes vote down vote up
/**
 * Invoke the RuntimeXmlConfigService#startService method and register a stopService call with the shutdown context.
 *
 * @param shutdownContext - context for adding shutdown hooks
 * @param runtimeValue - service value
 * @throws IOException - on startup failure
 */
public void startRuntimeService(ShutdownContext shutdownContext, RuntimeValue<RuntimeXmlConfigService> runtimeValue)
        throws IOException {
    RuntimeXmlConfigService service = runtimeValue.getValue();
    service.startService();
    shutdownContext.addShutdownTask(service::stopService);
}