deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [2/3] git commit: DELTASPIKE-489 AbstractContext#getContextualStorage fixed
Date Thu, 02 Jan 2014 23:41:34 GMT
DELTASPIKE-489 AbstractContext#getContextualStorage fixed


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/9429d0ef
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/9429d0ef
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/9429d0ef

Branch: refs/heads/master
Commit: 9429d0ef0e32afdbe88839ee955b2f638471f771
Parents: fca5cbd
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Jan 3 00:27:14 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Jan 3 00:27:14 2014 +0100

----------------------------------------------------------------------
 .../core/util/context/AbstractContext.java      | 30 +++++++++-----
 .../GroupedConversationContext.java             | 42 +++++---------------
 .../impl/scope/window/WindowContextImpl.java    |  3 +-
 .../core/api/util/context/DummyContext.java     |  3 +-
 .../jsf/impl/scope/view/ViewScopedContext.java  |  2 +-
 5 files changed, 35 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9429d0ef/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/context/AbstractContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/context/AbstractContext.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/context/AbstractContext.java
index 11546ec..1154a78 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/context/AbstractContext.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/context/AbstractContext.java
@@ -25,13 +25,15 @@ import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.PassivationCapable;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
  * A skeleton containing the most important parts of a custom CDI Context.
  * An implementing Context needs to implement the missing methods from the
