Search in sources :

Example 6 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class BeanIdentifierIndexTest method testGetHash.

@Test
public void testGetHash() {
    Bean<Object> dummy01 = DummyBean.of("1");
    Bean<Object> dummy02 = DummyBean.of("2");
    BeanIdentifierIndex index01 = new BeanIdentifierIndex();
    index01.build(Collections.singleton(dummy01));
    BeanIdentifierIndex index02 = new BeanIdentifierIndex();
    index02.build(Collections.singleton(dummy01));
    BeanIdentifierIndex index03 = new BeanIdentifierIndex();
    Set<Bean<?>> beans = new HashSet<Bean<?>>();
    beans.add(dummy01);
    beans.add(dummy02);
    index03.build(beans);
    assertTrue(index01.getIndexHash() == index02.getIndexHash());
    assertFalse(index01.getIndexHash() == index03.getIndexHash());
}
Also used : BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) CommonBean(org.jboss.weld.bean.CommonBean) Bean(javax.enterprise.inject.spi.Bean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class BeanIdentifierIndexTest method testIsEmpty.

@Test
public void testIsEmpty() {
    BeanIdentifierIndex index = new BeanIdentifierIndex();
    index.build(Collections.<Bean<?>>emptySet());
    assertTrue(index.isEmpty());
}
Also used : BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) Test(org.junit.Test)

Example 8 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class BeanIdentifierIndexTest method testInvalidIndex.

@Test
public void testInvalidIndex() {
    BeanIdentifierIndex index = new BeanIdentifierIndex();
    index.build(Collections.<Bean<?>>emptySet());
    try {
        index.getIdentifier(-10);
        fail();
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        index.getIdentifier(0);
        fail();
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        index.getIdentifier(10);
        fail();
    } catch (IllegalStateException e) {
    // Expected
    }
}
Also used : IllegalStateException(org.jboss.weld.exceptions.IllegalStateException) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) Test(org.junit.Test)

