deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-544 ViewAccessContextManager (first draft)
Date Sat, 25 Oct 2014 10:18:39 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 785ba0ad9 -> f7e4ff47a


DELTASPIKE-544 ViewAccessContextManager (first draft)


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

Branch: refs/heads/master
Commit: f7e4ff47ae288a1a3fcfbbfe0fa651efa485289f
Parents: 785ba0a
Author: gpetracek <gpetracek@apache.org>
Authored: Sat Oct 25 12:03:20 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Sat Oct 25 12:03:20 2014 +0200

----------------------------------------------------------------------
 .../viewaccess/ViewAccessContextManager.java    | 26 ++++++++++
 .../InjectableViewAccessContextManager.java     | 52 ++++++++++++++++++++
 .../scope/viewaccess/ViewAccessContext.java     | 39 ++++++++++-----
 .../ViewAccessContextArtifactProducer.java      | 41 +++++++++++++++
 4 files changed, 146 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f7e4ff47/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/scope/viewaccess/ViewAccessContextManager.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/scope/viewaccess/ViewAccessContextManager.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/scope/viewaccess/ViewAccessContextManager.java
new file mode 100644
index 0000000..0a87365
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/spi/scope/viewaccess/ViewAccessContextManager.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.core.spi.scope.viewaccess;
+
+import java.io.Serializable;
+
+public interface ViewAccessContextManager extends Serializable
+{
+    void close();
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f7e4ff47/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/InjectableViewAccessContextManager.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/InjectableViewAccessContextManager.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/InjectableViewAccessContextManager.java
new file mode 100644
index 0000000..a4cfac3
--- /dev/null
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/InjectableViewAccessContextManager.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.core.impl.scope.viewaccess;
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension;
+import org.apache.deltaspike.core.spi.scope.viewaccess.ViewAccessContextManager;
+
+import javax.enterprise.inject.Typed;
+
+@Typed()
+class InjectableViewAccessContextManager implements ViewAccessContextManager
+{
+    private transient volatile ViewAccessContextManager viewAccessContextManager;
+
+    public InjectableViewAccessContextManager(ViewAccessContextManager viewAccessContextManager)
+    {
+        this.viewAccessContextManager = viewAccessContextManager;
+    }
+
+    private ViewAccessContextManager getConversationManager()
+    {
+        if (this.viewAccessContextManager == null)
+        {
+            this.viewAccessContextManager =
+                BeanProvider.getContextualReference(DeltaSpikeContextExtension.class).getViewAccessScopedContext();
+        }
+        return this.viewAccessContextManager;
+    }
+
+    @Override
+    public void close()
+    {
+        getConversationManager().close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f7e4ff47/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java
index bd3bad9..c43f8c1 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContext.java
@@ -18,19 +18,23 @@
  */
 package org.apache.deltaspike.core.impl.scope.viewaccess;
 
-import java.lang.annotation.Annotation;
-import java.util.Map;
-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 org.apache.deltaspike.core.api.scope.ViewAccessScoped;
 import org.apache.deltaspike.core.impl.scope.window.WindowContextImpl;
+import org.apache.deltaspike.core.spi.scope.viewaccess.ViewAccessContextManager;
 import org.apache.deltaspike.core.util.context.AbstractContext;
 import org.apache.deltaspike.core.util.context.ContextualInstanceInfo;
 import org.apache.deltaspike.core.util.context.ContextualStorage;
 
-public class ViewAccessContext extends AbstractContext
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.PassivationCapable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+@Typed()
+public class ViewAccessContext extends AbstractContext implements ViewAccessContextManager
 {
     private static final String KEY = "VAS"; //TODO re-visit key (e.g. view-id instead of
using one big storage)
 
@@ -112,32 +116,37 @@ public class ViewAccessContext extends AbstractContext
 
     public void onProcessingViewFinished(String view)
     {
+        close(view, false);
+    }
+
+    public void close(String view, boolean force)
+    {
         // ignore if WindowContext isn't active - our ViewAccessViewHistory is WindowScoped
         if (!windowContext.isActive())
         {
             return;
         }
-        
+
         // destroy beans only if the view has been changed
-        if (!view.equals(viewAccessViewHistory.getLastView()))
+        if (force || !view.equals(viewAccessViewHistory.getLastView()))
         {
             viewAccessViewHistory.setLastView(view);
             
-            destroyExpiredBeans();
+            destroyExpiredBeans(force);
         }
         
         // clear history after each rendering process
         viewAccessBeanAccessHistory.getAccessedBeans().clear();
     }
     
-    private void destroyExpiredBeans()
+    private void destroyExpiredBeans(boolean force)
     {
         ContextualStorage storage = viewAccessBeanHolder.getContextualStorage(beanManager,
KEY, false);
         if (storage != null)
         {
             for (Map.Entry<Object, ContextualInstanceInfo<?>> storageEntry :
storage.getStorage().entrySet())
             {
-                if (!viewAccessBeanAccessHistory.getAccessedBeans().contains((String) storageEntry.getKey()))
+                if (force || !viewAccessBeanAccessHistory.getAccessedBeans().contains((String)
storageEntry.getKey()))
                 {
                     Contextual bean = storage.getBean(storageEntry.getKey());
                     AbstractContext.destroyBean(bean, storageEntry.getValue());
@@ -146,4 +155,10 @@ public class ViewAccessContext extends AbstractContext
             }
         }
     }
+
+    @Override
+    public void close()
+    {
+        close(null, true);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f7e4ff47/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContextArtifactProducer.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContextArtifactProducer.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContextArtifactProducer.java
new file mode 100644
index 0000000..5d514a2
--- /dev/null
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessContextArtifactProducer.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.core.impl.scope.viewaccess;
+
+import org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension;
+import org.apache.deltaspike.core.spi.scope.viewaccess.ViewAccessContextManager;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+@ApplicationScoped
+public class ViewAccessContextArtifactProducer
+{
+    @Inject
+    private DeltaSpikeContextExtension deltaSpikeContextExtension;
+
+    @Produces
+    @Dependent
+    public ViewAccessContextManager getViewAccessContextManager()
+    {
+        return new InjectableViewAccessContextManager(this.deltaSpikeContextExtension.getViewAccessScopedContext());
+    }
+}


Mime
View raw message