Skip to content

Commit

Permalink
#20: allow configuration of multiple named connection factories
Browse files Browse the repository at this point in the history
  • Loading branch information
turing85 authored and middagj committed Oct 13, 2022
1 parent e211c5a commit 37dc312
Show file tree
Hide file tree
Showing 96 changed files with 2,192 additions and 868 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
"code",
"maintenance"
]
},
{
"login": "turing85",
"name": "Marco Bungart",
"avatar_url": "https://avatars.githubusercontent.com/u/32584495?v=4",
"profile": "https://github.com/turing85",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.artemis.core.deployment;

import java.util.Collections;
import java.util.Set;

import io.quarkus.builder.item.SimpleBuildItem;

public final class ArtemisBootstrappedBuildItem extends SimpleBuildItem {
private final Set<String> connectionNames;

public ArtemisBootstrappedBuildItem(Set<String> connectionNames) {
this.connectionNames = Collections.unmodifiableSet(connectionNames);
}

public Set<String> getConnectionNames() {
return connectionNames;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,113 +1,153 @@
package io.quarkus.artemis.core.deployment;

import java.util.Collection;
import java.util.Optional;
import java.util.*;
import java.util.function.Supplier;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Default;

import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.api.core.client.loadbalance.ConnectionLoadBalancingPolicy;
import org.apache.activemq.artemis.api.core.client.loadbalance.FirstElementConnectionLoadBalancingPolicy;
import org.apache.activemq.artemis.api.core.client.loadbalance.RandomConnectionLoadBalancingPolicy;
import org.apache.activemq.artemis.api.core.client.loadbalance.RandomStickyConnectionLoadBalancingPolicy;
import org.apache.activemq.artemis.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy;
import org.apache.activemq.artemis.api.core.client.loadbalance.*;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.apache.activemq.artemis.spi.core.remoting.ConnectorFactory;
import org.apache.activemq.artemis.utils.RandomUtil;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;

import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.artemis.core.runtime.ArtemisCoreRecorder;
import io.quarkus.artemis.core.runtime.*;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.smallrye.health.deployment.spi.HealthBuildItem;
import io.smallrye.common.annotation.Identifier;

public class ArtemisCoreProcessor {

private static final Logger LOGGER = Logger.getLogger(ArtemisCoreProcessor.class);
private static final String FEATURE = "artemis-core";

static final Class[] BUILTIN_CONNECTOR_FACTORIES = {
static final Class<?>[] BUILTIN_CONNECTOR_FACTORIES = {
NettyConnectorFactory.class
};

static final Class[] BUILTIN_LOADBALANCING_POLICIES = {
static final Class<?>[] BUILTIN_LOADBALANCING_POLICIES = {
FirstElementConnectionLoadBalancingPolicy.class,
RandomConnectionLoadBalancingPolicy.class,
RandomStickyConnectionLoadBalancingPolicy.class,
RoundRobinConnectionLoadBalancingPolicy.class
};

@SuppressWarnings("unused")
@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@SuppressWarnings("unused")
@BuildStep
NativeImageConfigBuildItem config() {
return NativeImageConfigBuildItem.builder()
.addRuntimeInitializedClass("org.apache.activemq.artemis.api.core.ActiveMQBuffers")
.addRuntimeInitializedClass("org.apache.activemq.artemis.utils.RandomUtil").build();
.addRuntimeInitializedClass(ActiveMQBuffers.class.getCanonicalName())
.addRuntimeInitializedClass(RandomUtil.class.getCanonicalName())
.build();
}

@SuppressWarnings("unused")
@BuildStep
void build(CombinedIndexBuildItem indexBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {

ArtemisBootstrappedBuildItem build(
CombinedIndexBuildItem indexBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
ShadowRunTimeConfig shadowRunTimeConfig,
ArtemisBuildTimeConfigs buildTimeConfigs) {
Collection<ClassInfo> connectorFactories = indexBuildItem.getIndex()
.getAllKnownImplementors(DotName.createSimple(ConnectorFactory.class.getName()));

for (ClassInfo ci : connectorFactories) {
LOGGER.debug("Adding reflective class " + ci);
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ci.toString()));
}

for (Class c : BUILTIN_CONNECTOR_FACTORIES) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, c));
}
addDynamicReflectiveBuildItems(reflectiveClass, connectorFactories);
addBuiltinReflectiveBuiltitems(reflectiveClass, BUILTIN_CONNECTOR_FACTORIES);

Collection<ClassInfo> loadBalancers = indexBuildItem.getIndex()
.getAllKnownImplementors(DotName.createSimple(ConnectionLoadBalancingPolicy.class.getName()));

for (ClassInfo ci : loadBalancers) {
LOGGER.debug("Adding reflective class " + ci);
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ci.toString()));
}

for (Class c : BUILTIN_LOADBALANCING_POLICIES) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, c));
addDynamicReflectiveBuildItems(reflectiveClass, loadBalancers);
addBuiltinReflectiveBuiltitems(reflectiveClass, BUILTIN_LOADBALANCING_POLICIES);
HashSet<String> names = new HashSet<>(shadowRunTimeConfig.getNames());
HashSet<String> disabled = new HashSet<>();
for (var entry : shadowRunTimeConfig.getAllConfigs().entrySet()) {
if (entry.getValue().isDisabled()) {
disabled.add(entry.getKey());
}
}
names.addAll(buildTimeConfigs.getAllConfigs().keySet());
names.removeAll(disabled);
return new ArtemisBootstrappedBuildItem(names);
}

