Search in sources :

Example 1 with MpConfig

use of io.helidon.config.mp.MpConfig in project helidon by oracle.

the class JmsConnector method getSubscriberBuilder.

@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config mpConfig) {
    io.helidon.config.Config config = MpConfig.toHelidonConfig(mpConfig);
    ConnectionContext ctx = new ConnectionContext(config);
    ConnectionFactory factory = getFactory(ctx).orElseThrow(() -> new MessagingException("No ConnectionFactory found."));
    try {
        SessionMetadata sessionEntry = prepareSession(config, factory);
        Session session = sessionEntry.session();
        Destination destination = createDestination(session, ctx);
        MessageProducer producer = session.createProducer(destination);
        AtomicReference<MessageMappers.MessageMapper> mapper = new AtomicReference<>();
        return ReactiveStreams.<Message<?>>builder().flatMapCompletionStage(m -> consume(m, session, mapper, producer, config)).onError(t -> LOGGER.log(Level.SEVERE, t, () -> "Error intercepted from channel " + config.get(CHANNEL_NAME_ATTRIBUTE).asString().orElse("unknown"))).ignore();
    } catch (JMSException e) {
        throw new MessagingException("Error when creating JMS producer.", e);
    }
}
Also used : BufferedEmittingPublisher(io.helidon.common.reactive.BufferedEmittingPublisher) OutgoingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.OutgoingConnectorFactory) Observes(jakarta.enterprise.event.Observes) BytesMessage(jakarta.jms.BytesMessage) MpConfig(io.helidon.config.mp.MpConfig) MessageProducer(jakarta.jms.MessageProducer) Builder(io.helidon.common.Builder) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) JMSException(jakarta.jms.JMSException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Instance(jakarta.enterprise.inject.Instance) Session(jakarta.jms.Session) Level(java.util.logging.Level) FlowAdapters(org.reactivestreams.FlowAdapters) MessageConsumer(jakarta.jms.MessageConsumer) Map(java.util.Map) Destination(jakarta.jms.Destination) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) Connector(org.eclipse.microprofile.reactive.messaging.spi.Connector) ConnectionFactory(jakarta.jms.ConnectionFactory) Connection(jakarta.jms.Connection) IncomingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory) MessagingException(io.helidon.messaging.MessagingException) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) ExecutorService(java.util.concurrent.ExecutorService) Multi(io.helidon.common.reactive.Multi) Executor(java.util.concurrent.Executor) ScheduledThreadPoolSupplier(io.helidon.common.configurable.ScheduledThreadPoolSupplier) NamedLiteral(jakarta.enterprise.inject.literal.NamedLiteral) SubscriberBuilder(org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder) UUID(java.util.UUID) ConfigValue(io.helidon.config.ConfigValue) Stoppable(io.helidon.messaging.Stoppable) Config(org.eclipse.microprofile.config.Config) Logger(java.util.logging.Logger) BeforeDestroyed(jakarta.enterprise.context.BeforeDestroyed) TimeUnit(java.util.concurrent.TimeUnit) Message(org.eclipse.microprofile.reactive.messaging.Message) CompletionStage(java.util.concurrent.CompletionStage) Topic(jakarta.jms.Topic) TextMessage(jakarta.jms.TextMessage) Optional(java.util.Optional) Inject(jakarta.inject.Inject) ThreadPoolSupplier(io.helidon.common.configurable.ThreadPoolSupplier) PublisherBuilder(org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder) Destination(jakarta.jms.Destination) MessagingException(io.helidon.messaging.MessagingException) AtomicReference(java.util.concurrent.atomic.AtomicReference) JMSException(jakarta.jms.JMSException) ConnectionFactory(jakarta.jms.ConnectionFactory) MessageProducer(jakarta.jms.MessageProducer) Session(jakarta.jms.Session)

Example 2 with MpConfig

use of io.helidon.config.mp.MpConfig in project helidon by oracle.

the class HelidonContainerImpl method init.

