Search in sources :

Example 1 with ServiceRegistry

use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.

the class AdditionalServiceTest method testOverridingService.

@Test
public void testOverridingService() {
    try (WeldContainer container = createWeld().addServices(new ExecutorServices2()).initialize()) {
        ServiceRegistry registry = BeanManagerProxy.unwrap(container.getBeanManager()).getServices();
        ExecutorServices executorServices = registry.get(ExecutorServices.class);
        Assert.assertNotNull(executorServices);
        Assert.assertTrue(executorServices instanceof ExecutorServices2);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) ExecutorServices(org.jboss.weld.manager.api.ExecutorServices) ServiceRegistry(org.jboss.weld.bootstrap.api.ServiceRegistry) Test(org.junit.Test)

Example 2 with ServiceRegistry

use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.

the class AdditionalServiceTest method testAdditionalServiceWithMultipleInterfaces.

@Test
public void testAdditionalServiceWithMultipleInterfaces() {
    try (WeldContainer container = createWeld().addServices(new BravoImpl()).initialize()) {
        ServiceRegistry registry = BeanManagerProxy.unwrap(container.getBeanManager()).getServices();
        Bravo1Service bravo1 = registry.get(Bravo1Service.class);
        Bravo2Service bravo2 = registry.get(Bravo2Service.class);
        BravoImpl bravo3 = registry.get(BravoImpl.class);
        assertNotNull(bravo1);
        assertNotNull(bravo2);
        assertNotNull(bravo3);
        assertTrue(bravo1 == bravo2);
        assertTrue(bravo2 == bravo3);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) ServiceRegistry(org.jboss.weld.bootstrap.api.ServiceRegistry) Test(org.junit.Test)

Example 3 with ServiceRegistry

use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.

the class AdditionalServiceTest method testSimpleAdditionalService.

@Test
public void testSimpleAdditionalService() {
    try (WeldContainer container = createWeld().addServices(new AlphaImpl()).initialize()) {
        ServiceRegistry registry = BeanManagerProxy.unwrap(container.getBeanManager()).getServices();
        assertNotNull(registry.get(AlphaService.class));
        assertTrue(registry.get(AlphaService.class) instanceof AlphaImpl);
        assertNull(registry.get(AlphaImpl.class));
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) ServiceRegistry(org.jboss.weld.bootstrap.api.ServiceRegistry) Test(org.junit.Test)

Example 4 with ServiceRegistry

use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.

the class VerifyingExtension method init.

void init(@Observes BeforeBeanDiscovery event, BeanManager manager) throws Exception {
    ServiceRegistry services = BeanManagerProxy.unwrap(manager).getServices();
    this.classFileServices = services.get(ClassFileServices.class);
    this.resolver = new FastProcessAnnotatedTypeResolver(services.get(GlobalObserverNotifierService.class).getAllObserverMethods());
    this.notifier = BeanManagerProxy.unwrap(manager).getGlobalLenientObserverNotifier();
    this.discovery = services.get(RequiredAnnotationDiscovery.class);
    this.transformer = services.get(ClassTransformer.class);
}
Also used : RequiredAnnotationDiscovery(org.jboss.weld.bootstrap.events.RequiredAnnotationDiscovery) ClassFileServices(org.jboss.weld.resources.spi.ClassFileServices) FastProcessAnnotatedTypeResolver(org.jboss.weld.bootstrap.FastProcessAnnotatedTypeResolver) ClassTransformer(org.jboss.weld.resources.ClassTransformer) ServiceRegistry(org.jboss.weld.bootstrap.api.ServiceRegistry) GlobalObserverNotifierService(org.jboss.weld.event.GlobalObserverNotifierService)

Example 5 with ServiceRegistry

use of org.jboss.weld.bootstrap.api.ServiceRegistry in project wildfly by wildfly.

the class WeldDeployment method createAndRegisterAdditionalBeanDeploymentArchive.

protected BeanDeploymentArchiveImpl createAndRegisterAdditionalBeanDeploymentArchive(Module module, Class<?> beanClass) {
    String id = null;
    if (module == null) {
        id = BOOTSTRAP_CLASSLOADER_BDA_ID;
    } else {
        id = module.getIdentifier() + ADDITIONAL_CLASSES_BDA_SUFFIX;
    }
    BeanDeploymentArchiveImpl newBda = new BeanDeploymentArchiveImpl(Collections.singleton(beanClass.getName()), Collections.singleton(beanClass.getName()), BeansXml.EMPTY_BEANS_XML, module, id, BeanArchiveType.SYNTHETIC, false);
    WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(newBda);
    newBda.addBeanClass(beanClass);
    ServiceRegistry newBdaServices = newBda.getServices();
    for (Entry<Class<? extends Service>, Service> entry : serviceRegistry.entrySet()) {
        // Do not overwrite existing services
        if (!newBdaServices.contains(entry.getKey())) {
            newBdaServices.add(entry.getKey(), Reflections.cast(entry.getValue()));
        }
    }
    if (module == null) {
        // For bootstrapClassLoaderBeanDeploymentArchive always use the parent ResourceLoader
        newBdaServices.add(ResourceLoader.class, serviceRegistry.get(ResourceLoader.class));
    }
    if (module != null && eeModuleDescriptors.containsKey(module.getIdentifier())) {
        newBda.getServices().add(EEModuleDescriptor.class, eeModuleDescriptors.get(module.getIdentifier()));
    }
    // handle BDAs visible from the new BDA
    for (BeanDeploymentArchiveImpl bda : beanDeploymentArchives) {
        if (newBda.isAccessible(bda)) {
            newBda.addBeanDeploymentArchive(bda);
        }
    }
    // handle visibility of the new BDA from other BDAs
    for (BeanDeploymentArchiveImpl bda : beanDeploymentArchives) {
        if (bda.isAccessible(newBda)) {
            bda.addBeanDeploymentArchive(newBda);
        }
    }
    // make the top-level deployment BDAs visible from the additional archive
    newBda.addBeanDeploymentArchives(rootBeanDeploymentModule.getBeanDeploymentArchives());
    // Ignore beans loaded by the bootstrap class loader. This should only be JDK classes in most cases.
    // See getBeanDeploymentArchive(final Class<?> beanClass), per the JavaDoc this is mean to archive which
    // contains the bean class.
    final ClassLoader cl = beanClass.getClassLoader();
    if (cl != null) {
        additionalBeanDeploymentArchivesByClassloader.put(cl, newBda);
    }
    beanDeploymentArchives.add(newBda);
    return newBda;
}
Also used : WeldModuleResourceLoader(org.jboss.as.weld.WeldModuleResourceLoader) ResourceLoader(org.jboss.weld.resources.spi.ResourceLoader) Service(org.jboss.weld.bootstrap.api.Service) ServiceRegistry(org.jboss.weld.bootstrap.api.ServiceRegistry) SimpleServiceRegistry(org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry)

Aggregations

ServiceRegistry (org.jboss.weld.bootstrap.api.ServiceRegistry)7 WeldContainer (org.jboss.weld.environment.se.WeldContainer)3 Test (org.junit.Test)3 SimpleServiceRegistry (org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry)2 ResourceLoader (org.jboss.weld.resources.spi.ResourceLoader)2 WeldModuleResourceLoader (org.jboss.as.weld.WeldModuleResourceLoader)1 SimpleProxyServices (org.jboss.weld.bean.proxy.util.SimpleProxyServices)1 FastProcessAnnotatedTypeResolver (org.jboss.weld.bootstrap.FastProcessAnnotatedTypeResolver)1 Service (org.jboss.weld.bootstrap.api.Service)1 RequiredAnnotationDiscovery (org.jboss.weld.bootstrap.events.RequiredAnnotationDiscovery)1 CDI11Deployment (org.jboss.weld.bootstrap.spi.CDI11Deployment)1 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)1 EjbServices (org.jboss.weld.ejb.spi.EjbServices)1 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)1 BeanManagerLookupService (org.jboss.weld.manager.BeanManagerLookupService)1 ExecutorServices (org.jboss.weld.manager.api.ExecutorServices)1 ClassTransformer (org.jboss.weld.resources.ClassTransformer)1 DefaultResourceLoader (org.jboss.weld.resources.DefaultResourceLoader)1 ClassFileServices (org.jboss.weld.resources.spi.ClassFileServices)1 NoopSecurityServices (org.jboss.weld.security.NoopSecurityServices)1