@SuppressWarnings("unused")
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
HealthBuildItem health(ArtemisBuildTimeConfig buildConfig, Optional<ArtemisJmsBuildItem> artemisJms) {
ArtemisCoreConfiguredBuildItem configure(
ArtemisCoreRecorder recorder,
ArtemisRuntimeConfigs runtimeConfigs,
ArtemisBuildTimeConfigs buildTimeConfigs,
ArtemisBootstrappedBuildItem bootstrap,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanProducer,
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") Optional<ArtemisJmsBuildItem> artemisJms) {
if (artemisJms.isPresent()) {
return null;
}

return new HealthBuildItem(
"io.quarkus.artemis.core.runtime.health.ServerLocatorHealthCheck",
buildConfig.healthEnabled);
for (String name : bootstrap.getConnectionNames()) {
Supplier<ServerLocator> supplier = recorder.getServerLocatorSupplier(
name,
runtimeConfigs,
buildTimeConfigs);
SyntheticBeanBuildItem serverLocator = toSyntheticBeanBuildItem(name, supplier);
syntheticBeanProducer.produce(serverLocator);
}
return new ArtemisCoreConfiguredBuildItem();
}

@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
ArtemisCoreConfiguredBuildItem configure(ArtemisCoreRecorder recorder,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanProducer, Optional<ArtemisJmsBuildItem> artemisJms) {
private static void addDynamicReflectiveBuildItems(
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
Collection<ClassInfo> connectorFactories) {
for (ClassInfo ci : connectorFactories) {
LOGGER.debug("Adding reflective class " + ci);
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ci.toString()));
}
}

if (artemisJms.isPresent()) {
return null;
private static void addBuiltinReflectiveBuiltitems(
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
Class<?>[] builtinConnectorFactories) {
for (Class<?> c : builtinConnectorFactories) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, c));
}
}

SyntheticBeanBuildItem serverLocator = SyntheticBeanBuildItem.configure(ServerLocator.class)
.supplier(recorder.getServerLocatorSupplier())
.scope(ApplicationScoped.class)
.defaultBean()
.unremovable()
private SyntheticBeanBuildItem toSyntheticBeanBuildItem(
String name,
Supplier<ServerLocator> supplier) {
SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem
.configure(ServerLocator.class)
.supplier(supplier)
.scope(ApplicationScoped.class);
return addQualifiers(configurator, name)
.setRuntimeInit()
.done();
syntheticBeanProducer.produce(serverLocator);
}

return new ArtemisCoreConfiguredBuildItem();
public static SyntheticBeanBuildItem.ExtendedBeanConfigurator addQualifiers(
SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator,
String name) {
if (ArtemisUtil.isDefault(name)) {
configurator
.addQualifier().annotation(Default.class).done();
}
return configurator
.addQualifier().annotation(Identifier.class).addValue("value", name).done();
}
}
Loading

0 comments on commit 37dc312

Please sign in to comment.