protected AbstractBeanDeployer<E> deploySpecialized() { // ensure that all decorators are initialized before initializing // the rest of the beans for (DecoratorImpl<?> bean : getEnvironment().getDecorators()) { bean.initialize(getEnvironment()); containerLifecycleEvents.fireProcessBean(getManager(), bean); manager.addDecorator(bean); BootstrapLogger.LOG.foundDecorator(bean); } for (InterceptorImpl<?> bean : getEnvironment().getInterceptors()) { bean.initialize(getEnvironment()); containerLifecycleEvents.fireProcessBean(getManager(), bean); manager.addInterceptor(bean); BootstrapLogger.LOG.foundInterceptor(bean); } return this; }
/** * Notifies CDI extension of a given {@link InjectionPoint}. */ protected <T, X> FieldInjectionPointAttributes<T, X> processInjectionPoint( FieldInjectionPointAttributes<T, X> injectionPointAttributes, Class<?> declaringComponentClass, BeanManagerImpl manager) { return manager.getContainerLifecycleEvents().fireProcessInjectionPoint(injectionPointAttributes, declaringComponentClass, manager); }
protected void processInjectionTargetEvents(Iterable<? extends AbstractBean<?, ?>> beans) { if (!containerLifecycleEvents.isProcessInjectionTargetObserved()) { return; } for (AbstractBean<?, ?> bean : beans) { if (!(bean instanceof NewBean) && bean instanceof AbstractClassBean<?>) { containerLifecycleEvents.fireProcessInjectionTarget(getManager(), (AbstractClassBean<?>) bean); } } }
protected void processProducerEvents(Iterable<? extends AbstractBean<?, ?>> beans) { if (!containerLifecycleEvents.isProcessProducerObserved()) { return; } for (AbstractBean<?, ?> bean : beans) { if (!(bean instanceof NewBean) && bean instanceof AbstractProducerBean<?, ?, ?>) { containerLifecycleEvents.fireProcessProducer(getManager(), Reflections.<AbstractProducerBean<?, ?, Member>>cast(bean)); } } }
@Override protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedType<?> type, String id) { SlimAnnotatedType<?> annotatedType = transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id); Extension extension = getReceiver(); SlimAnnotatedTypeContext<?> annotatedTypeContext = SlimAnnotatedTypeContext.of(annotatedType, extension); ProcessAnnotatedTypeImpl<?> event = events.fireProcessAnnotatedType(getBeanManager(), annotatedTypeContext); if (event == null) { deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext); store.put(annotatedType); } else if (event.isVeto()) { return; } else { annotatedType = event.getResultingAnnotatedType(); deployment.getBeanDeployer().getEnvironment().addSyntheticAnnotatedType(annotatedType, extension); store.put(annotatedType); } } }
public void processAnnotatedTypes() { Set<SlimAnnotatedTypeContext<?>> classesToBeAdded = new HashSet<SlimAnnotatedTypeContext<?>>(); Set<SlimAnnotatedTypeContext<?>> classesToBeRemoved = new HashSet<SlimAnnotatedTypeContext<?>>(); for (SlimAnnotatedTypeContext<?> annotatedTypeContext : getEnvironment().getAnnotatedTypes()) { SlimAnnotatedType<?> annotatedType = annotatedTypeContext.getAnnotatedType(); final ProcessAnnotatedTypeImpl<?> event = containerLifecycleEvents.fireProcessAnnotatedType(getManager(), annotatedTypeContext); // process the result if (event != null) { if (event.isVeto()) { getEnvironment().vetoJavaClass(annotatedType.getJavaClass()); classesToBeRemoved.add(annotatedTypeContext); } else { boolean dirty = event.isDirty(); if (dirty) { classesToBeRemoved.add(annotatedTypeContext); // remove the original class classesToBeAdded.add(SlimAnnotatedTypeContext.of(event.getResultingAnnotatedType(), annotatedTypeContext.getExtension())); } processPriority(event.getResultingAnnotatedType()); } } else { processPriority(annotatedType); } } getEnvironment().removeAnnotatedTypes(classesToBeRemoved); getEnvironment().addAnnotatedTypes(classesToBeAdded); }
protected <T> void processBean(Bean<T> bean) { BeanManagerImpl beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager(); if (bean instanceof Interceptor<?>) { beanManager.addInterceptor((Interceptor<?>) bean); } else if (bean instanceof Decorator<?>) { beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) bean, beanManager)); } else { beanManager.addBean(bean); } containerLifecycleEvents.fireProcessBean(beanManager, bean); }
public <T> ProcessAnnotatedTypeImpl<T> fireProcessAnnotatedType(BeanManagerImpl beanManager, SlimAnnotatedTypeContext<T> annotatedTypeContext) { if (!isProcessAnnotatedTypeObserved()) { return null; } final Set<ExtensionObserverMethodImpl<?, ?>> observers = annotatedTypeContext.getResolvedProcessAnnotatedTypeObservers(); final SlimAnnotatedType<T> annotatedType = annotatedTypeContext.getAnnotatedType(); // if the fast resolver resolved an empty set of observer methods, skip this event if (observers != null && observers.isEmpty()) { BootstrapLogger.LOG.patSkipped(annotatedType); return null; } ProcessAnnotatedTypeImpl<T> event = null; if (annotatedTypeContext.getExtension() == null) { event = new ProcessAnnotatedTypeImpl<T>(beanManager, annotatedType); } else { event = new ProcessSyntheticAnnotatedTypeImpl<T>(beanManager, annotatedTypeContext); } if (observers == null) { BootstrapLogger.LOG.patDefaultResolver(annotatedType); fireProcessAnnotatedType(event, beanManager); } else { BootstrapLogger.LOG.patFastResolver(annotatedType); fireProcessAnnotatedType(event, annotatedTypeContext.getResolvedProcessAnnotatedTypeObservers()); } return event; }
protected AbstractBeanDeployer<E> fireProcessBeanEvents() { for (RIBean<?> bean : getEnvironment().getBeans()) { if (!(bean instanceof NewBean)) { containerLifecycleEvents.fireProcessBean(getManager(), bean); } } return this; }
protected void processBeanAttributes(Iterable<? extends AbstractBean<?, ?>> beans) { if (!containerLifecycleEvents.isProcessBeanAttributesObserved()) { return; } if (!beans.iterator().hasNext()) { return; // exit recursion } Collection<AbstractBean<?, ?>> vetoedBeans = new HashSet<AbstractBean<?, ?>>(); Collection<AbstractBean<?, ?>> previouslySpecializedBeans = new HashSet<AbstractBean<?, ?>>(); for (AbstractBean<?, ?> bean : beans) { // fire ProcessBeanAttributes for class beans boolean vetoed = fireProcessBeanAttributes(bean); if (vetoed) { vetoedBeans.add(bean); } } // remove vetoed class beans for (AbstractBean<?, ?> bean : vetoedBeans) { if (bean.isSpecializing()) { previouslySpecializedBeans.addAll(specializationAndEnablementRegistry.resolveSpecializedBeans(bean)); specializationAndEnablementRegistry.vetoSpecializingBean(bean); } getEnvironment().vetoBean(bean); } // if a specializing bean was vetoed, let's process the specializing bean now processBeans(previouslySpecializedBeans); }
public void preloadProcessBeanAttributes(Type type) { if (preloader != null && isProcessBeanAttributesObserved()) { preloader.preloadContainerLifecycleEvent(ProcessBeanAttributes.class, type); } }
public void preloadProcessAnnotatedType(Class<?> type) { if (preloader != null && isProcessAnnotatedTypeObserved()) { preloader.preloadContainerLifecycleEvent(ProcessAnnotatedType.class, type); } }
protected <T, S> boolean fireProcessBeanAttributes(AbstractBean<T, S> bean) { if (!specializationAndEnablementRegistry.isCandidateForLifecycleEvent(bean)) { return false; } ProcessBeanAttributesImpl<T> event = containerLifecycleEvents.fireProcessBeanAttributes(getManager(), bean, bean.getAnnotated(), bean.getType()); if (event == null) { return false; } if (event.isVeto()) { return true; } if (event.isDirty()) { bean.setAttributes(ExternalBeanAttributesFactory.<T>of(event.getBeanAttributesInternal(), manager)); bean.checkSpecialization(); } return false; } }
int preloaderThreadPoolSize = configuration.getIntegerProperty(ConfigurationKey.PRELOADER_THREAD_POOL_SIZE); if (preloaderThreadPoolSize > 0 && Permissions.hasPermission(Permissions.MODIFY_THREAD_GROUP)) { preloader = new ContainerLifecycleEventPreloader(preloaderThreadPoolSize, observerNotificationService.getGlobalLenientObserverNotifier()); services.add(ContainerLifecycleEvents.class, new ContainerLifecycleEvents(preloader, services.get(RequiredAnnotationDiscovery.class))); if (environment.isEEModulesAware()) { services.add(BeanDeploymentModules.class, new BeanDeploymentModules(contextId, services));
/** * Fires a {@link ProcessAnnotatedType}. Instead of using the default event dispatching mechanism, this method directly notifies * extension observers resolved by FastProcessAnnotatedTypeResolver. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void fireProcessAnnotatedType(ProcessAnnotatedTypeImpl<?> event, Set<ExtensionObserverMethodImpl<?, ?>> observers) { List<Throwable> errors = new LinkedList<Throwable>(); for (ExtensionObserverMethodImpl observer : observers) { // FastProcessAnnotatedTypeResolver does not consider special scope inheritance rules (see CDI - section 4.1) if (checkScopeInheritanceRules(event.getOriginalAnnotatedType(), observer)) { try { observer.notify(event); } catch (Throwable e) { errors.add(e); } } } if (!errors.isEmpty()) { throw new DefinitionException(errors); } }
public <T> ProcessBeanAttributesImpl<T> fireProcessBeanAttributes(BeanManagerImpl beanManager, BeanAttributes<T> attributes, Annotated annotated, Type type) { if (isProcessBeanAttributesObserved()) { return ProcessBeanAttributesImpl.fire(beanManager, attributes, annotated, type); } return null; }
@Override public <X> InjectionTarget<X> fireProcessInjectionTarget(AnnotatedType<X> annotatedType, InjectionTarget<X> injectionTarget) { return services.get(ContainerLifecycleEvents.class).fireProcessInjectionTarget(this, annotatedType, injectionTarget); }
@Override protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedType<?> type, String id) { SlimAnnotatedType<?> annotatedType = transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id); Extension extension = getReceiver(); SlimAnnotatedTypeContext<?> annotatedTypeContext = SlimAnnotatedTypeContext.of(annotatedType, extension); ProcessAnnotatedTypeImpl<?> event = events.fireProcessAnnotatedType(getBeanManager(), annotatedTypeContext); if (event == null) { deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext); store.put(annotatedType); } else if (event.isVeto()) { return; } else { annotatedType = event.getResultingAnnotatedType(); deployment.getBeanDeployer().getEnvironment().addSyntheticAnnotatedType(annotatedType, extension); store.put(annotatedType); } } }
public void processAnnotatedTypes() { Set<SlimAnnotatedTypeContext<?>> classesToBeAdded = new HashSet<SlimAnnotatedTypeContext<?>>(); Set<SlimAnnotatedTypeContext<?>> classesToBeRemoved = new HashSet<SlimAnnotatedTypeContext<?>>(); for (SlimAnnotatedTypeContext<?> annotatedTypeContext : getEnvironment().getAnnotatedTypes()) { SlimAnnotatedType<?> annotatedType = annotatedTypeContext.getAnnotatedType(); final ProcessAnnotatedTypeImpl<?> event = containerLifecycleEvents.fireProcessAnnotatedType(getManager(), annotatedTypeContext); // process the result if (event != null) { if (event.isVeto()) { getEnvironment().vetoJavaClass(annotatedType.getJavaClass()); classesToBeRemoved.add(annotatedTypeContext); } else { boolean dirty = event.isDirty(); if (dirty) { classesToBeRemoved.add(annotatedTypeContext); // remove the original class classesToBeAdded.add(SlimAnnotatedTypeContext.of(event.getResultingAnnotatedType(), annotatedTypeContext.getExtension())); } processPriority(event.getResultingAnnotatedType()); } } else { processPriority(annotatedType); } } getEnvironment().removeAnnotatedTypes(classesToBeRemoved); getEnvironment().addAnnotatedTypes(classesToBeAdded); }
if (beanManager == null) { beanManager = getOrCreateBeanDeployment(bean.getBeanClass()).getBeanManager(); } else { beanManager.addInterceptor((Interceptor<?>) bean); if (priority != null) { globalEnablementBuilder.addInterceptor(bean.getBeanClass(), priority); beanManager.addDecorator(CustomDecoratorWrapper.of((Decorator<?>) bean, beanManager)); if (priority != null) { globalEnablementBuilder.addDecorator(bean.getBeanClass(), priority); beanManager.addBean(bean); if (priority != null && bean.isAlternative()) { globalEnablementBuilder.addAlternative(bean.getBeanClass(), priority); containerLifecycleEvents.fireProcessBean(beanManager, bean, registration.extension);