Repository: deltaspike Updated Branches: refs/heads/master 499c58154 -> 552891f58
DELTASPIKE-1199 WeldContextControl should not stop App context during shutdown method call. Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/552891f5 Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/552891f5 Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/552891f5 Branch: refs/heads/master Commit: 552891f58e4359c884d4b67def72cbc68430d224 Parents: 499c581 Author: Matej Novotny <[email protected]> Authored: Wed Aug 31 12:04:13 2016 +0200 Committer: Matej Novotny <[email protected]> Committed: Wed Aug 31 12:04:13 2016 +0200 ---------------------------------------------------------------------- .../cdise/weld/WeldContainerControl.java | 9 ++++++++- .../cdise/weld/WeldContextControl.java | 21 +++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltaspike/blob/552891f5/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java ---------------------------------------------------------------------- diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java index 92818a3..ac114f3 100644 --- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java +++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContainerControl.java @@ -33,6 +33,10 @@ import java.util.Map; import java.util.Set; import java.util.logging.Logger; +import javax.enterprise.context.ConversationScoped; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.context.SessionScoped; + /** * Weld specific implementation of {@link org.apache.deltaspike.cdise.api.CdiContainer}. */ @@ -83,7 +87,10 @@ public class WeldContainerControl implements CdiContainer { try { - ctxCtrl.stopContexts(); + // stops all built-in contexts except for ApplicationScoped as that one is handled by Weld + ctxCtrl.stopContext(ConversationScoped.class); + ctxCtrl.stopContext(RequestScoped.class); + ctxCtrl.stopContext(SessionScoped.class); ctxCtrlBean.destroy(ctxCtrl, ctxCtrlCreationalContext); } catch (Exception e) http://git-wip-us.apache.org/repos/asf/deltaspike/blob/552891f5/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContextControl.java ---------------------------------------------------------------------- diff --git a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContextControl.java b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContextControl.java index e1ef95f..bbe0292 100644 --- a/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContextControl.java +++ b/deltaspike/cdictrl/impl-weld/src/main/java/org/apache/deltaspike/cdise/weld/WeldContextControl.java @@ -94,7 +94,10 @@ public class WeldContextControl implements ContextControl } /** - * Currently we can't stop the {@link ApplicationScoped} due to WELD-1072 + * Stops Conversation, Request and Session contexts. + * Does NOT stop Application context, only invalidates + * App scoped beans, as in Weld this context always active and clears + * automatically on shutdown. * * {@inheritDoc} */ @@ -104,7 +107,7 @@ public class WeldContextControl implements ContextControl stopConversationScope(); stopRequestScope(); stopSessionScope(); - stopApplicationScope(); //can't be done because of WELD-1072 + stopApplicationScope(); } @Override @@ -129,21 +132,25 @@ public class WeldContextControl implements ContextControl } /* - * start scopes + * This is a no-op method. In Weld Application Context is active as soon as the container starts */ private void startApplicationScope() { - // Welds ApplicationContext is always active - // No need to attach any ThreadLocals... + // No-op, in Weld Application context is always active } + /** + * Weld Application context is active from container start to its shutdown + * This method merely clears out all ApplicationScoped beans BUT the context + * will still be active which may result in immediate re-creation of some beans. + */ private void stopApplicationScope() { // Welds ApplicationContext gets cleaned at shutdown. - //X TODO if we really drop the context then we might trash EE - //X if we do not do it then we loose the ability to cleanup ApplicationScoped beans + // Weld App context should be always active if (applicationContext.isActive()) { + // destroys the bean instances, but the context stays active applicationContext.invalidate(); //needed for weld < v1.1.9
