Author: pete.muir(a)jboss.org
Date: 2009-08-10 20:09:18 -0400 (Mon, 10 Aug 2009)
New Revision: 3426
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java
Log:
WBRI-332
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-11
00:03:07 UTC (rev 3425)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-11
00:09:18 UTC (rev 3426)
@@ -156,6 +156,9 @@
// The Web Beans manager
private BeanManagerImpl manager;
+ private BeanDeployer beanDeployer;
+ private DeploymentVisitor deploymentVisitor;
+ private BeanStore requestBeanStore;
public WebBeansBootstrap()
{
@@ -163,38 +166,43 @@
getServices().add(ResourceLoader.class, new DefaultResourceLoader());
}
- public void initialize()
+ public Bootstrap startContainer()
{
- verify();
- if (!getServices().contains(TransactionServices.class))
+ synchronized (this)
{
- log.info("Transactional services not available. Transactional observers
will be invoked synchronously.");
+ 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;
}
- 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();
}
private void addImplementationServices()
@@ -217,32 +225,8 @@
{
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)
{
@@ -255,10 +239,10 @@
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();
@@ -277,16 +261,54 @@
// 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)
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-08-11
00:03:07 UTC (rev 3425)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-08-11
00:09:18 UTC (rev 3426)
@@ -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
*
@@ -41,49 +60,87 @@
* @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:
*
- * @return the manager. Unless {@link #initialize()} has been called, this
- * method will return null.
+ * <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.
+ *
*/
- 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();
+
}
Modified:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
===================================================================
---
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-08-11
00:03:07 UTC (rev 3425)
+++
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-08-11
00:09:18 UTC (rev 3426)
@@ -17,6 +17,8 @@
package org.jboss.webbeans.bootstrap.api.helpers;
import org.jboss.webbeans.bootstrap.api.Bootstrap;
+import org.jboss.webbeans.bootstrap.api.Environment;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.manager.api.WebBeansManager;
@@ -30,21 +32,12 @@
protected abstract Bootstrap delegate();
- public void boot()
- {
- delegate().boot();
- }
-
public WebBeansManager getManager()
{
return delegate().getManager();
}
+
- public void initialize()
- {
- delegate().initialize();
- }
-
public void setApplicationContext(BeanStore beanStore)
{
delegate().setApplicationContext(beanStore);
@@ -72,5 +65,35 @@
{
return delegate().equals(obj);
}
+
+ public Bootstrap deployBeans()
+ {
+ return delegate().deployBeans();
+ }
+
+ public Bootstrap endInitialization()
+ {
+ return delegate().endInitialization();
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return delegate().getServices();
+ }
+
+ public void setEnvironment(Environment environment)
+ {
+ delegate().setEnvironment(environment);
+ }
+
+ public Bootstrap startInitialization()
+ {
+ return delegate().startInitialization();
+ }
+
+ public Bootstrap validateBeans()
+ {
+ return delegate().validateBeans();
+ }
}
Modified:
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
===================================================================
---
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java 2009-08-11
00:03:07 UTC (rev 3425)
+++
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java 2009-08-11
00:09:18 UTC (rev 3426)
@@ -23,7 +23,7 @@
bootstrap.setEnvironment(Environments.SE);
bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test(expectedExceptions=IllegalStateException.class)
@@ -39,7 +39,7 @@
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
bootstrap.getServices().add(WebServices.class, new MockWebServices());
bootstrap.getServices().add(JmsServices.class, new MockJmsServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test(expectedExceptions=IllegalStateException.class)
@@ -55,7 +55,7 @@
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
bootstrap.getServices().add(WebServices.class, new MockWebServices());
bootstrap.getServices().add(JmsServices.class, new MockJmsServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test(expectedExceptions=IllegalStateException.class)
@@ -71,7 +71,7 @@
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
bootstrap.getServices().add(JmsServices.class, new MockJmsServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test(expectedExceptions=IllegalStateException.class)
@@ -87,7 +87,7 @@
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
bootstrap.getServices().add(WebServices.class, new MockWebServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@@ -105,7 +105,7 @@
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
bootstrap.getServices().add(WebServices.class, new MockWebServices());
bootstrap.getServices().add(JmsServices.class, new MockJmsServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test
@@ -120,7 +120,7 @@
bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test(expectedExceptions=IllegalStateException.class)
@@ -134,7 +134,7 @@
bootstrap.getServices().add(Deployment.class, new MockDeployment());
bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test(expectedExceptions=IllegalStateException.class)
@@ -148,7 +148,7 @@
bootstrap.getServices().add(Deployment.class, new MockDeployment());
bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
bootstrap.getServices().add(TransactionServices.class, new
MockTransactionServices());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test
@@ -159,7 +159,7 @@
bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
@Test
@@ -170,7 +170,7 @@
bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.initialize();
+ bootstrap.startContainer();
}
}
Modified:
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
===================================================================
---
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java 2009-08-11
00:03:07 UTC (rev 3425)
+++
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java 2009-08-11
00:09:18 UTC (rev 3426)
@@ -1,28 +1,47 @@
package org.jboss.webbeans.bootstrap.api.test;
+import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
import org.jboss.webbeans.manager.api.WebBeansManager;
public class MockBootstrap extends AbstractBootstrap
{
- public void boot()
- {
-
- }
-
public WebBeansManager getManager()
{
return null;
}
- public void initialize()
+ public Bootstrap startContainer()
{
verify();
+ return this;
}
+
+
public void shutdown()
{
}
+
+ public Bootstrap deployBeans()
+ {
+ return this;
+ }
+
+ public Bootstrap endInitialization()
+ {
+ return this;
+ }
+
+ public Bootstrap startInitialization()
+ {
+ return this;
+ }
+
+ public Bootstrap validateBeans()
+ {
+ return this;
+ }
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java
===================================================================
---
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java 2009-08-11
00:03:07 UTC (rev 3425)
+++
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java 2009-08-11
00:09:18 UTC (rev 3426)
@@ -34,7 +34,7 @@
public void initialize()
{
- bootstrap.initialize();
+ bootstrap.startContainer();
}
public MockDeployment getDeployment()
@@ -49,7 +49,7 @@
public void beginApplication()
{
- bootstrap.boot();
+ bootstrap.startInitialization().deployBeans().validateBeans().endInitialization();
}
public void endApplication()