Example 9 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class AccessibleManagerResolutionTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    BeanIdentifierIndex beanIdentifierIndex = new BeanIdentifierIndex();
    beanIdentifierIndex.build(Collections.<Bean<?>>emptySet());
    this.typeStore = new TypeStore();
    this.classTransformer = new ClassTransformer(typeStore, new SharedObjectCache(), ReflectionCacheFactory.newInstance(typeStore), RegistrySingletonProvider.STATIC_INSTANCE);
    this.services = new SimpleServiceRegistry();
    this.services.add(MetaAnnotationStore.class, new MetaAnnotationStore(classTransformer));
    this.services.add(ContextualStore.class, new ContextualStoreImpl(STATIC_INSTANCE, beanIdentifierIndex));
    this.services.add(ClassTransformer.class, classTransformer);
    this.services.add(SharedObjectCache.class, new SharedObjectCache());
    this.services.add(WeldConfiguration.class, new WeldConfiguration(this.services, new MockDeployment(services)));
    this.services.add(SecurityServices.class, NoopSecurityServices.INSTANCE);
    this.services.add(ObserverNotifierFactory.class, DefaultObserverNotifierFactory.INSTANCE);
    this.services.add(GlobalObserverNotifierService.class, new GlobalObserverNotifierService(services, RegistrySingletonProvider.STATIC_INSTANCE));
    this.services.add(ExpressionLanguageSupport.class, WeldWebModule.EL_SUPPORT);
    this.services.add(SpecializationAndEnablementRegistry.class, new SpecializationAndEnablementRegistry());
    this.services.add(InterceptorsApiAbstraction.class, new InterceptorsApiAbstraction(DefaultResourceLoader.INSTANCE));
    this.services.add(ProxyInstantiator.class, DefaultProxyInstantiator.INSTANCE);
    this.services.add(ResourceInjectionFactory.class, new ResourceInjectionFactory());
    this.services.add(EjbSupport.class, EjbSupport.NOOP_IMPLEMENTATION);
    // create BeanManagerImpl and initialize container
    root = BeanManagerImpl.newRootManager(STATIC_INSTANCE, "root", services);
    Container.initialize(root, services);
    // add injection target service; has to be done once container was initialized
    this.services.add(InjectionTargetService.class, new InjectionTargetService(root));
}
Also used : SpecializationAndEnablementRegistry(org.jboss.weld.bootstrap.SpecializationAndEnablementRegistry) ResourceInjectionFactory(org.jboss.weld.injection.ResourceInjectionFactory) MetaAnnotationStore(org.jboss.weld.metadata.cache.MetaAnnotationStore) ClassTransformer(org.jboss.weld.resources.ClassTransformer) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) InterceptorsApiAbstraction(org.jboss.weld.interceptor.builder.InterceptorsApiAbstraction) SharedObjectCache(org.jboss.weld.resources.SharedObjectCache) SimpleServiceRegistry(org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry) TypeStore(org.jboss.weld.metadata.TypeStore) InjectionTargetService(org.jboss.weld.injection.producer.InjectionTargetService) GlobalObserverNotifierService(org.jboss.weld.event.GlobalObserverNotifierService) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) ContextualStoreImpl(org.jboss.weld.serialization.ContextualStoreImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with BeanIdentifierIndex

use of org.jboss.weld.serialization.BeanIdentifierIndex in project core by weld.

the class WeldStartup method endInitialization.

public void endInitialization() {
    tracker.start(Tracker.OP_END_INIT);
    final BeanIdentifierIndex index = deploymentManager.getServices().get(BeanIdentifierIndex.class);
    if (index != null) {
        // Build a special index of bean identifiers
        index.build(getBeansForBeanIdentifierIndex());
    }
    // Register the managers so external requests can handle them
    // clear the TypeSafeResolvers, so data that is only used at startup
    // is not kept around using up memory
    flushCaches();
    deploymentManager.getServices().cleanupAfterBoot();
    deploymentManager.cleanupAfterBoot();
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
        BeanManagerImpl beanManager = beanDeployment.getBeanManager();
        beanManager.getInterceptorMetadataReader().cleanAfterBoot();
        beanManager.getServices().cleanupAfterBoot();
        beanManager.cleanupAfterBoot();
        // clean up beans
        for (Bean<?> bean : beanManager.getBeans()) {
            if (bean instanceof RIBean<?>) {
                RIBean<?> riBean = (RIBean<?>) bean;
                riBean.cleanupAfterBoot();
            }
        }
        // clean up decorators
        for (Decorator<?> decorator : beanManager.getDecorators()) {
            if (decorator instanceof DecoratorImpl<?>) {
                Reflections.<DecoratorImpl<?>>cast(decorator).cleanupAfterBoot();
            }
        }
        // clean up interceptors
        for (Interceptor<?> interceptor : beanManager.getInterceptors()) {
            if (interceptor instanceof InterceptorImpl<?>) {
                Reflections.<InterceptorImpl<?>>cast(interceptor).cleanupAfterBoot();
            }
        }
    }
    for (BeanDeployment beanDeployment : getBeanDeployments()) {
        beanDeployment.getBeanDeployer().cleanup();
    }
    // feed BeanDeploymentModule registry
    final BeanDeploymentModules modules = deploymentManager.getServices().get(BeanDeploymentModules.class);
    if (modules != null) {
        modules.processBeanDeployments(getBeanDeployments());
        BootstrapLogger.LOG.debugv("EE modules: {0}", modules);
    }
    getContainer().setState(ContainerState.INITIALIZED);
    if (modules != null) {
        // web modules are handled by HttpContextLifecycle
        for (BeanDeploymentModule module : modules) {
            if (!module.isWebModule()) {
                module.fireEvent(Object.class, ContextEvent.APPLICATION_INITIALIZED, InitializedLiteral.APPLICATION);
            }
        }
    }
    tracker.close();
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) DecoratorImpl(org.jboss.weld.bean.DecoratorImpl) RIBean(org.jboss.weld.bean.RIBean) BeanIdentifierIndex(org.jboss.weld.serialization.BeanIdentifierIndex) InterceptorImpl(org.jboss.weld.bean.InterceptorImpl)

Aggregations

BeanIdentifierIndex (org.jboss.weld.serialization.BeanIdentifierIndex)11 Test (org.junit.Test)6 Annotation (java.lang.annotation.Annotation)2 HashSet (java.util.HashSet)2 Bean (javax.enterprise.inject.spi.Bean)2 CommonBean (org.jboss.weld.bean.CommonBean)2 WeldConfiguration (org.jboss.weld.config.WeldConfiguration)2 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)2 ResourceInjectionFactory (org.jboss.weld.injection.ResourceInjectionFactory)2 MetaAnnotationStore (org.jboss.weld.metadata.cache.MetaAnnotationStore)2 WeldModules (org.jboss.weld.module.WeldModules)2 ClassTransformer (org.jboss.weld.resources.ClassTransformer)2 ContextualStoreImpl (org.jboss.weld.serialization.ContextualStoreImpl)2 ArrayList (java.util.ArrayList)1 Context (javax.enterprise.context.spi.Context)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 SlimAnnotatedTypeStoreImpl (org.jboss.weld.annotated.slim.SlimAnnotatedTypeStoreImpl)1 DecoratorImpl (org.jboss.weld.bean.DecoratorImpl)1 InterceptorImpl (org.jboss.weld.bean.InterceptorImpl)1 ManagedBean (org.jboss.weld.bean.ManagedBean)1