Author: nickarls
Date: 2010-04-06 04:25:59 -0400 (Tue, 06 Apr 2010)
New Revision: 6075
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
Log:
Clean up lifecycles (ContextLifecycle, ServletLifecycle, AbstractConversationManager)
Fix broken (until otherwise proven) test
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-01
08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-06
08:25:59 UTC (rev 6075)
@@ -30,6 +30,7 @@
import static org.jboss.weld.logging.messages.ContextMessage.REQUEST_STARTED;
import static org.jboss.weld.logging.messages.ContextMessage.SESSION_ENDED;
import static org.jboss.weld.logging.messages.ContextMessage.SESSION_RESTORED;
+import static org.jboss.weld.logging.messages.ContextMessage.CONVERSATION_RESTORED;
import org.jboss.weld.bootstrap.api.Lifecycle;
import org.jboss.weld.bootstrap.api.Service;
@@ -43,11 +44,21 @@
* destroying all the built in contexts
*
* @author Pete Muir
+ * @author Nicklas Karlsson
*
*/
public class ContextLifecycle implements Lifecycle, Service
{
-
+ /*
+ * Naming conventions:
+ *
+ * "activating a context" = setting a non-null BeanStore and setting active
to true
+ * "deactivating a context" = setting a null BeanStore and setting active to
false
+ * "destroying a context" = activating the context, calling destroy(),
deactivating the context
+ * "restoring a context" = alias for activating the context
+ *
+ */
+
private static final LocLogger log = loggerFactory().getLogger(CONTEXT);
private final AbstractApplicationContext applicationContext;
@@ -67,36 +78,36 @@
this.dependentContext = dependentContext;
}
- public void restoreSession(String id, BeanStore sessionBeanStore)
+ public AbstractApplicationContext getApplicationContext()
{
- log.trace(SESSION_RESTORED, id);
- setupContext(sessionContext, sessionBeanStore);
+ return applicationContext;
}
- public void endSession(String id, BeanStore sessionBeanStore)
+ public AbstractApplicationContext getSingletonContext()
{
- log.trace(SESSION_ENDED, id);
- teardownContext(sessionContext);
+ return singletonContext;
}
- public void beginRequest(String id, BeanStore requestBeanStore)
+ public SessionContext getSessionContext()
{
- log.trace(REQUEST_STARTED, id);
- dependentContext.setActive(true);
- setupContext(requestContext, requestBeanStore);
- setupConversationContext();
+ return sessionContext;
}
- public void endRequest(String id, BeanStore requestBeanStore)
+ public ConversationContext getConversationContext()
{
- log.trace(REQUEST_ENDED, id);
- requestContext.setBeanStore(requestBeanStore);
- dependentContext.setActive(false);
- teardownContext(requestContext);
- conversationContext.setBeanStore(null);
- conversationContext.setActive(false);
+ return conversationContext;
}
+ public RequestContext getRequestContext()
+ {
+ return requestContext;
+ }
+
+ public DependentContext getDependentContext()
+ {
+ return dependentContext;
+ }
+
public boolean isRequestActive()
{
return singletonContext.isActive() && applicationContext.isActive()
&& requestContext.isActive() && dependentContext.isActive();
@@ -117,100 +128,216 @@
return singletonContext.isActive() && applicationContext.isActive()
&& sessionContext.isActive() && dependentContext.isActive();
}
+ public void cleanup()
+ {
+ dependentContext.cleanup();
+ requestContext.cleanup();
+ conversationContext.cleanup();
+ sessionContext.cleanup();
+ singletonContext.cleanup();
+ applicationContext.cleanup();
+ }
+
public void beginApplication(BeanStore applicationBeanStore)
{
log.trace(APPLICATION_STARTED, "");
- setupContext(applicationContext, applicationBeanStore);
- setupContext(singletonContext, new ConcurrentHashMapBeanStore());
+ activateApplicationContext(applicationBeanStore);
+ activateSingletonContext();
}
+ private void activateApplicationContext(BeanStore applicationBeanStore)
+ {
+ activateContext(applicationContext, applicationBeanStore);
+ }
+
+ private void activateContext(AbstractApplicationContext context, BeanStore beanStore)
+ {
+ if (beanStore == null)
+ {
+ throw new IllegalArgumentException("null bean store for " + context);
+ }
+ context.setBeanStore(beanStore);
+ context.setActive(true);
+ }
+
+ private void activateSingletonContext()
+ {
+ activateContext(singletonContext, new ConcurrentHashMapBeanStore());
+ }
+
+ public void beginRequest(String id, BeanStore requestBeanStore)
+ {
+ log.trace(REQUEST_STARTED, id);
+ activateDependentContext();
+ activateRequestContext(requestBeanStore);
+ activateConversationContext();
+ activateSessionContext();
+ }
+
+ private void activateDependentContext()
+ {
+ dependentContext.setActive(true);
+ }
+
+ private void activateRequestContext(BeanStore requestBeanStore)
+ {
+ activateContext(requestContext, requestBeanStore);
+ }
+
+ private void activateContext(AbstractThreadLocalMapContext context, BeanStore
beanStore)
+ {
+ if (beanStore == null)
+ {
+ throw new IllegalArgumentException("null bean store for " + context);
+ }
+ context.setBeanStore(beanStore);
+ context.setActive(true);
+ }
+
+ private void activateConversationContext()
+ {
+ activateContext(conversationContext, new ConcurrentHashMapBeanStore());
+ }
+
+ private void activateSessionContext()
+ {
+ activateContext(sessionContext, new ConcurrentHashMapBeanStore());
+ }
+
public void endApplication()
{
log.trace(APPLICATION_ENDED, "");
- teardownContext(applicationContext);
- teardownContext(singletonContext);
+ destroyApplicationContext();
+ destroySingletonContext();
}
- public void cleanup()
+ private void destroyApplicationContext()
{
- dependentContext.cleanup();
- requestContext.cleanup();
- conversationContext.cleanup();
- sessionContext.cleanup();
- singletonContext.cleanup();
- applicationContext.cleanup();
+ destroyContext(applicationContext);
}
- public AbstractApplicationContext getApplicationContext()
+ private void destroyContext(AbstractApplicationContext context)
{
- return applicationContext;
+ if (context.getBeanStore() == null)
+ {
+ return;
+ }
+ activateContext(context, context.getBeanStore());
+ context.destroy();
+ deactivateContext(context);
}
- public AbstractApplicationContext getSingletonContext()
+ private void deactivateContext(AbstractApplicationContext context)
{
- return singletonContext;
+ context.setBeanStore(null);
+ context.setActive(false);
}
- public SessionContext getSessionContext()
+ private void destroySingletonContext()
{
- return sessionContext;
+ destroyContext(singletonContext);
}
- public ConversationContext getConversationContext()
+ public void endRequest(String id, BeanStore requestBeanStore)
{
- return conversationContext;
+ log.trace(REQUEST_ENDED, id);
+ deactivateDependentContext();
+ destroyRequestContext(requestBeanStore);
+ deactivateConversationContext();
+ deactivateSessionContext();
}
- public RequestContext getRequestContext()
+ private void deactivateDependentContext()
{
- return requestContext;
+ dependentContext.setActive(false);
}
- public DependentContext getDependentContext()
+ private void destroyRequestContext(BeanStore requestBeanStore)
{
- return dependentContext;
+ destroyContext(requestContext, requestBeanStore);
}
- public void setupConversationContext()
+ private void deactivateConversationContext()
{
- setupContext(conversationContext, new HashMapBeanStore());
+ deactivateContext(conversationContext);
}
- public void teardownConversationContext()
+ public void deactivateSessionContext()
{
- teardownContext(conversationContext);
+ deactivateContext(sessionContext);
}
- private void setupContext(AbstractThreadLocalMapContext context, BeanStore beanStore)
+ public void endSession(String id, BeanStore sessionBeanStore)
{
- context.setBeanStore(beanStore);
- context.setActive(true);
+ log.trace(SESSION_ENDED, id);
+ destroyConversationContext();
+ destroySessionContext(sessionBeanStore);
}
- private void setupContext(AbstractApplicationContext context, BeanStore beanStore)
+ private void destroyConversationContext()
{
- context.setBeanStore(beanStore);
- context.setActive(true);
+ destroyContext(conversationContext, conversationContext.getBeanStore());
}
-
- private void teardownContext(AbstractThreadLocalMapContext context)
+
+ private void destroySessionContext(BeanStore sessionBeanStore)
{
- if (context.getBeanStore() == null)
- {
- return;
- }
- context.setActive(true);
+ destroyContext(sessionContext, sessionBeanStore);
+ }
+
+ private void destroyContext(AbstractThreadLocalMapContext context, BeanStore
beanStore)
+ {
+ activateContext(context, beanStore);
context.destroy();
- context.setBeanStore(null);
- context.setActive(false);
+ deactivateContext(context);
}
-
- private void teardownContext(AbstractApplicationContext context)
+
+ private void deactivateContext(AbstractThreadLocalMapContext context)
{
- context.setActive(true);
- context.destroy();
context.setBeanStore(null);
context.setActive(false);
- }
+ }
-}
+ public void restoreSession(String id, BeanStore sessionBeanStore)
+ {
+ log.trace(SESSION_RESTORED, id);
+ activateSessionContext(sessionBeanStore);
+ }
+
+ private void activateSessionContext(BeanStore sessionBeanStore)
+ {
+ activateContext(sessionContext, sessionBeanStore);
+ }
+
+ public void restoreConversation(String id, BeanStore conversationBeanStore)
+ {
+ log.trace(CONVERSATION_RESTORED, id);
+ activateConversationContext(new HashMapBeanStore());
+ conversationContext.loadTransientBeanStore(conversationBeanStore);
+ }
+
+ private void activateConversationContext(BeanStore conversationBeanStore)
+ {
+ activateContext(conversationContext, conversationBeanStore);
+ }
+
+ public void setupConversationContext()
+ {
+ activateConversationContext();
+ }
+
+ public void teardownConversationContext()
+ {
+ destroyConversationContext();
+ }
+
+ public boolean isSessionContextActive()
+ {
+ return sessionContext.isActive();
+ }
+
+ public boolean isRequestContextActive()
+ {
+ return requestContext.isActive();
+ }
+
+}
\ No newline at end of file
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java 2010-04-01
08:18:22 UTC (rev 6074)
+++
core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java 2010-04-06
08:25:59 UTC (rev 6075)
@@ -167,7 +167,7 @@
}
String oldConversation = conversation.toString();
conversation.switchTo(resumedManagedConversation.getConversation());
- getConversationContext().loadTransientBeanStore(getBeanStore(cid));
+ getContextLifeCycle().restoreConversation(cid, getBeanStore(cid));
log.trace(CONVERSATION_SWITCHED, oldConversation, conversation);
return this;
}
@@ -297,17 +297,22 @@
public ConversationManager2 setupContext()
{
-
Container.instance().services().get(ContextLifecycle.class).setupConversationContext();
+ getContextLifeCycle().setupConversationContext();
return this;
}
public ConversationManager2 teardownContext()
{
-
Container.instance().services().get(ContextLifecycle.class).teardownConversationContext();
+ getContextLifeCycle().teardownConversationContext();
destroyBackgroundConversations();
return this;
}
+ private ContextLifecycle getContextLifeCycle()
+ {
+ return Container.instance().services().get(ContextLifecycle.class);
+ }
+
public String generateConversationId()
{
return conversationIdGenerator.nextId();
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java 2010-04-01
08:18:22 UTC (rev 6074)
+++
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java 2010-04-06
08:25:59 UTC (rev 6075)
@@ -47,6 +47,7 @@
@MessageId("000210") DEPENDENT_INSTANCE_ATTACHED,
@MessageId("000211") DELIMITER_IN_PREFIX,
@MessageId("000212") CONTEXTUAL_IS_NULL,
- @MessageId("000213") NO_BEAN_STORE_AVAILABLE;
+ @MessageId("000213") NO_BEAN_STORE_AVAILABLE,
+ @MessageId("000214") CONVERSATION_RESTORED;
}
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java
===================================================================
---
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java 2010-04-01
08:18:22 UTC (rev 6074)
+++
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java 2010-04-06
08:25:59 UTC (rev 6075)
@@ -30,7 +30,7 @@
{
private final HttpServletRequest request;
- public HttpPassThruOnDemandSessionBeanStore(HttpServletRequest request)
+ protected HttpPassThruOnDemandSessionBeanStore(HttpServletRequest request)
{
this.request = request;
if (request.getSession(false) != null)
@@ -48,4 +48,9 @@
}
super.setAttribute(key, instance);
}
+
+ public static HttpPassThruSessionBeanStore of(HttpServletRequest request)
+ {
+ return new HttpPassThruOnDemandSessionBeanStore(request);
+ }
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-01
08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-06
08:25:59 UTC (rev 6075)
@@ -38,7 +38,8 @@
/**
* Implementation of the Weld lifecycle that can react to servlet events and
- * drives the Session, Conversation and Request (for Servlet requests) lifecycle
+ * drives the Servlet based lifecycles of the Session, Conversation and Request
+ * contexts
*
* @author Pete Muir
* @author Nicklas Karlsson
@@ -46,12 +47,33 @@
*/
public class ServletLifecycle
{
-
private final ContextLifecycle lifecycle;
- public static final String REQUEST_ATTRIBUTE_NAME = ServletLifecycle.class.getName() +
".requestBeanStore";
+ private static class RequestBeanStoreCache
+ {
+ private static final String REQUEST_ATTRIBUTE_NAME =
ServletLifecycle.class.getName() + ".requestBeanStore";
+ public static void clear(HttpServletRequest request)
+ {
+ request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
+ }
+ public static BeanStore get(HttpServletRequest request)
+ {
+ return (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
+ }
+
+ public static void set(HttpServletRequest request, BeanStore requestBeanStore)
+ {
+ request.setAttribute(REQUEST_ATTRIBUTE_NAME, requestBeanStore);
+ }
+
+ public static boolean isSet(HttpServletRequest request)
+ {
+ return get(request) != null;
+ }
+ }
+
/**
* Constructor
*
@@ -63,65 +85,23 @@
}
/**
- * Begins a session
+ * Begins a HTTP request. Sets the session into the session context
*
- * @param session The HTTP session
+ * @param request The request
*/
- public void beginSession(HttpSession session)
+ public void beginRequest(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore beanStore = (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
- if (beanStore == null)
+ if (!RequestBeanStoreCache.isSet(request))
{
- restoreSessionContext(session);
+ BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+ RequestBeanStoreCache.set(request, requestBeanStore);
+ lifecycle.beginRequest(request.getRequestURI(), requestBeanStore);
+ restoreSessionContext(request);
+ restoreConversationContext(request);
}
- else
- {
- beanStore.attachToSession(session);
- }
}
/**
- * Ends a session, setting up a mock request if necessary
- *
- * @param session The HTTP session
- */
- public void endSession(HttpSession session)
- {
- ServletConversationManager conversationManager = (ServletConversationManager)
conversationManager(session.getServletContext());
- if (lifecycle.getSessionContext().isActive())
- {
- HttpPassThruSessionBeanStore beanStore = (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
- if (lifecycle.getRequestContext().isActive())
- {
- // Probably invalidated during request. This will be terminated
- // at the end of the request.
- beanStore.invalidate();
- conversationManager.invalidateSession();
- }
- else
- {
- lifecycle.endSession(session.getId(), beanStore);
- }
- }
- else if (lifecycle.getRequestContext().isActive())
- {
- BeanStore store = restoreSessionContext(session);
- conversationManager.destroyBackgroundConversations();
- lifecycle.endSession(session.getId(), store);
- }
- else
- {
- BeanStore mockRequest = new ConcurrentHashMapBeanStore();
-
- lifecycle.beginRequest("endSession-" + session.getId(), mockRequest);
- BeanStore sessionBeanStore = restoreSessionContext(session);
- lifecycle.endSession(session.getId(), sessionBeanStore);
- lifecycle.endRequest("endSession-" + session.getId(), mockRequest);
- }
-
- }
-
- /**
* Restore the session from the underlying session object. Also allow the
* session to be injected by the Session manager
*
@@ -130,9 +110,10 @@
*/
protected BeanStore restoreSessionContext(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore sessionBeanStore = new
HttpPassThruOnDemandSessionBeanStore(request);
+ HttpPassThruSessionBeanStore sessionBeanStore =
HttpPassThruOnDemandSessionBeanStore.of(request);
HttpSession session = request.getSession(true);
- lifecycle.restoreSession(session == null ? "Inactive session" :
session.getId(), sessionBeanStore);
+ String sessionId = session == null ? "Inactive session" :
session.getId();
+ lifecycle.restoreSession(sessionId, sessionBeanStore);
if (session != null)
{
sessionBeanStore.attachToSession(session);
@@ -141,32 +122,50 @@
return sessionBeanStore;
}
- protected BeanStore restoreSessionContext(HttpSession session)
+ private void restoreConversationContext(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore beanStore = new HttpPassThruSessionBeanStore();
- beanStore.attachToSession(session);
- lifecycle.restoreSession(session.getId(), beanStore);
- httpSessionManager(session.getServletContext()).setSession(session);
- return beanStore;
+ // FIXME: HC "cid"
+
conversationManager(request.getSession().getServletContext()).setupConversation(request.getParameter("cid"));
}
/**
- * Begins a HTTP request. Sets the session into the session context
+ * Begins a session
*
- * @param request The request
+ * @param session The HTTP session
*/
- public void beginRequest(HttpServletRequest request)
+ public void beginSession(HttpSession session)
{
- if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) == null)
+ HttpPassThruSessionBeanStore beanStore = getSessionBeanStore();
+ if (beanStore == null)
{
- BeanStore beanStore = new ConcurrentHashMapBeanStore();
- request.setAttribute(REQUEST_ATTRIBUTE_NAME, beanStore);
- lifecycle.beginRequest(request.getRequestURI(), beanStore);
- restoreSessionContext(request);
-
conversationManager(request.getSession().getServletContext()).setupConversation(request.getParameter("cid"));
+ restoreSessionContext(session);
}
+ else
+ {
+ beanStore.attachToSession(session);
+ }
}
+ private HttpPassThruSessionBeanStore getSessionBeanStore()
+ {
+ return (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
+ }
+
+ protected BeanStore restoreSessionContext(HttpSession session)
+ {
+ String sessionId = session.getId();
+ HttpPassThruSessionBeanStore beanStore = new HttpPassThruSessionBeanStore();
+ beanStore.attachToSession(session);
+ lifecycle.restoreSession(sessionId, beanStore);
+ cacheSession(session);
+ return beanStore;
+ }
+
+ private void cacheSession(HttpSession session)
+ {
+ httpSessionManager(session.getServletContext()).setSession(session);
+ }
+
/**
* Ends a HTTP request
*
@@ -174,40 +173,111 @@
*/
public void endRequest(HttpServletRequest request)
{
- if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) == null)
+ if (!RequestBeanStoreCache.isSet(request))
{
return;
}
- HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
- conversationManager(sessionBeanStore.getServletContext()).teardownConversation();
teardownRequest(request);
- lifecycle.getConversationContext().setBeanStore(null);
- lifecycle.getConversationContext().setActive(false);
+ teardownConversation();
teardownSession(request);
}
-
+
+ private void teardownRequest(HttpServletRequest request)
+ {
+ BeanStore beanStore = RequestBeanStoreCache.get(request);
+ if (beanStore == null)
+ {
+ throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
+ }
+ lifecycle.endRequest(request.getRequestURI(), beanStore);
+ RequestBeanStoreCache.clear(request);
+ }
+
+ private void teardownConversation()
+ {
+ conversationManager(getServletContext()).teardownConversation();
+ }
+
+ private ServletContext getServletContext()
+ {
+ return getSessionBeanStore().getServletContext();
+ }
+
private void teardownSession(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore)
lifecycle.getSessionContext().getBeanStore();
- if ((sessionBeanStore != null) && (sessionBeanStore.isInvalidated()))
+ HttpPassThruSessionBeanStore sessionBeanStore = getSessionBeanStore();
+ if (isSessionBeanStoreInvalid(sessionBeanStore))
{
- conversationManager(sessionBeanStore.getServletContext()).teardownContext();
+ conversationManager(getServletContext()).teardownContext();
lifecycle.endSession(request.getRequestedSessionId(), sessionBeanStore);
}
- lifecycle.getSessionContext().setActive(false);
- lifecycle.getSessionContext().setBeanStore(null);
-
+ lifecycle.deactivateSessionContext();
}
-
- private void teardownRequest(HttpServletRequest request)
+
+ private boolean isSessionBeanStoreInvalid(HttpPassThruSessionBeanStore
sessionBeanStore)
{
- BeanStore beanStore = (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
- if (beanStore == null)
+ return sessionBeanStore != null && sessionBeanStore.isInvalidated();
+ }
+
+ /**
+ * Ends a session, setting up a mock request if necessary
+ *
+ * @param session The HTTP session
+ */
+ public void endSession(HttpSession session)
+ {
+ if (lifecycle.isSessionContextActive())
{
- throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
+ activeSessionTermination(session);
}
- lifecycle.endRequest(request.getRequestURI(), beanStore);
- request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
+ else if (lifecycle.isRequestContextActive())
+ {
+ activeRequestTermination(session);
+ }
+ else
+ {
+ mockedSessionTermination(session);
+ }
}
+ private void activeRequestTermination(HttpSession session)
+ {
+ String sessionId = session.getId();
+ BeanStore store = restoreSessionContext(session);
+ getServletConversationManager().destroyBackgroundConversations();
+ lifecycle.endSession(sessionId, store);
+ }
+
+ private ServletConversationManager getServletConversationManager()
+ {
+ return (ServletConversationManager) conversationManager(getServletContext());
+ }
+
+ private void activeSessionTermination(HttpSession session)
+ {
+ String sessionId = session.getId();
+ HttpPassThruSessionBeanStore beanStore = getSessionBeanStore();
+ if (lifecycle.isRequestContextActive())
+ {
+ // Probably invalidated during request. This will be terminated
+ // at the end of the request.
+ beanStore.invalidate();
+ getServletConversationManager().invalidateSession();
+ }
+ else
+ {
+ lifecycle.endSession(sessionId, beanStore);
+ }
+ }
+
+ private void mockedSessionTermination(HttpSession session)
+ {
+ String sessionId = session.getId();
+ BeanStore mockRequest = new ConcurrentHashMapBeanStore();
+ lifecycle.beginRequest("endSession-" + sessionId, mockRequest);
+ BeanStore sessionBeanStore = restoreSessionContext(session);
+ lifecycle.endSession(session.getId(), sessionBeanStore);
+ lifecycle.endRequest("endSession-" + sessionId, mockRequest);
+ }
+
}
Modified:
core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties
===================================================================
---
core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties 2010-04-01
08:18:22 UTC (rev 6074)
+++
core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties 2010-04-06
08:25:59 UTC (rev 6075)
@@ -11,4 +11,5 @@
DEPENDENT_INSTANCE_ATTACHED=Attached dependent instance {0} to {1}
DELIMITER_IN_PREFIX=The delimiter \\"{0}\\" should not be in the prefix
\\"{1}\\"
CONTEXTUAL_IS_NULL=No contextual specified to retrieve (null)
-NO_BEAN_STORE_AVAILABLE=No bean store available for {0}
+NO_BEAN_STORE_AVAILABLE=No bean store available for {0}
+CONVERSATION_RESTORED=Restoring conversation {0}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2010-04-01
08:18:22 UTC (rev 6074)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2010-04-06
08:25:59 UTC (rev 6075)
@@ -64,9 +64,9 @@
newRequest();
assert tempConsumer.getSpecialTemp().getNumber() == 10;
- assert tempConsumer.getUselessTemp().getNumber() == 102;
+ assert tempConsumer.getUselessTemp().getNumber() == 11;
assert getReference(specialTempBean).getNumber() == 10;
- assert getReference(uselessTempBean).getNumber() == 102;
+ assert getReference(uselessTempBean).getNumber() == 11;
}
private void newRequest()