private void configureWerewolf(BeanManager bm, BeanConfigurator<Werewolf> werewolf){ werewolf.beanClass(Werewolf.class); werewolf.addTransitiveTypeClosure(Werewolf.class); Set<Class<? extends Annotation>> stereotypes = new HashSet<>(); stereotypes.add(Model.class); werewolf.stereotypes(stereotypes); werewolf.produceWith(obj -> new Werewolf()); }
public static void registerVertxBeanIfNeeded(AfterBeanDiscovery discovery, BeanManager beanManager) { Optional<Bean<?>> optional = beanManager.getBeans(Vertx.class).stream().findFirst(); if (!optional.isPresent()) { LOGGER.debug("Declaring a Vert.x bean"); discovery.addBean() .types(Vertx.class) .beanClass(Vertx.class) .scope(Singleton.class) .produceWith(i -> Vertx.vertx()) .disposeWith((vertx, i) -> vertx.close()); } } }
private void afterBeanDiscovery(@Observes final AfterBeanDiscovery event) { if (event != null) { for (final String dataSourceName : this.dataSourceNames) { event.<HikariDataSource>addBean() .addQualifier(NamedLiteral.of(dataSourceName)) // ...and Default and Any? .addTransitiveTypeClosure(HikariDataSource.class) .beanClass(HikariDataSource.class) .scope(ApplicationScoped.class) .produceWith(beans -> new HikariDataSource(new HikariConfig(toProperties(dataSourceName, beans.select(Config.class).get())))) .disposeWith((dataSource, beans) -> dataSource.close()); } } }
private void configureBogey(BeanManager bm, BeanConfigurator<Bogey> bogey){ bogey.beanClass(Bogey.class); bogey.addType(Bogey.class); bogey.addQualifier(Undead.UndeadLiteral.INSTANCE); bogey.produceWith(obj -> new Bogey()); }
private void addCamelContext(@Observes AfterBeanDiscovery abd, BeanManager manager) { abd.addBean() .types(CamelContext.class) .scope(ApplicationScoped.class) .produceWith(instance -> new DefaultCamelContext(new CamelCdiRegistry(manager))) .disposeWith(rethrow((context, instance) -> context.stop())); }
private void addCamelContext(@Observes AfterBeanDiscovery abd, BeanManager manager) { abd.addBean() .types(CamelContext.class) .scope(ApplicationScoped.class) .produceWith(instance -> new DefaultCamelContext(new CamelCdiRegistry(manager))) .disposeWith(rethrow((context, instance) -> context.stop())); }
public void registerWeldSEContexts(@Observes AfterBeanDiscovery event, BeanManager manager) { if (ignoreEvent(event)) { return; } final String contextId = BeanManagerProxy.unwrap(manager).getContextId(); this.threadContext = new ThreadContext(contextId); event.addContext(threadContext); // Register WeldContainer as a singleton event.addBean().addType(WeldContainer.class).addQualifier(Default.Literal.INSTANCE).scope(Singleton.class) .produceWith((i) -> WeldContainer.instance(contextId)); }
public void registerWeldSEContexts(@Observes AfterBeanDiscovery event, BeanManager manager) { if (ignoreEvent(event)) { return; } final String contextId = BeanManagerProxy.unwrap(manager).getContextId(); this.threadContext = new ThreadContext(contextId); event.addContext(threadContext); // Register WeldContainer as a singleton event.addBean().addType(WeldContainer.class).addQualifier(Default.Literal.INSTANCE).scope(Singleton.class) .produceWith((i) -> WeldContainer.instance(contextId)); }
public void registerWeldSEContexts(@Observes AfterBeanDiscovery event, BeanManager manager) { if (ignoreEvent(event)) { return; } final String contextId = BeanManagerProxy.unwrap(manager).getContextId(); this.threadContext = new ThreadContext(contextId); event.addContext(threadContext); // Register WeldContainer as a singleton event.addBean().addType(WeldContainer.class).addQualifier(Default.Literal.INSTANCE).scope(Singleton.class) .produceWith((i) -> WeldContainer.instance(contextId)); }
ConfigurationValue.Literal.of("")) .scope(Dependent.class) .produceWith(cdi -> produceConfigurationValue(cdi.select(InjectionPoint.class).get(), cdi.select(Configurations.class).get()));
private void configureSkeleton(BeanManager bm, BeanConfigurator<Skeleton> skeleton) { // set bean class, qualifier, stereotype, scope // no read() method used here, all set manually skeleton.beanClass(Skeleton.class); skeleton.addQualifier(Undead.UndeadLiteral.INSTANCE); skeleton.addStereotype(Monster.class); skeleton.scope(RequestScoped.class); skeleton.addTransitiveTypeClosure(Skeleton.class); for (AnnotatedField<? super Skeleton> field : bm.createAnnotatedType(Skeleton.class).getFields()) { if (field.getJavaMember().getType().equals(DesireToHurtHumans.class)) { skeleton.addInjectionPoint(bm.createInjectionPoint(field)); break; } } // set Supplier as producer skeleton.produceWith(MonsterController.skeletonSupplier); // set Consumer in dispose method skeleton.disposeWith(MonsterController.skeletonConsumer); }
private void configureGhost(BeanManager bm, BeanConfigurator<Ghost> ghost) { // creation using read from bean attributes ghost.read(bm.createBeanAttributes(bm.createAnnotatedType(Ghost.class))); ghost.beanClass(Ghost.class); ghost.addQualifier(Undead.UndeadLiteral.INSTANCE); ghost.addStereotype(Monster.class); ghost.scope(RequestScoped.class); // test replacement of IPs InjectionPoint ghostWeaponIP = null; InjectionPoint ghostDesireIP = null; for (AnnotatedField<? super Ghost> field : bm.createAnnotatedType(Ghost.class).getFields()) { if (field.getJavaMember().getType().equals(DesireToHurtHumans.class)) { ghostDesireIP = bm.createInjectionPoint(field); } if (field.getJavaMember().getType().equals(Weapon.class)) { ghostWeaponIP = bm.createInjectionPoint(field); } } // firstly add one IP, then replace it with other ghost.addInjectionPoint(ghostWeaponIP); ghost.injectionPoints(ghostDesireIP); // set producing ghost.produceWith(MonsterController.getGhostInstance); }
private void configureZombie(BeanManager bm, BeanConfigurator<Zombie> zombie) { // init with read() method, then set values zombie.read(bm.createAnnotatedType(Zombie.class)); zombie.beanClass(Zombie.class); zombie.addQualifiers(Undead.UndeadLiteral.INSTANCE, Dangerous.DangerousLiteral.INSTANCE); zombie.addStereotype(Monster.class); zombie.scope(RequestScoped.class); InjectionPoint zombieWeaponIP = null; InjectionPoint zombieDesireIP = null; for (AnnotatedField<? super Zombie> field : bm.createAnnotatedType(Zombie.class).getFields()) { if (field.getJavaMember().getType().equals(DesireToHurtHumans.class)) { zombieDesireIP = bm.createInjectionPoint(field); } if (field.getJavaMember().getType().equals(Weapon.class)) { zombieWeaponIP = bm.createInjectionPoint(field); } } // add multiple injection points zombie.addInjectionPoints(zombieWeaponIP, zombieDesireIP); // set Function as a supplier zombie.produceWith(MonsterController.zombieProducingFunction); // set BiConsumer to destroyWith zombie.destroyWith(MonsterController.zombieConsumer); // make passivation capable zombie.id("zombie"); }