Skip to content

Commit

Permalink
Look for mongo client in the whole deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Mar 10, 2021
1 parent eb98535 commit fbadd34
Showing 1 changed file with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.mongodb.event.ConnectionPoolListener;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
Expand All @@ -41,7 +42,6 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.annotations.Weak;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
Expand Down Expand Up @@ -116,10 +116,10 @@ List<ReflectiveClassBuildItem> addExtensionPointsToNative(CodecProviderBuildItem
}

@BuildStep
public void mongoClientNames(ApplicationArchivesBuildItem applicationArchivesBuildItem,
public void mongoClientNames(BeanArchiveIndexBuildItem indexBuildItem,
BuildProducer<MongoClientNameBuildItem> mongoClientName) {
Set<String> values = new HashSet<>();
IndexView indexView = applicationArchivesBuildItem.getRootArchive().getIndex();
IndexView indexView = indexBuildItem.getIndex();
addMongoClientNameValues(LEGACY_MONGO_CLIENT_ANNOTATION, indexView, values);
addMongoClientNameValues(MONGO_CLIENT_ANNOTATION, indexView, values);
for (String value : values) {
Expand Down Expand Up @@ -163,6 +163,16 @@ MongoConnectionPoolListenerBuildItem setupMetrics(
return null;
}

@BuildStep
void additionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
// add the @MongoClientName class otherwise it won't registered as a qualifier
additionalBeans.produce(
AdditionalBeanBuildItem.builder().addBeanClass(io.quarkus.mongodb.runtime.MongoClientName.class).build());
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(MongoClientName.class).build());
// make MongoClients an unremoveable bean
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClasses(MongoClients.class).setUnremovable().build());
}

@Record(STATIC_INIT)
@BuildStep
void build(
Expand All @@ -175,22 +185,13 @@ void build(
CommandListenerBuildItem commandListener,
List<MongoConnectionPoolListenerBuildItem> connectionPoolListenerProvider,
BuildProducer<MongoConnectionNameBuildItem> mongoConnections,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {

// add the @MongoClientName class otherwise it won't registered as a qualifier
additionalBeans.produce(
AdditionalBeanBuildItem.builder().addBeanClass(io.quarkus.mongodb.runtime.MongoClientName.class).build());
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(MongoClientName.class).build());
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer) {

List<Supplier<ConnectionPoolListener>> poolListenerList = new ArrayList<>(connectionPoolListenerProvider.size());
for (MongoConnectionPoolListenerBuildItem item : connectionPoolListenerProvider) {
poolListenerList.add(item.getConnectionPoolListener());
}

// make MongoClients an unremoveable bean
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClasses(MongoClients.class).setUnremovable().build());

// create MongoClientSupport as a synthetic bean as it's used in AbstractMongoClientProducer
syntheticBeanBuildItemBuildProducer.produce(SyntheticBeanBuildItem.configure(MongoClientSupport.class)
.scope(Singleton.class)
Expand Down

0 comments on commit fbadd34

Please sign in to comment.