Skip to content

Commit

Permalink
WBRI-332
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3426 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Aug 11, 2009
1 parent 36f765f commit 794a0fd
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 111 deletions.
138 changes: 80 additions & 58 deletions impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
Expand Up @@ -156,45 +156,53 @@ public Iterable<EjbDescriptor<?>> getEjbDescriptors()

// The Web Beans manager
private BeanManagerImpl manager;
private BeanDeployer beanDeployer;
private DeploymentVisitor deploymentVisitor;
private BeanStore requestBeanStore;

public WebBeansBootstrap()
{
// initialize default services
getServices().add(ResourceLoader.class, new DefaultResourceLoader());
}

public void initialize()
public Bootstrap startContainer()
{
verify();
if (!getServices().contains(TransactionServices.class))
{
log.info("Transactional services not available. Transactional observers will be invoked synchronously.");
}
if (!getServices().contains(EjbServices.class))
{
log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
}
if (!getServices().contains(JmsServices.class))
{
log.info("JMS services not available. JMS resources will not be available.");
}
if (!getServices().contains(JpaServices.class))
{
log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
}
if (!getServices().contains(ResourceServices.class))
{
log.info("@Resource injection not available.");
}
if (!getServices().contains(WebServices.class))
synchronized (this)
{
log.info("WebService reference injection not available.");
verify();
if (!getServices().contains(TransactionServices.class))
{
log.info("Transactional services not available. Transactional observers will be invoked synchronously.");
}
if (!getServices().contains(EjbServices.class))
{
log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
}
if (!getServices().contains(JmsServices.class))
{
log.info("JMS services not available. JMS resources will not be available.");
}
if (!getServices().contains(JpaServices.class))
{
log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
}
if (!getServices().contains(ResourceServices.class))
{
log.info("@Resource injection not available.");
}
if (!getServices().contains(WebServices.class))
{
log.info("WebService reference injection not available.");
}
addImplementationServices();
createContexts();
this.manager = BeanManagerImpl.newRootManager(ServiceRegistries.unmodifiableServiceRegistry(getServices()));
CurrentManager.setRootManager(manager);
initializeContexts();
this.deploymentVisitor = new DeploymentVisitor(getServices().get(Deployment.class));
return this;
}
addImplementationServices();
createContexts();
this.manager = BeanManagerImpl.newRootManager(ServiceRegistries.unmodifiableServiceRegistry(getServices()));
CurrentManager.setRootManager(manager);
initializeContexts();
}

private void addImplementationServices()
Expand All @@ -217,32 +225,8 @@ public BeanManagerImpl getManager()
{
return manager;
}

/**
* Register the bean with the getManager(), including any standard (built in)
* beans
*
* @param classes The classes to register as Web Beans
*/
protected void registerBeans(Iterable<Class<?>> classes, BeanDeployer beanDeployer)
{
beanDeployer.addClasses(classes);
beanDeployer.getEnvironment().addBean(ManagerBean.of(manager));
beanDeployer.getEnvironment().addBean(InjectionPointBean.of(manager));
beanDeployer.getEnvironment().addBean(EventBean.of(manager));
beanDeployer.getEnvironment().addBean(InstanceBean.of(manager));
if (!getEnvironment().equals(Environments.SE))
{
beanDeployer.addClass(ConversationImpl.class);
beanDeployer.addClass(ServletConversationManager.class);
beanDeployer.addClass(JavaSEConversationTerminator.class);
beanDeployer.addClass(NumericConversationIdGenerator.class);
beanDeployer.addClass(HttpSessionManager.class);
}
beanDeployer.createBeans().deploy();
}

public void boot()
public Bootstrap startInitialization()
{
synchronized (this)
{
Expand All @@ -255,10 +239,10 @@ public void boot()
throw new IllegalStateException("No application context BeanStore set");
}

DeploymentVisitor deploymentVisitor = new DeploymentVisitor(getServices().get(Deployment.class)).visit();
deploymentVisitor.visit();

beginApplication(getApplicationContext());
BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
requestBeanStore = new ConcurrentHashMapBeanStore();
beginDeploy(requestBeanStore);

EjbDescriptorCache ejbDescriptors = new EjbDescriptorCache();
Expand All @@ -277,16 +261,54 @@ public void boot()
// Parse beans.xml before main bean deployment
parseBeansXml(deploymentVisitor.getBeansXmlUrls());

BeanDeployer beanDeployer = new BeanDeployer(manager, ejbDescriptors);
beanDeployer = new BeanDeployer(manager, ejbDescriptors);

fireBeforeBeanDiscoveryEvent(beanDeployer);
registerBeans(deploymentVisitor.getBeanClasses(), beanDeployer);
}
return this;
}

