[weld-commits] Weld SVN: r4660 - in core/trunk: impl/src/main/java/org/jboss/weld/bootstrap and 2 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Wed Nov 4 12:35:19 EST 2009
Author: pete.muir at jboss.org
Date: 2009-11-04 12:35:19 -0500 (Wed, 04 Nov 2009)
New Revision: 4660
Added:
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/bootstrap/ContainerStatusTest.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/Container.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/WeldListener.java
Log:
WELD-256
Modified: core/trunk/impl/src/main/java/org/jboss/weld/Container.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/Container.java 2009-11-04 16:47:06 UTC (rev 4659)
+++ core/trunk/impl/src/main/java/org/jboss/weld/Container.java 2009-11-04 17:35:19 UTC (rev 4660)
@@ -35,6 +35,52 @@
public class Container
{
+ /**
+ * Container status
+ * @author pmuir
+ *
+ */
+ public enum Status
+ {
+ /**
+ * The container has not been started
+ */
+ STOPPED(false),
+ /**
+ * The container is starting
+ */
+ STARTING(false),
+ /**
+ * The container has started and beans have been deployed
+ */
+ INITIALIZED(true),
+ /**
+ * The deployment has been validated
+ */
+ VALIDATED(true),
+ /**
+ * The container has been shutdown
+ */
+ SHUTDOWN(false);
+
+ private Status(boolean available)
+ {
+ this.available = available;
+ }
+
+ final boolean available;
+
+ /**
+ * Whether the container is available for use
+ *
+ * @return
+ */
+ public boolean isAvailable()
+ {
+ return available;
+ }
+ }
+
private final static Singleton<Container> instance;
static
@@ -52,6 +98,11 @@
return instance.get();
}
+ public static boolean available()
+ {
+ return instance.isSet() && instance() != null && instance().getStatus().isAvailable();
+ }
+
/**
* Initialize the container for the current application deployment
@@ -76,7 +127,7 @@
private final ServiceRegistry deploymentServices;
- private boolean initialized = false;
+ private Status status = Status.STOPPED;
public Container(BeanManagerImpl deploymentManager, ServiceRegistry deploymentServices)
{
@@ -171,24 +222,14 @@
}
}
- /**
- * Check if the application container is fully initialized
- *
- * @return the initialized
- */
- public boolean isInitialized()
+ public Status getStatus()
{
- return initialized;
+ return status;
}
- /**
- * Put the application container into an initialized state
- *
- * @param initialized the initialized to set
- */
- public void setInitialized(boolean initialized)
+ public void setStatus(Status status)
{
- this.initialized = initialized;
+ this.status = status;
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2009-11-04 16:47:06 UTC (rev 4659)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2009-11-04 17:35:19 UTC (rev 4660)
@@ -37,6 +37,7 @@
import org.jboss.weld.Container;
import org.jboss.weld.ContextualStoreImpl;
import org.jboss.weld.Validator;
+import org.jboss.weld.Container.Status;
import org.jboss.weld.bean.builtin.ManagerBean;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.api.Environment;
@@ -279,6 +280,7 @@
this.deploymentManager = BeanManagerImpl.newRootManager("deployment", deploymentServices);
Container.initialize(deploymentManager, ServiceRegistries.unmodifiableServiceRegistry(deployment.getServices()));
+ Container.instance().setStatus(Status.STARTING);
createContexts();
initializeContexts();
@@ -371,7 +373,8 @@
}
// Re-read the deployment structure, this will be the physical structure, extensions, classes, and any beans added using addBean outside the physical structure
beanDeployments = deploymentVisitor.visit();
- log.debug(VALIDATING_BEANS);
+ Container.instance().putBeanDeployments(beanDeployments);
+ Container.instance().setStatus(Status.INITIALIZED);
}
return this;
}
@@ -380,6 +383,7 @@
{
synchronized (this)
{
+ log.debug(VALIDATING_BEANS);
for (Entry<BeanDeploymentArchive, BeanDeployment> entry : beanDeployments.entrySet())
{
deployment.getServices().get(Validator.class).validateDeployment(entry.getValue().getBeanManager(), entry.getValue().getBeanDeployer().getEnvironment());
@@ -399,8 +403,7 @@
synchronized (this)
{
// Register the managers so external requests can handle them
- Container.instance().putBeanDeployments(beanDeployments);
- Container.instance().setInitialized(true);
+ Container.instance().setStatus(Status.VALIDATED);
}
return this;
}
@@ -436,6 +439,7 @@
}
finally
{
+ Container.instance().setStatus(Status.SHUTDOWN);
Container.instance().deploymentServices().get(ContextLifecycle.class).endApplication();
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/WeldListener.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/WeldListener.java 2009-11-04 16:47:06 UTC (rev 4659)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/WeldListener.java 2009-11-04 17:35:19 UTC (rev 4660)
@@ -86,7 +86,7 @@
public void contextInitialized(ServletContextEvent sce)
{
super.contextInitialized(sce);
- if (!Container.instance().isInitialized())
+ if (!Container.available())
{
log.warn(NOT_STARTING);
return;
@@ -114,7 +114,7 @@
public void sessionCreated(HttpSessionEvent event)
{
// JBoss AS will still start the deployment even if WB fails
- if (Container.instance() != null && Container.instance().isInitialized())
+ if (Container.available())
{
getLifecycle().beginSession(event.getSession());
}
@@ -129,7 +129,7 @@
public void sessionDestroyed(HttpSessionEvent event)
{
// JBoss AS will still start the deployment even if WB fails
- if (Container.instance() != null && Container.instance().isInitialized())
+ if (Container.available())
{
getLifecycle().endSession(event.getSession());
}
@@ -144,7 +144,7 @@
public void requestDestroyed(ServletRequestEvent event)
{
// JBoss AS will still start the deployment even if WB fails
- if (Container.instance() != null && Container.instance().isInitialized())
+ if (Container.available())
{
if (event.getServletRequest() instanceof HttpServletRequest)
{
@@ -166,7 +166,7 @@
public void requestInitialized(ServletRequestEvent event)
{
// JBoss AS will still start the deployment even if WB fails
- if (Container.instance() != null && Container.instance().isInitialized())
+ if (Container.available())
{
if (event.getServletRequest() instanceof HttpServletRequest)
{
Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/bootstrap/ContainerStatusTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/bootstrap/ContainerStatusTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/bootstrap/ContainerStatusTest.java 2009-11-04 17:35:19 UTC (rev 4660)
@@ -0,0 +1,34 @@
+package org.jboss.weld.test.unit.bootstrap;
+
+import org.jboss.weld.Container;
+import org.jboss.weld.Container.Status;
+import org.jboss.weld.mock.MockServletLifecycle;
+import org.jboss.weld.mock.TestContainer;
+import org.testng.annotations.Test;
+
+public class ContainerStatusTest
+{
+
+ @Test
+ public void testStatus()
+ {
+ TestContainer container = new TestContainer(new MockServletLifecycle());
+ assert !Container.available();
+ container.getLifecycle().initialize();
+ assert !Container.available();
+ assert Container.instance().getStatus().equals(Status.STARTING);
+ container.getLifecycle().getBootstrap().startInitialization();
+ assert !Container.available();
+ assert Container.instance().getStatus().equals(Status.STARTING);
+ container.getLifecycle().getBootstrap().deployBeans();
+ assert Container.available();
+ assert Container.instance().getStatus().equals(Status.INITIALIZED);
+ container.getLifecycle().getBootstrap().validateBeans().endInitialization();
+ assert Container.available();
+ assert Container.instance().getStatus().equals(Status.VALIDATED);
+ container.stopContainer();
+ assert !Container.available();
+ assert Container.instance().getStatus().equals(Status.SHUTDOWN);
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/bootstrap/ContainerStatusTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the weld-commits
mailing list