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");
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
}
Aggregations