public Bootstrap deployBeans()
{
synchronized (this)
{
beanDeployer.addClasses(deploymentVisitor.getBeanClasses());
beanDeployer.getEnvironment().addBean(ManagerBean.of(manager));
beanDeployer.getEnvironment().addBean(InjectionPointBean.of(manager));
beanDeployer.getEnvironment().addBean(EventBean.of(manager));
beanDeployer.getEnvironment().addBean(InstanceBean.of(manager));
if (!getEnvironment().equals(Environments.SE))
{
beanDeployer.addClass(ConversationImpl.class);
beanDeployer.addClass(ServletConversationManager.class);
beanDeployer.addClass(JavaSEConversationTerminator.class);
beanDeployer.addClass(NumericConversationIdGenerator.class);
beanDeployer.addClass(HttpSessionManager.class);
}
beanDeployer.createBeans().deploy();
fireAfterBeanDiscoveryEvent();
log.debug("Web Beans initialized. Validating beans.");
}
return this;
}

public Bootstrap validateBeans()
{
synchronized (this)
{
getServices().get(Validator.class).validateDeployment(manager, beanDeployer.getEnvironment());
fireAfterDeploymentValidationEvent();
}
return this;
}

public Bootstrap endInitialization()
{
synchronized (this)
{
endDeploy(requestBeanStore);
}
return this;
}

private void parseBeansXml(Iterable<URL> urls)
Expand Down
105 changes: 81 additions & 24 deletions spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
Expand Up @@ -16,18 +16,37 @@
*/
package org.jboss.webbeans.bootstrap.api;

import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;

import org.jboss.webbeans.bootstrap.spi.Deployment;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.manager.api.WebBeansManager;

/**
* Bootstrap API for Web Beans.
* Application container initialization API for Web Beans.
*
* To initialize the container you must call, in this order:
*
* <ol>
* <li>{@link #startContainer()}</li>
* <li>{@link #startInitialization()}</li>
* <li>{@link #deployBeans()}</li>
* <li>{@link #validateBeans()}</li>
* <li>{@link #endInitialization()}</li>
* </ol>
*
* To stop the container and clean up, you must call {@link #shutdown()}
*
* @author Pete Muir
*
*/
public interface Bootstrap
{

/**
* Set the bean store to use as backing for the application context
*
Expand All @@ -41,49 +60,87 @@ public interface Bootstrap
* @param environment the environment to use
*/
public void setEnvironment(Environment environment);

/**
* Initialize the bootstrap:
* Creates the application container:
* <ul>
* <li>Create the manager and bind it to JNDI</li>
* <li>Checks that the services required by the environment have been
* provided</li>
* <li>Adds container provided services</li>
* <li>Creates and initializes the built in contexts</li>
* <li>Creates the manager</li>
* </ul>
*
* @throws IllegalStateException
* if not all the services required for the given environment are
* available
* This method name is a workaround for weird JBoss MC behavior, calling
*
*
* @throws IllegalStateException if not all the services required for the
* given environment are available
*/
public void initialize();
public Bootstrap startContainer();

/**
* Get the manager used for this application.
* Starts the application container initialization process:
*
* <ul>
* <li>Reads metadata from beans.xml and the {@link Deployment} service</li>
* <li>Starts the application context</li>
* <li>Starts the request context which lasts until
* {@link #endInitialization()} is called</li>
* <li>Discovers and creates {@link Extension} service providers</li>
* </ul>
*
* Finally, the {@link BeforeBeanDiscovery} event is fired.
*
* @return the manager. Unless {@link #initialize()} has been called, this
* method will return null.
*/
public WebBeansManager getManager();
public Bootstrap startInitialization();

/**
* Starts the boot process.
* Creates and deploys the application's beans:
*
* Discovers the beans and registers them with the getManager(). Also
* resolves the injection points. Before running {@link #boot()}
* {@link #initialize()} must have been called and the contexts should be
* available
* <ul>
* <li>Creates and deploys the discovered beans</li>
* <li>Creates and deploys the built-in beans defined by the CDI
* specification</li>
* </ul>
*
* Finally the {@link AfterBeanDiscovery} is event is fired
*/
public void boot();

public Bootstrap deployBeans();

/**
* Validates the deployment.
*
* After validation, the {@link AfterDeploymentValidation} event is fired
*/
public Bootstrap validateBeans();

/**
* Cleans up after the initialization
*
*/
public Bootstrap endInitialization();

/**
* Causes the container to clean up and shutdown
*
* Before the contain is shutdown the {@link BeforeShutdown} event is fired
*/
public void shutdown();

/**
* Get the services available to this bootstrap
*
* @return the services available
*/
public ServiceRegistry getServices();


/**
* Get the manager used for this application.
*
* @return the manager. Unless {@link #startContainer()} has been called, this method
* will return null.
*/
public WebBeansManager getManager();

}

0 comments on commit 794a0fd

Please sign in to comment.