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