Search in sources :

Example 1 with Default

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);
                }
            }
        }
    }
}
Also used : Named(jakarta.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Default(jakarta.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation)

Example 2 with Default

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);
                }
            }
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Named(jakarta.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Default(jakarta.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation)

Example 3 with Default

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);
                }
            }
        }
    }
}
Also used : Named(jakarta.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Default(jakarta.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation)

Example 4 with Default

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());
            }
        }
    }
}
Also used : Dependent(jakarta.enterprise.context.Dependent) Observes(jakarta.enterprise.event.Observes) SSLParameters(javax.net.ssl.SSLParameters) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) HashMap(java.util.HashMap) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) Instance(jakarta.enterprise.inject.Instance) Default(jakarta.enterprise.inject.Default) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) JedisPool(redis.clients.jedis.JedisPool) HostnameVerifier(javax.net.ssl.HostnameVerifier) Method(java.lang.reflect.Method) BeanManager(jakarta.enterprise.inject.spi.BeanManager) CreationException(jakarta.enterprise.inject.CreationException) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) NamedLiteral(jakarta.enterprise.inject.literal.NamedLiteral) Set(java.util.Set) Config(org.eclipse.microprofile.config.Config) IntrospectionException(java.beans.IntrospectionException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Objects(java.util.Objects) Protocol(redis.clients.jedis.Protocol) ParameterizedType(java.lang.reflect.ParameterizedType) AfterBeanDiscovery(jakarta.enterprise.inject.spi.AfterBeanDiscovery) Type(java.lang.reflect.Type) Provider(jakarta.inject.Provider) Jedis(redis.clients.jedis.Jedis) PropertyDescriptor(java.beans.PropertyDescriptor) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Collections(java.util.Collections) Named(jakarta.inject.Named) IntrospectionException(java.beans.IntrospectionException) CreationException(jakarta.enterprise.inject.CreationException) Dependent(jakarta.enterprise.context.Dependent) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Annotation(java.lang.annotation.Annotation)

Example 5 with Default

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);
                }
            }
        }
    }
}
Also used : Named(jakarta.inject.Named) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Default(jakarta.enterprise.inject.Default) Annotation(java.lang.annotation.Annotation)

Aggregations

Default (jakarta.enterprise.inject.Default)7 InjectionPoint (jakarta.enterprise.inject.spi.InjectionPoint)7 ProcessInjectionPoint (jakarta.enterprise.inject.spi.ProcessInjectionPoint)7 Named (jakarta.inject.Named)7 Annotation (java.lang.annotation.Annotation)7 ParameterizedType (java.lang.reflect.ParameterizedType)7 Type (java.lang.reflect.Type)7 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 Dependent (jakarta.enterprise.context.Dependent)1 Observes (jakarta.enterprise.event.Observes)1 CreationException (jakarta.enterprise.inject.CreationException)1 Instance (jakarta.enterprise.inject.Instance)1 NamedLiteral (jakarta.enterprise.inject.literal.NamedLiteral)1 AfterBeanDiscovery (jakarta.enterprise.inject.spi.AfterBeanDiscovery)1 BeanManager (jakarta.enterprise.inject.spi.BeanManager)1 Provider (jakarta.inject.Provider)1 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 Introspector (java.beans.Introspector)1 PropertyDescriptor (java.beans.PropertyDescriptor)1