@SuppressWarnings("unchecked")
private HelidonContainerImpl init() {
    LOGGER.fine(() -> "Initializing CDI container " + id);
    addHelidonBeanDefiningAnnotations("jakarta.ws.rs.Path", "jakarta.ws.rs.ext.Provider", "jakarta.websocket.server.ServerEndpoint", "org.eclipse.microprofile.graphql.GraphQLApi", "org.eclipse.microprofile.graphql.Input", "org.eclipse.microprofile.graphql.Interface", "org.eclipse.microprofile.graphql.Type");
    ResourceLoader resourceLoader = new WeldResourceLoader() {

        @Override
        public Collection<URL> getResources(String name) {
            Collection<URL> resources = super.getResources(name);
            // drops duplicates when using patch-module
            return new HashSet<>(resources);
        }
    };
    setResourceLoader(resourceLoader);
    Config mpConfig = ConfigProvider.getConfig();
    io.helidon.config.Config config = MpConfig.toHelidonConfig(mpConfig);
    Map<String, String> properties = config.get("cdi").detach().asMap().orElseGet(Map::of);
    setProperties(new HashMap<>(properties));
    ServiceLoader.load(Extension.class).findFirst().ifPresent(it -> {
        // adding an empty extension to start even with just extensions on classpath
        // Weld would fail (as it sets the extensions after checking if they are empty)
        addExtension(new Extension() {
        });
    });
    Deployment deployment = createDeployment(resourceLoader, bootstrap);
    // we need to configure custom proxy services to
    // load classes in module friendly way
    deployment.getServices().add(ProxyServices.class, new HelidonProxyServices());
    ExternalConfigurationBuilder configurationBuilder = new ExternalConfigurationBuilder().add(EXECUTOR_THREAD_POOL_TYPE.get(), COMMON.toString()).add(ConfigurationKey.RELAXED_CONSTRUCTION.get(), true).add(ConfigurationKey.ALLOW_OPTIMIZED_CLEANUP.get(), isEnabled(ALLOW_OPTIMIZED_CLEANUP, true));
    for (Map.Entry<String, String> property : properties.entrySet()) {
        String key = property.getKey();
        if (SHUTDOWN_HOOK_SYSTEM_PROPERTY.equals(key) || ARCHIVE_ISOLATION_SYSTEM_PROPERTY.equals(key) || DEV_MODE_SYSTEM_PROPERTY.equals(key) || SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTY.equals(key) || JAVAX_ENTERPRISE_INJECT_SCAN_IMPLICIT.equals(key)) {
            continue;
        }
        configurationBuilder.add(key, property.getValue());
    }
    deployment.getServices().add(ExternalConfiguration.class, configurationBuilder.build());
    bootstrap.startContainer(id, Environments.SE, deployment);
    bootstrap.startInitialization();
    Collection<BeanDeploymentArchive> archives = deployment.getBeanDeploymentArchives();
    if (archives.isEmpty()) {
        throw new IllegalStateException("No deployment archive");
    }
    BeanManagerImpl beanManager = bootstrap.getManager(archives.iterator().next());
    beanManager.getEvent().select(BuildTimeStart.Literal.INSTANCE).fire(id);
    bootstrap.deployBeans();
    cdi = new HelidonCdi(id, bootstrap, deployment);
    HelidonCdiProvider.setCdi(cdi);
    beanManager.getEvent().select(BuildTimeEnd.Literal.INSTANCE).fire(id);
    return this;
}
Also used : WeldResourceLoader(org.jboss.weld.environment.deployment.WeldResourceLoader) ResourceLoader(org.jboss.weld.resources.spi.ResourceLoader) MpConfig(io.helidon.config.mp.MpConfig) SerializationConfig(io.helidon.common.SerializationConfig) Config(org.eclipse.microprofile.config.Config) LogConfig(io.helidon.common.LogConfig) ExternalConfigurationBuilder(org.jboss.weld.configuration.spi.helpers.ExternalConfigurationBuilder) Deployment(org.jboss.weld.bootstrap.spi.Deployment) WeldDeployment(org.jboss.weld.environment.deployment.WeldDeployment) URL(java.net.URL) Extension(jakarta.enterprise.inject.spi.Extension) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) Map(java.util.Map) HashMap(java.util.HashMap) WeldResourceLoader(org.jboss.weld.environment.deployment.WeldResourceLoader) HashSet(java.util.HashSet)

Aggregations

MpConfig (io.helidon.config.mp.MpConfig)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Config (org.eclipse.microprofile.config.Config)2 Builder (io.helidon.common.Builder)1 LogConfig (io.helidon.common.LogConfig)1 SerializationConfig (io.helidon.common.SerializationConfig)1 ScheduledThreadPoolSupplier (io.helidon.common.configurable.ScheduledThreadPoolSupplier)1 ThreadPoolSupplier (io.helidon.common.configurable.ThreadPoolSupplier)1 BufferedEmittingPublisher (io.helidon.common.reactive.BufferedEmittingPublisher)1 Multi (io.helidon.common.reactive.Multi)1 ConfigValue (io.helidon.config.ConfigValue)1 MessagingException (io.helidon.messaging.MessagingException)1 Stoppable (io.helidon.messaging.Stoppable)1 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 BeforeDestroyed (jakarta.enterprise.context.BeforeDestroyed)1 Observes (jakarta.enterprise.event.Observes)1 Instance (jakarta.enterprise.inject.Instance)1 NamedLiteral (jakarta.enterprise.inject.literal.NamedLiteral)1 Extension (jakarta.enterprise.inject.spi.Extension)1