Search in sources :

Example 1 with CommonBean

use of org.wildfly.swarm.spi.api.cdi.CommonBean in project wildfly-swarm by wildfly-swarm.

the class InterfaceExtensionTest method testAfterBeanDiscovery.

@Test
public void testAfterBeanDiscovery() throws Exception {
    ConfigView configView = mock(ConfigView.class);
    List<SimpleKey> interfaces = Arrays.asList(new SimpleKey("test"));
    when(configView.simpleSubkeys(any(ConfigKey.class))).thenReturn(interfaces);
    when(configView.valueOf(any(ConfigKey.class))).thenReturn("192.168.1.1");
    ext = new InterfaceExtension(configView);
    BeanManager beanManager = mock(BeanManager.class);
    AfterBeanDiscovery abd = mock(AfterBeanDiscovery.class);
    @SuppressWarnings("unchecked") ArgumentCaptor<CommonBean<Interface>> captor = ArgumentCaptor.forClass(CommonBean.class);
    ext.afterBeanDiscovery(abd, beanManager);
    verify(abd, times(1)).addBean(captor.capture());
    assertThat(captor.getValue().create(null).getName()).isEqualTo("test");
    assertThat(captor.getValue().create(null).getExpression()).isEqualTo("192.168.1.1");
}
Also used : ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) BeanManager(javax.enterprise.inject.spi.BeanManager) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey) Test(org.junit.Test)

Example 2 with CommonBean

use of org.wildfly.swarm.spi.api.cdi.CommonBean in project wildfly-swarm by wildfly-swarm.

the class OutboundSocketBindingExtension method afterBeanDiscovery.

@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("OutboundSocketBindingExtension.afterBeanDiscovery")) {
        for (OutboundSocketBindingRequest each : this.bindings) {
            Supplier<Customizer> customizerSupplier = () -> (Customizer) () -> {
                Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
                groups.stream().map((Bean<?> e) -> {
                    CreationalContext<?> ctx = beanManager.createCreationalContext(e);
                    return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
                }).filter(group -> group.name().equals(each.socketBindingGroup())).findFirst().ifPresent((group) -> group.outboundSocketBinding(each.outboundSocketBinding()));
            };
            CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class).beanClass(OutboundSocketBindingExtension.class).scope(Singleton.class).addQualifier(Pre.Literal.INSTANCE).addQualifier(AnyLiteral.INSTANCE).createSupplier(customizerSupplier).addType(Customizer.class).addType(Object.class).build();
            abd.addBean(customizerBean);
        }
    }
}
Also used : OutboundSocketBindingRequest(org.wildfly.swarm.internal.OutboundSocketBindingRequest) CreationalContext(javax.enterprise.context.spi.CreationalContext) Customizer(org.wildfly.swarm.spi.api.Customizer) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Example 3 with CommonBean

use of org.wildfly.swarm.spi.api.cdi.CommonBean in project wildfly-swarm by wildfly-swarm.

the class SocketBindingExtension method afterBeanDiscovery.

@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    try (AutoCloseable handle = Performance.time("SocketBindingExtension.afterBeanDiscovery")) {
        for (SocketBindingRequest each : this.bindings) {
            Supplier<Customizer> supplier = () -> (Customizer) () -> {
                Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
                groups.stream().map((Bean<?> e) -> {
                    CreationalContext<?> ctx = beanManager.createCreationalContext(e);
                    return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
                }).filter(group -> group.name().equals(each.socketBindingGroup())).findFirst().ifPresent((group) -> group.socketBinding(each.socketBinding()));
            };
            CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class).beanClass(SocketBindingExtension.class).scope(Singleton.class).addQualifier(Pre.Literal.INSTANCE).addQualifier(AnyLiteral.INSTANCE).createSupplier(supplier).addType(Customizer.class).addType(Object.class).build();
            abd.addBean(customizerBean);
        }
    }
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) SocketBindingRequest(org.wildfly.swarm.internal.SocketBindingRequest) Customizer(org.wildfly.swarm.spi.api.Customizer) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Example 4 with CommonBean

use of org.wildfly.swarm.spi.api.cdi.CommonBean 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)

Example 5 with CommonBean

use of org.wildfly.swarm.spi.api.cdi.CommonBean in project wildfly-swarm by wildfly-swarm.

the class SocketBindingGroupExtension method afterBeanDiscovery.

@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
    List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
    for (SimpleKey groupName : configuredGroups) {
        Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
        AtomicBoolean producerRequired = new AtomicBoolean(false);
        if (groups.stream().noneMatch(e -> e.getQualifiers().stream().anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {
            SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");
            applyConfiguration(group);
            if (producerRequired.get()) {
                CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class).beanClass(SocketBindingGroupExtension.class).scope(ApplicationScoped.class).addQualifier(AnyLiteral.INSTANCE).addQualifier(new NamedLiteral(group.name())).createSupplier(() -> group).addType(SocketBindingGroup.class).addType(Object.class).build();
                abd.addBean(interfaceBean);
            }
        }
    }
}
Also used : AfterBeanDiscovery(javax.enterprise.inject.spi.AfterBeanDiscovery) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AnyLiteral(org.jboss.weld.literal.AnyLiteral) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey) List(java.util.List) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) ConfigKey(org.wildfly.swarm.spi.api.config.ConfigKey) SocketBindingGroup(org.wildfly.swarm.spi.api.SocketBindingGroup) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Named(javax.inject.Named) SocketBindingGroup(org.wildfly.swarm.spi.api.SocketBindingGroup) NamedLiteral(org.jboss.weld.literal.NamedLiteral) SimpleKey(org.wildfly.swarm.spi.api.config.SimpleKey) CommonBean(org.wildfly.swarm.spi.api.cdi.CommonBean) Bean(javax.enterprise.inject.spi.Bean)

Aggregations

CommonBean (org.wildfly.swarm.spi.api.cdi.CommonBean)5 Bean (javax.enterprise.inject.spi.Bean)4 AfterBeanDiscovery (javax.enterprise.inject.spi.AfterBeanDiscovery)3 BeanManager (javax.enterprise.inject.spi.BeanManager)3 ConfigKey (org.wildfly.swarm.spi.api.config.ConfigKey)3 ConfigView (org.wildfly.swarm.spi.api.config.ConfigView)3 SimpleKey (org.wildfly.swarm.spi.api.config.SimpleKey)3 List (java.util.List)2 Set (java.util.Set)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 CreationalContext (javax.enterprise.context.spi.CreationalContext)2 Observes (javax.enterprise.event.Observes)2 Named (javax.inject.Named)2 AnyLiteral (org.jboss.weld.literal.AnyLiteral)2 NamedLiteral (org.jboss.weld.literal.NamedLiteral)2 Customizer (org.wildfly.swarm.spi.api.Customizer)2 CommonBeanBuilder (org.wildfly.swarm.spi.api.cdi.CommonBeanBuilder)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 Interface (org.wildfly.swarm.container.Interface)1