- * {@link Context} interface and {@link #getContextualStorage(boolean)}.
+ * {@link Context} interface and {@link #getContextualStorage(Contextual, boolean)}.
  */
 public abstract class AbstractContext implements Context
 {
@@ -51,7 +53,14 @@ public abstract class AbstractContext implements Context
      * @param createIfNotExist whether a ContextualStorage shall get created if it doesn't
yet exist.
      * @return the underlying storage
      */
-    protected abstract ContextualStorage getContextualStorage(boolean createIfNotExist);
+    protected abstract ContextualStorage getContextualStorage(Contextual<?> contextual,
boolean createIfNotExist);
+
+    protected List<ContextualStorage> getActiveContextualStorages()
+    {
+        List<ContextualStorage> result = new ArrayList<ContextualStorage>();
+        result.add(getContextualStorage(null, false));
+        return result;
+    }
 
     /**
      * @return whether the served scope is a passivating scope
@@ -66,7 +75,7 @@ public abstract class AbstractContext implements Context
     {
         checkActive();
 
-        ContextualStorage storage = getContextualStorage(false);
+        ContextualStorage storage = getContextualStorage(bean, false);
         if (storage == null)
         {
             return null;
@@ -96,7 +105,7 @@ public abstract class AbstractContext implements Context
             }
         }
 
-        ContextualStorage storage = getContextualStorage(true);
+        ContextualStorage storage = getContextualStorage(bean, true);
 
         Map<Object, ContextualInstanceInfo<?>> contextMap = storage.getStorage();
         ContextualInstanceInfo<?> contextualInstanceInfo = contextMap.get(storage.getBeanKey(bean));
@@ -122,7 +131,7 @@ public abstract class AbstractContext implements Context
      */
     public boolean destroy(Contextual bean)
     {
-        ContextualStorage storage = getContextualStorage(false);
+        ContextualStorage storage = getContextualStorage(bean, false);
         if (storage == null)
         {
             return false;
@@ -142,17 +151,20 @@ public abstract class AbstractContext implements Context
 
     /**
      * destroys all the Contextual Instances in the Storage returned by
-     * {@link #getContextualStorage(boolean)}.
+     * {@link #getContextualStorage(Contextual, boolean)}.
      */
     public void destroyAllActive()
     {
-        ContextualStorage storage = getContextualStorage(false);
-        if (storage == null)
+        List<ContextualStorage> storages = getActiveContextualStorages();
+        if (storages == null)
         {
             return;
         }
 
-        destroyAllActive(storage);
+        for (ContextualStorage storage : storages)
+        {
+            destroyAllActive(storage);
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9429d0ef/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java
index 0724ae4..106a85e 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/conversation/GroupedConversationContext.java
@@ -26,11 +26,12 @@ import org.apache.deltaspike.core.util.context.AbstractContext;
 import org.apache.deltaspike.core.util.context.ContextualStorage;
 
 import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.spi.BeanManager;
 import java.lang.annotation.Annotation;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -41,9 +42,6 @@ public class GroupedConversationContext extends AbstractContext implements
Group
 {
     private static final long serialVersionUID = -5463564406828391468L;
 
-    @Deprecated //TODO remove it once DELTASPIKE-489 is fixed
-    private static ThreadLocal<Contextual<?>> currentContextual = new ThreadLocal<Contextual<?>>();
-
     private final BeanManager beanManager;
 
     private final WindowContextImpl windowContext;
@@ -64,40 +62,18 @@ public class GroupedConversationContext extends AbstractContext implements
Group
     }
 
     @Override
-    public <T> T get(Contextual<T> bean)
-    {
-        try
-        {
-            currentContextual.set(bean);
-            return super.get(bean);
-        }
-        finally
-        {
-            currentContextual.set(null);
-            currentContextual.remove();
-        }
-    }
-
-    @Override
-    public <T> T get(Contextual<T> bean, CreationalContext<T> creationalContext)
+    protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean
createIfNotExist)
     {
-        try
-        {
-            currentContextual.set(bean);
-            return super.get(bean, creationalContext);
-        }
-        finally
-        {
-            currentContextual.set(null);
-            currentContextual.remove();
-        }
+        ConversationKey conversationKey = ConversationUtils.convertToConversationKey(contextual);
+        return this.conversationBeanHolder.getContextualStorage(beanManager, conversationKey,
createIfNotExist);
     }
 
     @Override
-    protected ContextualStorage getContextualStorage(boolean createIfNotExist)
+    protected List<ContextualStorage> getActiveContextualStorages()
     {
-        ConversationKey conversationKey = ConversationUtils.convertToConversationKey(currentContextual.get());
-        return this.conversationBeanHolder.getContextualStorage(beanManager, conversationKey,
createIfNotExist);
+        List<ContextualStorage> result = new ArrayList<ContextualStorage>();
+        result.addAll(this.conversationBeanHolder.getStorageMap().values());
+        return result;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9429d0ef/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextImpl.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextImpl.java
index 10faa7b..e0f8cc6 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextImpl.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextImpl.java
@@ -19,6 +19,7 @@
 package org.apache.deltaspike.core.impl.scope.window;
 
 import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.spi.BeanManager;
 
@@ -97,7 +98,7 @@ public class WindowContextImpl extends AbstractContext implements WindowContext
     }
 
     @Override
-    protected ContextualStorage getContextualStorage(boolean createIfNotExist)
+    protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean
createIfNotExist)
     {
         String windowId = getCurrentWindowId();
         if (windowId == null)

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9429d0ef/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/context/DummyContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/context/DummyContext.java
b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/context/DummyContext.java
index 31efeb7..0074dbb 100644
--- a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/context/DummyContext.java
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/api/util/context/DummyContext.java
@@ -18,6 +18,7 @@
 */
 package org.apache.deltaspike.test.core.api.util.context;
 
+import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.inject.spi.BeanManager;
 import java.lang.annotation.Annotation;
 
@@ -42,7 +43,7 @@ public class DummyContext extends AbstractContext
     }
 
     @Override
-    protected ContextualStorage getContextualStorage(boolean createIfNotExists)
+    protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean
createIfNotExists)
     {
         if (storage == null && createIfNotExists)
         {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9429d0ef/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedContext.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedContext.java
index 042b2c0..45ad0e3 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedContext.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/view/ViewScopedContext.java
@@ -52,7 +52,7 @@ public class ViewScopedContext extends AbstractContext implements SystemEventLis
     }
 
     @Override
-    protected ContextualStorage getContextualStorage(boolean createIfNotExists)
+    protected ContextualStorage getContextualStorage(Contextual<?> contextual, boolean
createIfNotExists)
     {
         Map<String, Object> viewMap = getViewMap();
         ContextualStorage storage = (ContextualStorage) viewMap.get(CONTEXTUAL_MAP_NAME);


Mime
View raw message