Search in sources :

Example 1 with SocketBindingRequest

use of org.wildfly.swarm.internal.SocketBindingRequest 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)

Aggregations

CreationalContext (javax.enterprise.context.spi.CreationalContext)1 Bean (javax.enterprise.inject.spi.Bean)1 SocketBindingRequest (org.wildfly.swarm.internal.SocketBindingRequest)1 Customizer (org.wildfly.swarm.spi.api.Customizer)1 CommonBean (org.wildfly.swarm.spi.api.cdi.CommonBean)1