deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-484 fixed handling of contextual-storages
Date Thu, 02 Jan 2014 19:20:59 GMT
Updated Branches:
  refs/heads/master eced5f1e6 -> 48811a587


DELTASPIKE-484 fixed handling of contextual-storages


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

Branch: refs/heads/master
Commit: 48811a5871ce0123a2592ad473368b7753e679dd
Parents: eced5f1
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Jan 2 20:16:26 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Jan 2 20:20:36 2014 +0100

----------------------------------------------------------------------
 .../impl/scope/window/WindowBeanHolder.java     | 29 ++++++++++++--------
 .../impl/scope/window/WindowContextImpl.java    | 11 ++------
 2 files changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/48811a58/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowBeanHolder.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowBeanHolder.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowBeanHolder.java
index 429fa20..a94966f 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowBeanHolder.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowBeanHolder.java
@@ -36,6 +36,8 @@ import org.apache.deltaspike.core.util.context.ContextualStorage;
 @SessionScoped
 public class WindowBeanHolder implements Serializable
 {
+    private static final long serialVersionUID = 6313493410718133308L;
+
     /**
      * key: the windowId for the browser tab or window
      * value: the {@link ContextualStorage} which holds all the
@@ -46,27 +48,32 @@ public class WindowBeanHolder implements Serializable
     /**
      * This method will return the ContextualStorage or create a new one
      * if no one is yet assigned to the current windowId.
-     * @param beanManager we need the CDI {@link BeanManager} for serialisation.
+     * @param beanManager we need the CDI {@link javax.enterprise.inject.spi.BeanManager}
for serialisation.
      * @param windowId the windowId for the current browser tab or window.
+     * @param createIfNotExist true if a new storage should get created (if it doesn't exist
already), false otherwise
      */
-    public ContextualStorage getContextualStorage(BeanManager beanManager, String windowId)
+    public ContextualStorage getContextualStorage(BeanManager beanManager, String windowId,
boolean createIfNotExist)
     {
         ContextualStorage contextualStorage = storageMap.get(windowId);
-        if (contextualStorage == null)
+        if (contextualStorage == null && createIfNotExist)
         {
-            synchronized (this)
-            {
-                contextualStorage = storageMap.get(windowId);
-                if (contextualStorage == null)
-                {
-                    storageMap.put(windowId, new ContextualStorage(beanManager, true, true));
-                }
-            }
+            contextualStorage = createContextualStorage(beanManager, windowId);
         }
 
         return contextualStorage;
     }
 
+    private synchronized ContextualStorage createContextualStorage(BeanManager beanManager,
String windowId)
+    {
+        ContextualStorage contextualStorage = storageMap.get(windowId);
+        if (contextualStorage == null)
+        {
+            contextualStorage = new ContextualStorage(beanManager, true, true);
+            storageMap.put(windowId, contextualStorage);
+        }
+        return contextualStorage;
+    }
+
     public Map<String, ContextualStorage> getStorageMap()
     {
         return storageMap;

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/48811a58/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 ebda229..ce63708 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
@@ -92,13 +92,8 @@ public class WindowContextImpl extends AbstractContext implements WindowContext
             return false;
         }
 
-        ContextualStorage windowStorage = windowBeanHolder.getContextualStorage(beanManager,
windowId);
-        if (windowStorage == null)
-        {
-            return false;
-        }
-
-        return true;
+        ContextualStorage windowStorage = windowBeanHolder.getContextualStorage(beanManager,
windowId, false);
+        return windowStorage != null;
     }
 
     @Override
@@ -110,7 +105,7 @@ public class WindowContextImpl extends AbstractContext implements WindowContext
             throw new ContextNotActiveException("WindowContext: no windowId set for the current
Thread yet!");
         }
 
-        return windowBeanHolder.getContextualStorage(beanManager, windowId);
+        return windowBeanHolder.getContextualStorage(beanManager, windowId, createIfNotExist);
     }
 
     @Override


Mime
View raw message