Skip to content

Commit

Permalink
WELD-1909 Turn EjbSupport into per-archive service
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Apr 13, 2015
1 parent 9e7ccf3 commit cc462d0
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
Expand Up @@ -88,7 +88,7 @@ public AbstractBeanDeployer(BeanManagerImpl manager, ServiceRegistry services, E
this.classTransformer = services.get(ClassTransformer.class);
this.slimAnnotatedTypeStore = services.get(SlimAnnotatedTypeStore.class);
this.specializationAndEnablementRegistry = services.get(SpecializationAndEnablementRegistry.class);
this.ejbSupport = services.get(EjbSupport.class);
this.ejbSupport = manager.getServices().getRequired(EjbSupport.class);
}

protected BeanManagerImpl getManager() {
Expand Down
Expand Up @@ -115,6 +115,9 @@ public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerIm
ejbDescriptors.addAll(beanDeploymentArchive.getEjbs());
}

services.get(WeldModules.class).postBeanArchiveServiceRegistration(services, beanManager);
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);
} else {
Expand Down
5 changes: 0 additions & 5 deletions impl/src/main/java/org/jboss/weld/bootstrap/WeldStartup.java
Expand Up @@ -100,7 +100,6 @@
import org.jboss.weld.manager.api.ExecutorServices;
import org.jboss.weld.metadata.TypeStore;
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.module.EjbSupport;
import org.jboss.weld.module.ObserverNotifierFactory;
import org.jboss.weld.module.WeldModules;
import org.jboss.weld.resources.ClassTransformer;
Expand Down Expand Up @@ -308,10 +307,6 @@ private void addImplementationServices(ServiceRegistry services) {
services.add(Validator.class, new Validator(modules.getPluggableValidators()));
}

if (!services.contains(EjbSupport.class)) {
services.add(EjbSupport.class, EjbSupport.NOOP_IMPLEMENTATION);
}

GlobalObserverNotifierService observerNotificationService = new GlobalObserverNotifierService(services, contextId);
services.add(GlobalObserverNotifierService.class, observerNotificationService);

Expand Down
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/module/EjbSupport.java
Expand Up @@ -33,7 +33,7 @@
import org.jboss.weld.util.collections.SetMultimap;

/**
* This service provides EJB support. It is implemented by the weld-ejb module.
* This service provides EJB support. It is implemented by the weld-ejb module. This is a per-archive service.
*
* @author Jozef Hartinger
*
Expand Down
29 changes: 26 additions & 3 deletions impl/src/main/java/org/jboss/weld/module/WeldModule.java
Expand Up @@ -105,6 +105,29 @@ interface PostContextRegistrationContext {
void addContext(ContextHolder<? extends Context> context);
}

/**
* This hook is called once Weld registered {@link Service}s for deployment of a particular bean archive.
* A module may use this hook to discover services for a particular archive and to register additional services.
* This method is called for each bean archive that is processed.
* @param ctx context
*/
default void postBeanArchiveServiceRegistration(PostBeanArchiveServiceRegistrationContext ctx) {
}

interface PostBeanArchiveServiceRegistrationContext {
/**
* A mutable service registry for a given bean archive. Existing services may be replaced and additional services may be registered by a module.
* @return services
*/
ServiceRegistry getServices();

/**
* Returns the {@link BeanManagerImpl} for the given bean archive deployment.
* @return bean manager
*/
BeanManagerImpl getBeanManager();
}

/**
* This hook is called by Weld before it starts deploying beans. A module may register additional built-in beans.
* This callback is called for each {@link BeanDeployment} separately.
Expand All @@ -123,17 +146,17 @@ interface PreBeanRegistrationContext {
*/
Environment getEnvironment();
/**
* Returns {@link BeanDeploymentArchive} represented by this bean deployment.
* Returns {@link BeanDeploymentArchive} represented by this bean archive deployment.
* @return bda
*/
BeanDeploymentArchive getBeanDeploymentArchive();
/**
* Returns the {@link BeanManagerImpl} for the given bean deployment.
* Returns the {@link BeanManagerImpl} for the given bean archive deployment.
* @return bean manager
*/
BeanManagerImpl getBeanManager();
/**
* Register an additional built-in bean with the given bean deployment.
* Register an additional built-in bean with the given bean archive deployment.
* @param additional built-in bean
*/
void registerBean(AbstractBuiltInBean<?> bean);
Expand Down
19 changes: 19 additions & 0 deletions impl/src/main/java/org/jboss/weld/module/WeldModules.java
Expand Up @@ -36,6 +36,7 @@
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.logging.BootstrapLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.module.WeldModule.PostBeanArchiveServiceRegistrationContext;
import org.jboss.weld.module.WeldModule.PostContextRegistrationContext;
import org.jboss.weld.module.WeldModule.PostServiceRegistrationContext;
import org.jboss.weld.module.WeldModule.PreBeanRegistrationContext;
Expand Down Expand Up @@ -108,6 +109,24 @@ public void addContext(ContextHolder<? extends Context> context) {
}
}

public void postBeanArchiveServiceRegistration(final ServiceRegistry services, final BeanManagerImpl manager) {
final PostBeanArchiveServiceRegistrationContext ctx = new PostBeanArchiveServiceRegistrationContext() {

@Override
public ServiceRegistry getServices() {
return services;
}

@Override
public BeanManagerImpl getBeanManager() {
return manager;
}
};
for (WeldModule module : modules) {
module.postBeanArchiveServiceRegistration(ctx);
}
}

public void preBeanRegistration(final BeanDeployment deployment, final Environment environment) {
final PreBeanRegistrationContext ctx = new PreBeanRegistrationContext() {
@Override
Expand Down
Expand Up @@ -32,16 +32,13 @@
*/
public class WeldEjbModule implements WeldModule {

private final EjbSupport ejbSupport = new EjbSupportImpl();

@Override
public String getName() {
return "weld-ejb";
}

@Override
public void postServiceRegistration(PostServiceRegistrationContext ctx) {
ctx.getServices().add(EjbSupport.class, ejbSupport);
ctx.getServices().add(SLSBInvocationInjectionPoint.class, new SLSBInvocationInjectionPoint());
ctx.registerPlugableValidator(new WeldEjbValidator());
ctx.getServices().get(ResourceInjectionFactory.class).addResourceInjectionProcessor(new EjbResourceInjectionProcessor());
Expand All @@ -53,6 +50,11 @@ public void postContextRegistration(PostContextRegistrationContext ctx) {
ctx.addContext(new ContextHolder<EjbRequestContext>(new EjbRequestContextImpl(ctx.getContextId()), EjbRequestContext.class, EjbLiteral.INSTANCE));
}

@Override
public void postBeanArchiveServiceRegistration(PostBeanArchiveServiceRegistrationContext ctx) {
ctx.getServices().add(EjbSupport.class, new EjbSupportImpl());
}

@Override
public void preBeanRegistration(PreBeanRegistrationContext ctx) {
ctx.registerBean(new SessionBeanAwareInjectionPointBean(ctx.getBeanManager()));
Expand Down

0 comments on commit cc462d0

Please sign in to comment.