use of jakarta.enterprise.inject.Default in project helidon by oracle.
the class JedisExtension method processJedisInjectionPoint.
private <T extends Jedis> void processJedisInjectionPoint(@Observes final ProcessInjectionPoint<?, T> e) {
if (e != null) {
final InjectionPoint injectionPoint = e.getInjectionPoint();
if (injectionPoint != null) {
final Type type = injectionPoint.getType();
assert type instanceof Class;
assert Jedis.class.isAssignableFrom((Class<?>) type);
final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
for (final Annotation qualifier : qualifiers) {
final String instanceName;
if (qualifier instanceof Default) {
instanceName = "default";
} else if (qualifier instanceof Named) {
instanceName = ((Named) qualifier).value();
} else {
instanceName = null;
}
if (instanceName != null && !instanceName.isEmpty()) {
this.instanceNames.add(instanceName);
}
}
}
}
}
use of jakarta.enterprise.inject.Default in project helidon by oracle.
the class JedisExtension method processJedisProviderInjectionPoint.
private <T extends Provider<Jedis>> void processJedisProviderInjectionPoint(@Observes final ProcessInjectionPoint<?, T> e) {
if (e != null) {
final InjectionPoint injectionPoint = e.getInjectionPoint();
if (injectionPoint != null) {
final Type type = injectionPoint.getType();
assert type instanceof ParameterizedType;
assert Provider.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType());
final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
for (final Annotation qualifier : qualifiers) {
final String instanceName;
if (qualifier instanceof Default) {
instanceName = "default";
} else if (qualifier instanceof Named) {
instanceName = ((Named) qualifier).value();
} else {
instanceName = null;
}
if (instanceName != null && !instanceName.isEmpty()) {
this.instanceNames.add(instanceName);
}
}
}
}
}
use of jakarta.enterprise.inject.Default in project helidon by oracle.
the class JedisExtension method processJedisPoolProviderInjectionPoint.
@SuppressWarnings("checkstyle:linelength")
private <T extends Provider<JedisPool>> void processJedisPoolProviderInjectionPoint(@Observes final ProcessInjectionPoint<?, T> e) {
if (e != null) {
final InjectionPoint injectionPoint = e.getInjectionPoint();
if (injectionPoint != null) {
final Type type = injectionPoint.getType();
assert type instanceof Class;
assert Provider.class.isAssignableFrom((Class<?>) type);
final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
for (final Annotation qualifier : qualifiers) {
final String instanceName;
if (qualifier instanceof Default) {
instanceName = "default";
} else if (qualifier instanceof Named) {
instanceName = ((Named) qualifier).value();
} else {
instanceName = null;
}
if (instanceName != null && !instanceName.isEmpty()) {
this.instanceNames.add(instanceName);
}
}
}
}
}
use of jakarta.enterprise.inject.Default in project helidon by oracle.
the class JedisExtension method addBeans.
private void addBeans(@Observes final AfterBeanDiscovery event, final BeanManager beanManager) throws IntrospectionException {
if (event != null && beanManager != null) {
for (final String instanceName : this.instanceNames) {
if (instanceName != null) {
final Set<Annotation> qualifiers;
if (instanceName.equals("default")) {
qualifiers = Collections.singleton(Default.Literal.INSTANCE);
} else {
qualifiers = Collections.singleton(NamedLiteral.of(instanceName));
}
event.<JedisPoolConfig>addBean().addTransitiveTypeClosure(JedisPoolConfig.class).scope(ApplicationScoped.class).addQualifiers(qualifiers).produceWith((instance) -> {
final JedisPoolConfig returnValue = new JedisPoolConfig();
try {
this.configure(instance.select(Config.class).get(), returnValue, JedisPoolConfig.class, instanceName);
} catch (final IntrospectionException | ReflectiveOperationException e) {
throw new CreationException(e.getMessage(), e);
}
return returnValue;
});
final Annotation[] qualifiersArray = qualifiers.toArray(new Annotation[qualifiers.size()]);
event.<JedisPool>addBean().addTransitiveTypeClosure(JedisPool.class).scope(ApplicationScoped.class).addQualifiers(qualifiers).produceWith(instance -> {
return produceJedisPool(instance, instanceName, qualifiersArray);
}).disposeWith((p, instance) -> p.destroy());
event.<Jedis>addBean().addTransitiveTypeClosure(Jedis.class).scope(Dependent.class).addQualifiers(qualifiers).produceWith(instance -> instance.select(JedisPool.class, qualifiersArray).get().getResource()).disposeWith((j, instance) -> j.close());
}
}
}
}
use of jakarta.enterprise.inject.Default in project helidon by oracle.
the class JedisExtension method processJedisPoolInjectionPoint.
private <T extends JedisPool> void processJedisPoolInjectionPoint(@Observes final ProcessInjectionPoint<?, T> e) {
if (e != null) {
final InjectionPoint injectionPoint = e.getInjectionPoint();
if (injectionPoint != null) {
final Type type = injectionPoint.getType();
assert type instanceof Class;
assert JedisPool.class.isAssignableFrom((Class<?>) type);
final Set<Annotation> qualifiers = injectionPoint.getQualifiers();
for (final Annotation qualifier : qualifiers) {
final String instanceName;
if (qualifier instanceof Default) {
instanceName = "default";
} else if (qualifier instanceof Named) {
instanceName = ((Named) qualifier).value();
} else {
instanceName = null;
}
if (instanceName != null && !instanceName.isEmpty()) {
this.instanceNames.add(instanceName);
}
}
}
}
}
Aggregations