Search in sources :

Example 1 with Interface

use of org.wildfly.swarm.container.Interface in project wildfly-swarm by wildfly-swarm.

the class InterfaceExtension method afterBeanDiscovery.

@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    List<SimpleKey> configuredInterfaces = this.configView.simpleSubkeys(ROOT);
    for (SimpleKey interfaceName : configuredInterfaces) {
        Set<Bean<?>> ifaces = beanManager.getBeans(Interface.class, AnyLiteral.INSTANCE);
        if (ifaces.stream().noneMatch(e -> e.getQualifiers().stream().anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(interfaceName + "-interface")))) {
            Interface iface = new Interface(interfaceName.name(), "0.0.0.0");
            applyConfiguration(iface);
            CommonBean<Interface> interfaceBean = CommonBeanBuilder.newBuilder(Interface.class).beanClass(InterfaceExtension.class).scope(ApplicationScoped.class).addQualifier(AnyLiteral.INSTANCE).addQualifier(new NamedLiteral(interfaceName.name() + "-interface")).createSupplier(() -> iface).addType(Interface.class).addType(Object.class).build();
            abd.addBean(interfaceBean);
        }
    }
}
Also used : AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) Set(java.util.Set) AnyLiteral(org.jboss.weld.literal.AnyLiteral) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey) List(java.util.List) Interface(org.wildfly.swarm.container.Interface) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) Observes(javax.enterprise.event.Observes) NamedLiteral(org.jboss.weld.literal.NamedLiteral) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Named(javax.inject.Named) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) Bean(javax.enterprise.inject.spi.Bean) BeanManager(javax.enterprise.inject.spi.BeanManager) CommonBeanBuilder(org.wildfly.swarm.spi.api.cdi.CommonBeanBuilder) Named(javax.inject.Named) NamedLiteral(org.jboss.weld.literal.NamedLiteral) Interface(org.wildfly.swarm.container.Interface) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Aggregations

List (java.util.List)1 Set (java.util.Set)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Observes (javax.enterprise.event.Observes)1 AfterBeanDiscovery (javax.enterprise.inject.spi.AfterBeanDiscovery)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 Named (javax.inject.Named)1 AnyLiteral (org.jboss.weld.literal.AnyLiteral)1 NamedLiteral (org.jboss.weld.literal.NamedLiteral)1 Interface (org.wildfly.swarm.container.Interface)1 CommonBean (org.wildfly.swarm.spi.api.cdi.CommonBean)1 CommonBeanBuilder (org.wildfly.swarm.spi.api.cdi.CommonBeanBuilder)1 ConfigKey (org.wildfly.swarm.spi.api.config.ConfigKey)1 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)1 SimpleKey (org.wildfly.swarm.spi.api.config.SimpleKey)1