Skip to content

Commit

Permalink
WELD-1909 Move EjbDescriptors to the EJB module
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Apr 13, 2015
1 parent b2ca4d6 commit d63fd45
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 64 deletions.
9 changes: 4 additions & 5 deletions impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
Expand Up @@ -41,7 +41,6 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder;
import org.jboss.weld.bootstrap.events.ProcessAnnotatedTypeImpl;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.spi.ClassFileServices;
Expand All @@ -65,11 +64,11 @@ public class BeanDeployer extends AbstractBeanDeployer<BeanDeployerEnvironment>
private final AnnotationApiAbstraction annotationApi;
private final ClassFileServices classFileServices;

public BeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, ServiceRegistry services) {
this(manager, ejbDescriptors, services, BeanDeployerEnvironmentFactory.newEnvironment(ejbDescriptors, manager));
public BeanDeployer(BeanManagerImpl manager, ServiceRegistry services) {
this(manager, services, BeanDeployerEnvironmentFactory.newEnvironment(manager));
}

public BeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, ServiceRegistry services, BeanDeployerEnvironment environment) {
public BeanDeployer(BeanManagerImpl manager, ServiceRegistry services, BeanDeployerEnvironment environment) {
super(manager, services, environment);
this.resourceLoader = manager.getServices().get(ResourceLoader.class);
this.annotatedTypeStore = manager.getServices().get(SlimAnnotatedTypeStore.class);
Expand Down Expand Up @@ -183,7 +182,7 @@ public void createClassBeans() {
}

protected void createClassBean(SlimAnnotatedType<?> annotatedType, SetMultimap<Class<?>, SlimAnnotatedType<?>> otherWeldClasses) {
boolean managedBeanOrDecorator = !getEnvironment().getEjbDescriptors().contains(annotatedType.getJavaClass()) && Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType);
boolean managedBeanOrDecorator = !ejbSupport.isEjb(annotatedType.getJavaClass()) && Beans.isTypeManagedBeanOrDecoratorOrInterceptor(annotatedType);
if (managedBeanOrDecorator) {
containerLifecycleEvents.preloadProcessInjectionTarget(annotatedType.getJavaClass());
containerLifecycleEvents.preloadProcessBeanAttributes(annotatedType.getJavaClass());
Expand Down
Expand Up @@ -52,7 +52,6 @@
import org.jboss.weld.bean.builtin.AbstractBuiltInBean;
import org.jboss.weld.bean.builtin.ExtensionBean;
import org.jboss.weld.config.WeldConfiguration;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.injection.attributes.WeldInjectionPointAttributes;
import org.jboss.weld.manager.BeanManagerImpl;
Expand All @@ -77,14 +76,13 @@ public class BeanDeployerEnvironment {
private final Set<DisposalMethod<?, ?>> resolvedDisposalBeans;
private final Set<DecoratorImpl<?>> decorators;
private final Set<InterceptorImpl<?>> interceptors;
private final EjbDescriptors ejbDescriptors;
private final TypeSafeDisposerResolver disposalMethodResolver;
private final ClassTransformer classTransformer;
private final Set<EnhancedAnnotatedType<?>> newManagedBeanClasses;
private final Map<InternalEjbDescriptor<?>, EnhancedAnnotatedType<?>> newSessionBeanDescriptorsFromInjectionPoint;
private final BeanManagerImpl manager;

protected BeanDeployerEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl manager) {
protected BeanDeployerEnvironment(BeanManagerImpl manager) {
this(
new HashSet<SlimAnnotatedTypeContext<?>>(),
new HashSet<Class<?>>(),
Expand All @@ -97,7 +95,6 @@ protected BeanDeployerEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl
new HashSet<DisposalMethod<?, ?>>(),
new HashSet<DecoratorImpl<?>>(),
new HashSet<InterceptorImpl<?>>(),
ejbDescriptors,
new HashSet<EnhancedAnnotatedType<?>>(),
new HashMap<InternalEjbDescriptor<?>, EnhancedAnnotatedType<?>>(),
manager);
Expand All @@ -115,7 +112,6 @@ protected BeanDeployerEnvironment(
Set<DisposalMethod<?, ?>> resolvedDisposalBeans,
Set<DecoratorImpl<?>> decorators,
Set<InterceptorImpl<?>> interceptors,
EjbDescriptors ejbDescriptors,
Set<EnhancedAnnotatedType<?>> newManagedBeanClasses,
Map<InternalEjbDescriptor<?>, EnhancedAnnotatedType<?>> newSessionBeanDescriptorsFromInjectionPoint,
BeanManagerImpl manager) {
Expand All @@ -130,7 +126,6 @@ protected BeanDeployerEnvironment(
this.resolvedDisposalBeans = resolvedDisposalBeans;
this.decorators = decorators;
this.interceptors = interceptors;
this.ejbDescriptors = ejbDescriptors;
this.disposalMethodResolver = new TypeSafeDisposerResolver(allDisposalBeans, manager.getServices().get(WeldConfiguration.class));
this.classTransformer = manager.getServices().get(ClassTransformer.class);
this.newManagedBeanClasses = newManagedBeanClasses;
Expand Down Expand Up @@ -286,12 +281,13 @@ public void addNewBeansFromInjectionPoints(Set<? extends InjectionPoint> injecti
}

private void addNewBeanFromInjectionPoint(Class<?> rawType, Type baseType) {
if (getEjbDescriptors().contains(rawType)) {
InternalEjbDescriptor<?> descriptor = getEjbDescriptors().getUnique(rawType);
newSessionBeanDescriptorsFromInjectionPoint.put(descriptor, classTransformer.getEnhancedAnnotatedType(rawType, baseType, manager.getId()));
} else {
// FIXME
// if (getEjbDescriptors().contains(rawType)) {
// InternalEjbDescriptor<?> descriptor = getEjbDescriptors().getUnique(rawType);
// newSessionBeanDescriptorsFromInjectionPoint.put(descriptor, classTransformer.getEnhancedAnnotatedType(rawType, baseType, manager.getId()));
// } else {
newManagedBeanClasses.add(classTransformer.getEnhancedAnnotatedType(rawType, baseType, manager.getId()));
}
// }
}

public Set<? extends RIBean<?>> getBeans() {
Expand All @@ -316,10 +312,6 @@ public Set<InterceptorImpl<?>> getInterceptors() {
return Collections.unmodifiableSet(beans);
}

public EjbDescriptors getEjbDescriptors() {
return ejbDescriptors;
}

/**
* Resolve the disposal method for the given producer method. Any resolved
* beans will be marked as such for the purpose of validating that all
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.jboss.weld.bean.ProducerMethod;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment.WeldMethodKey;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.collections.SetMultimap;
Expand All @@ -39,14 +38,14 @@ public class BeanDeployerEnvironmentFactory {
private BeanDeployerEnvironmentFactory() {
}

public static BeanDeployerEnvironment newEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl manager) {
return new BeanDeployerEnvironment(ejbDescriptors, manager);
public static BeanDeployerEnvironment newEnvironment(BeanManagerImpl manager) {
return new BeanDeployerEnvironment(manager);
}

/**
* Creates a new threadsafe BeanDeployerEnvironment instance. These instances are used by {@link ConcurrentBeanDeployer} during bootstrap.
*/
public static BeanDeployerEnvironment newConcurrentEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl manager) {
public static BeanDeployerEnvironment newConcurrentEnvironment(BeanManagerImpl manager) {
return new BeanDeployerEnvironment(Collections.newSetFromMap(new ConcurrentHashMap<SlimAnnotatedTypeContext<?>, Boolean>()),
Collections.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>()), SetMultimap.<Class<?>, AbstractClassBean<?>> newConcurrentSetMultimap(),
Collections.newSetFromMap(new ConcurrentHashMap<ProducerField<?, ?>, Boolean>()),
Expand All @@ -56,7 +55,7 @@ public static BeanDeployerEnvironment newConcurrentEnvironment(EjbDescriptors ej
Collections.newSetFromMap(new ConcurrentHashMap<DisposalMethod<?, ?>, Boolean>()),
Collections.newSetFromMap(new ConcurrentHashMap<DisposalMethod<?, ?>, Boolean>()),
Collections.newSetFromMap(new ConcurrentHashMap<DecoratorImpl<?>, Boolean>()),
Collections.newSetFromMap(new ConcurrentHashMap<InterceptorImpl<?>, Boolean>()), ejbDescriptors,
Collections.newSetFromMap(new ConcurrentHashMap<InterceptorImpl<?>, Boolean>()),
Collections.newSetFromMap(new ConcurrentHashMap<EnhancedAnnotatedType<?>, Boolean>()),
new ConcurrentHashMap<InternalEjbDescriptor<?>, EnhancedAnnotatedType<?>>(), manager);
}
Expand Down
Expand Up @@ -51,7 +51,6 @@
import org.jboss.weld.bootstrap.spi.Filter;
import org.jboss.weld.bootstrap.spi.Metadata;
import org.jboss.weld.config.WeldConfiguration;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.injection.producer.InjectionTargetService;
import org.jboss.weld.interceptor.builder.InterceptorsApiAbstraction;
import org.jboss.weld.logging.BootstrapLogger;
Expand Down Expand Up @@ -87,10 +86,8 @@ public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerIm

public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerImpl deploymentManager, ServiceRegistry deploymentServices, Collection<ContextHolder<? extends Context>> contexts, boolean additionalBeanArchive) {
this.beanDeploymentArchive = beanDeploymentArchive;
EjbDescriptors ejbDescriptors = new EjbDescriptors();

ServiceRegistry registry = beanDeploymentArchive.getServices();
registry.add(EjbDescriptors.class, ejbDescriptors);

ResourceLoader resourceLoader = registry.get(ResourceLoader.class);
if (resourceLoader == null) {
Expand All @@ -113,9 +110,9 @@ public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerIm
services.addIfAbsent(EjbSupport.class, EjbSupport.NOOP_IMPLEMENTATION);

if (services.get(WeldConfiguration.class).getBooleanProperty(CONCURRENT_DEPLOYMENT) && services.contains(ExecutorServices.class)) {
beanDeployer = new ConcurrentBeanDeployer(beanManager, ejbDescriptors, deploymentServices);
beanDeployer = new ConcurrentBeanDeployer(beanManager, deploymentServices);
} else {
beanDeployer = new BeanDeployer(beanManager, ejbDescriptors, deploymentServices);
beanDeployer = new BeanDeployer(beanManager, deploymentServices);
}
beanManager.getServices().get(SpecializationAndEnablementRegistry.class).registerEnvironment(beanManager, beanDeployer.getEnvironment(), additionalBeanArchive);

Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.executor.IterativeWorkerTaskFactory;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.manager.api.ExecutorServices;
Expand All @@ -42,8 +41,8 @@ public class ConcurrentBeanDeployer extends BeanDeployer {

private final ExecutorServices executor;

public ConcurrentBeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors, ServiceRegistry services) {
super(manager, ejbDescriptors, services, BeanDeployerEnvironmentFactory.newConcurrentEnvironment(ejbDescriptors, manager));
public ConcurrentBeanDeployer(BeanManagerImpl manager, ServiceRegistry services) {
super(manager, services, BeanDeployerEnvironmentFactory.newConcurrentEnvironment(manager));
this.executor = services.get(ExecutorServices.class);
}

Expand Down
Expand Up @@ -99,7 +99,6 @@
import org.jboss.weld.context.CreationalContextImpl;
import org.jboss.weld.context.PassivatingContextWrapper;
import org.jboss.weld.context.WeldCreationalContext;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.ejb.spi.EjbDescriptor;
import org.jboss.weld.event.EventImpl;
Expand Down Expand Up @@ -1185,7 +1184,7 @@ public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans) {

@Override
public <T> EjbDescriptor<T> getEjbDescriptor(String beanName) {
return getServices().get(EjbDescriptors.class).get(beanName);
return getServices().get(EjbSupport.class).getEjbDescriptor(beanName);
}

@Override
Expand Down Expand Up @@ -1370,9 +1369,8 @@ public <T> Instance<Object> getInstance(CreationalContext<?> ctx) {
@Override
public <T> BeanAttributes<T> createBeanAttributes(AnnotatedType<T> type) {
EnhancedAnnotatedType<T> clazz = services.get(ClassTransformer.class).getEnhancedAnnotatedType(type, getId());
if (services.get(EjbDescriptors.class).contains(type.getJavaClass())) {
final InternalEjbDescriptor<T> descriptor = services.get(EjbDescriptors.class).getUnique(clazz.getJavaClass());
return services.get(EjbSupport.class).createSessionBeanAttributes(clazz, descriptor, this);
if (services.get(EjbSupport.class).isEjb(type.getJavaClass())) {
return services.get(EjbSupport.class).createSessionBeanAttributes(clazz, this);
}
return BeanAttributesFactory.forBean(clazz, this);
}
Expand Down
42 changes: 40 additions & 2 deletions impl/src/main/java/org/jboss/weld/module/EjbSupport.java
Expand Up @@ -17,6 +17,8 @@
package org.jboss.weld.module;

import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;

import javax.enterprise.inject.New;
import javax.enterprise.inject.spi.BeanAttributes;
Expand All @@ -28,6 +30,7 @@
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.ejb.spi.EjbDescriptor;
import org.jboss.weld.ejb.spi.EjbServices;
import org.jboss.weld.injection.producer.BasicInjectionTarget;
import org.jboss.weld.manager.BeanManagerImpl;
Expand All @@ -48,7 +51,7 @@ public interface EjbSupport extends Service {
* @param manager the bean manager
* @return BeanAttributes representation of a given session bean
*/
<T> BeanAttributes<T> createSessionBeanAttributes(EnhancedAnnotatedType<T> type, InternalEjbDescriptor<?> descriptor, BeanManagerImpl manager);
<T> BeanAttributes<T> createSessionBeanAttributes(EnhancedAnnotatedType<T> type, BeanManagerImpl manager);

/**
* Creates an {@link InjectionTarget} implementation for a given session bean.
Expand Down Expand Up @@ -97,6 +100,26 @@ public interface EjbSupport extends Service {
*/
void registerCdiInterceptorsForMessageDrivenBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager);

/**
* Indicates whether an {@link EjbDescriptor} is known for a given class
* @param beanClass
* @return true iff an EjbDescriptor for the given class exists
*/
boolean isEjb(Class<?> beanClass);

/**
* Returns an {@link EjbDescriptor} identified by the given name or null if no such descriptor exists
* @param beanName
* @return descriptor identified by the given name or null if no such descriptor exists
*/
<T> InternalEjbDescriptor<T> getEjbDescriptor(String beanName);

/**
* Returns a collection of all known EJB descriptors
* @return a collection of all known EJB descriptors
*/
Collection<InternalEjbDescriptor<?>> getEjbDescriptors();

EjbSupport NOOP_IMPLEMENTATION = new EjbSupport() {

@Override
Expand All @@ -113,7 +136,7 @@ public <T> BasicInjectionTarget<T> createSessionBeanInjectionTarget(EnhancedAnno
}

@Override
public <T> BeanAttributes<T> createSessionBeanAttributes(EnhancedAnnotatedType<T> type, InternalEjbDescriptor<?> descriptor, BeanManagerImpl manager) {
public <T> BeanAttributes<T> createSessionBeanAttributes(EnhancedAnnotatedType<T> type, BeanManagerImpl manager) {
return fail();
}

Expand All @@ -139,5 +162,20 @@ public Class<? extends Annotation> getTimeoutAnnotation() {
@Override
public void registerCdiInterceptorsForMessageDrivenBeans(BeanDeployerEnvironment environment, BeanManagerImpl manager) {
}

@Override
public Collection<InternalEjbDescriptor<?>> getEjbDescriptors() {
return Collections.emptyList();
}

@Override
public boolean isEjb(Class<?> beanClass) {
return false;
}

@Override
public <T> InternalEjbDescriptor<T> getEjbDescriptor(String beanName) {
return null;
}
};
}
Expand Up @@ -18,12 +18,12 @@

import static org.jboss.weld.util.reflection.Reflections.cast;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.ejb.spi.EjbDescriptor;
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.util.collections.SetMultimap;
Expand All @@ -33,20 +33,19 @@
*
* @author Pete Muir
*/
public class EjbDescriptors implements Service, Iterable<InternalEjbDescriptor<?>> {
class EjbDescriptors {
// EJB name -> EJB descriptors map
private final Map<String, InternalEjbDescriptor<?>> ejbByName;

private final SetMultimap<Class<?>, String> ejbByClass;

public static final EjbDescriptors EMPTY = new EjbDescriptors();

/**
* Constructor
*/
public EjbDescriptors() {
EjbDescriptors(Collection<EjbDescriptor<?>> descriptors) {
this.ejbByName = new HashMap<String, InternalEjbDescriptor<?>>();
this.ejbByClass = SetMultimap.newSetMultimap();
addAll(descriptors);
}

/**
Expand All @@ -64,7 +63,7 @@ public <T> InternalEjbDescriptor<T> get(String beanName) {
*
* @param ejbDescriptor The EJB descriptor to add
*/
public <T> void add(EjbDescriptor<T> ejbDescriptor) {
private <T> void add(EjbDescriptor<T> ejbDescriptor) {
InternalEjbDescriptor<T> internalEjbDescriptor = InternalEjbDescriptor.of(ejbDescriptor);
ejbByName.put(ejbDescriptor.getEjbName(), internalEjbDescriptor);
ejbByClass.put(ejbDescriptor.getBeanClass(), internalEjbDescriptor.getEjbName());
Expand Down Expand Up @@ -108,23 +107,20 @@ public <T> InternalEjbDescriptor<T> getUnique(Class<T> beanClass) {
*
* @param ejbDescriptors The descriptors to add
*/
public void addAll(Iterable<EjbDescriptor<?>> ejbDescriptors) {
private void addAll(Iterable<EjbDescriptor<?>> ejbDescriptors) {
for (EjbDescriptor<?> ejbDescriptor : ejbDescriptors) {
add(ejbDescriptor);
}
}

/**
* Clears both maps
*/
public void clear() {
ejbByName.clear();
}

public Iterator<InternalEjbDescriptor<?>> iterator() {
return ejbByName.values().iterator();
}

public Collection<InternalEjbDescriptor<?>> getAll() {
return ejbByName.values();
}

public void cleanup() {
this.ejbByClass.clear();
this.ejbByName.clear();
Expand Down

0 comments on commit d63fd45

Please sign in to comment.