Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Identifier qualifier from smallrye-common instead of Named #23

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<module name="org.jboss.as.weld.common"/>
<module name="org.jboss.jandex"/>
<module name="io.vertx.core" />
<module name="io.smallrye.common.annotation" />
<module name="io.smallrye.reactive.mutiny.vertx-core" />
</dependencies>
</module>
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<version.org.wildfly.common>1.6.0.Final</version.org.wildfly.common>
<version.io.vertx.vertx>4.5.9</version.io.vertx.vertx>
<version.io.smallrye.smallrye-mutiny-vertx>3.13.0</version.io.smallrye.smallrye-mutiny-vertx>
<version.io.smallrye.smallrye-common>2.5.0</version.io.smallrye.smallrye-common>

<module.name>org.wildfly.extension.vertx</module.name>

Expand Down Expand Up @@ -103,6 +104,11 @@
<artifactId>vertx-core</artifactId>
<version>${version.io.vertx.vertx}</version>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-annotation</artifactId>
<version>${version.io.smallrye.smallrye-common}</version>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-core</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions subsystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-annotation</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface VertxConstants {

String[] TIME_UNITS = Arrays.stream(TimeUnit.values()).map(Enum::toString).collect(Collectors.toList()).toArray(new String[0]);

String CDI_NAMED_QUALIFIER = "vertx";
String CDI_QUALIFIER = "vertx";
String VERTX_SERVICE = "vertx";
String ELEMENT_VERTX = "vertx";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
package org.wildfly.extension.vertx.processors;

import io.smallrye.common.annotation.Identifier;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.literal.NamedLiteral;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
import jakarta.enterprise.inject.spi.AnnotatedType;
import jakarta.enterprise.inject.spi.Bean;
Expand All @@ -37,7 +38,7 @@
import java.util.HashSet;
import java.util.Set;

import static org.wildfly.extension.vertx.VertxConstants.CDI_NAMED_QUALIFIER;
import static org.wildfly.extension.vertx.VertxConstants.CDI_QUALIFIER;

/**
* CDI Extension which adds the ability to inject the Vertx instances by the member name.
Expand All @@ -51,27 +52,36 @@ public CDIExtension() {

public void registerVertxBean(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) {
if (VertxProxyHolder.instance().getVertxProxy() != null) {
final String vpName = CDI_NAMED_QUALIFIER;
AnnotatedType<io.vertx.core.Vertx> rawVertxAnnotatedType = beanManager.createAnnotatedType(io.vertx.core.Vertx.class);
BeanAttributes<io.vertx.core.Vertx> rawVertxBeanAttributes =
new BeanAttributesWrapper<>(beanManager.createBeanAttributes(rawVertxAnnotatedType), Set.of(NamedLiteral.of(vpName)));
afterBeanDiscovery.addBean(beanManager.createBean(rawVertxBeanAttributes, io.vertx.core.Vertx.class, new RawVertxProducer()));

AnnotatedType<io.vertx.mutiny.core.Vertx> annotatedType = beanManager.createAnnotatedType(io.vertx.mutiny.core.Vertx.class);
BeanAttributes<io.vertx.mutiny.core.Vertx> beanAttributes =
new BeanAttributesWrapper<>(beanManager.createBeanAttributes(annotatedType), Set.of(NamedLiteral.of(vpName)));
afterBeanDiscovery.addBean(beanManager.createBean(beanAttributes, io.vertx.mutiny.core.Vertx.class, new MunityVertxProducer()));
// Expose the Bean with @Any and @Identifier qualifiers, client side needs to use the same Qualifiers to select this instance.
final Set<Annotation> qualifiers = Set.of(Any.Literal.INSTANCE, Identifier.Literal.of(CDI_QUALIFIER));
AnnotatedType<io.vertx.core.Vertx> rawAnnotatedType = beanManager.createAnnotatedType(io.vertx.core.Vertx.class);
BeanAttributes<io.vertx.core.Vertx> rawBeanAttributes =
new BeanAttributesWrapper<>(beanManager.createBeanAttributes(rawAnnotatedType), qualifiers);
afterBeanDiscovery.addBean(beanManager.createBean(rawBeanAttributes, io.vertx.core.Vertx.class, new AbstractVertxProducer<>() {
@Override
protected io.vertx.core.Vertx produceBeanObject(CreationalContext<io.vertx.core.Vertx> ctx) {
return rawVertx();
}
}));

AnnotatedType<io.vertx.mutiny.core.Vertx> mutinyAnnotatedType = beanManager.createAnnotatedType(io.vertx.mutiny.core.Vertx.class);
BeanAttributes<io.vertx.mutiny.core.Vertx> mutinyBeanAttributes =
new BeanAttributesWrapper<>(beanManager.createBeanAttributes(mutinyAnnotatedType), qualifiers);
afterBeanDiscovery.addBean(beanManager.createBean(mutinyBeanAttributes, io.vertx.mutiny.core.Vertx.class, new AbstractVertxProducer<>() {
@Override
protected io.vertx.mutiny.core.Vertx produceBeanObject(CreationalContext<io.vertx.mutiny.core.Vertx> ctx) {
return mutinyVertx();
}
}));
}
}

private static class BeanAttributesWrapper<T> implements BeanAttributes<T> {
private final BeanAttributes<T> delegate;
private final Set<Annotation> qualifiers;

BeanAttributesWrapper(BeanAttributes<T> delegate, Set<Annotation> additionalQualifiers) {
BeanAttributesWrapper(BeanAttributes<T> delegate, Set<Annotation> qualifiers) {
this.delegate = delegate;
this.qualifiers = new HashSet<>(delegate.getQualifiers());
this.qualifiers.addAll(additionalQualifiers);
this.qualifiers = new HashSet<>(qualifiers);
}

@Override
Expand Down Expand Up @@ -106,51 +116,42 @@ public boolean isAlternative() {

}

private abstract static class AbstractVertxInjectionTarget<T> implements InjectionTarget<T> {
@Override
public void inject(T instance, CreationalContext<T> ctx) {
}
private abstract static class AbstractVertxProducer<T> implements InjectionTargetFactory<T> {

@Override
public void postConstruct(T instance) {
}
public InjectionTarget<T> createInjectionTarget(Bean<T> bean) {
return new InjectionTarget<>() {

@Override
public void preDestroy(T instance) {
}
@Override
public T produce(CreationalContext<T> ctx) {
return produceBeanObject(ctx);
}

@Override
public void dispose(T instance) {
}
@Override
public void dispose(T instance) {
}

@Override
public Set<InjectionPoint> getInjectionPoints() {
return Set.of();
}
}
@Override
public Set<InjectionPoint> getInjectionPoints() {
return Set.of();
}

private static class MunityVertxProducer implements InjectionTargetFactory<io.vertx.mutiny.core.Vertx> {
@Override
public InjectionTarget<io.vertx.mutiny.core.Vertx> createInjectionTarget(Bean<io.vertx.mutiny.core.Vertx> bean) {
return new AbstractVertxInjectionTarget<>() {
@Override
public void inject(T instance, CreationalContext<T> ctx) {
}

@Override
public io.vertx.mutiny.core.Vertx produce(CreationalContext<io.vertx.mutiny.core.Vertx> ctx) {
return mutinyVertx();
public void postConstruct(T instance) {
}
};
}
}
private static class RawVertxProducer implements InjectionTargetFactory<io.vertx.core.Vertx> {
@Override
public InjectionTarget<io.vertx.core.Vertx> createInjectionTarget(Bean<io.vertx.core.Vertx> bean) {
return new AbstractVertxInjectionTarget<>() {

@Override
public io.vertx.core.Vertx produce(CreationalContext<io.vertx.core.Vertx> ctx) {
return rawVertx();
public void preDestroy(T instance) {
}
};
}

protected abstract T produceBeanObject(CreationalContext<T> ctx);

}

private static io.vertx.mutiny.core.Vertx mutinyVertx() {
Expand All @@ -170,4 +171,4 @@ private static io.vertx.core.Vertx rawVertx() {
VertxLogger.VERTX_LOGGER.useVertxFromSubsystem();
return vertxProxy.getVertx();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static Properties stringToProperties(String data) {
try (StringReader sr = new StringReader(data)) {
props.load(sr);
} catch (IOException ioe) {
;// ignore
// ignore
}
return props;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void destroy() {
consumer.unregister().toCompletionStage().toCompletableFuture().get();
consumer = null;
} catch (Exception e) {
; //ignore
//ignore
}
}
}
Expand Down
Loading