deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject git commit: DELTASPIKE-487 removed unused logic (thanks netbeans)
Date Thu, 27 Feb 2014 22:40:52 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 4ff33b15b -> e0acd5c76


DELTASPIKE-487 removed unused logic (thanks netbeans)

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

Branch: refs/heads/master
Commit: e0acd5c76a23d858210a7a5d0ea46701c7d6a04c
Parents: 4ff33b1
Author: tandraschko <tandraschko@apache.org>
Authored: Thu Feb 27 23:40:40 2014 +0100
Committer: tandraschko <tandraschko@apache.org>
Committed: Thu Feb 27 23:40:40 2014 +0100

----------------------------------------------------------------------
 .../core/util/ClassDeactivationUtils.java       | 207 +++++++++----------
 .../scope/viewaccess/ViewAccessContext.java     |  15 +-
 .../viewaccess/ViewAccessScopedBeanHistory.java |  12 --
 3 files changed, 96 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e0acd5c7/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
index a69f730..ef8ef57 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassDeactivationUtils.java
@@ -16,161 +16,142 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.deltaspike.core.util;
+package org.apache.deltaspike.jsf.impl.listener.request;
 
-import org.apache.deltaspike.core.api.config.ConfigResolver;
-import org.apache.deltaspike.core.spi.activation.ClassDeactivator;
-import org.apache.deltaspike.core.spi.activation.Deactivatable;
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.spi.scope.window.WindowContext;
+import org.apache.deltaspike.core.util.ClassDeactivationUtils;
+import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
 
-import javax.enterprise.inject.Typed;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension;
+import org.apache.deltaspike.core.impl.scope.viewaccess.ViewAccessContext;
 
-/**
- * Helper methods for {@link ClassDeactivator}
- */
-@Typed()
-public abstract class ClassDeactivationUtils
+class DeltaSpikeLifecycleWrapper extends Lifecycle
 {
-    private static final Logger LOG = Logger.getLogger(ClassDeactivationUtils.class.getName());
+    private final Lifecycle wrapped;
 
-    /**
-     * This Map holds the ClassLoader as first level to make it possible to have different
configurations per 
-     * WebApplication in an EAR or other Multi-ClassLoader scenario.
-     * 
-     * The Map then contains a List of {@link ClassDeactivator}s in order of their configured
ordinal.
-     */
-    private static Map<ClassLoader, List<ClassDeactivator>> classDeactivatorMap
-        = new ConcurrentHashMap<ClassLoader, List<ClassDeactivator>>();
+    private JsfRequestBroadcaster jsfRequestBroadcaster;
 
-    /**
-     * Cache for the result. It won't contain many classes but it might be accessed frequently.
-     * Valid entries are only true or false. If an entry isn't available or null, it gets
calculated.
-     */
-    private static Map<Class<? extends Deactivatable>, Boolean> activationStatusCache
-        = new ConcurrentHashMap<Class<? extends Deactivatable>, Boolean>();
-    
-    private ClassDeactivationUtils()
+    private ClientWindow clientWindow;
+    private WindowContext windowContext;
+    private DeltaSpikeContextExtension contextExtension;
+
+    private volatile Boolean initialized;
+
+    DeltaSpikeLifecycleWrapper(Lifecycle wrapped)
     {
-        // prevent instantiation
+        this.wrapped = wrapped;
     }
 
-    /**
-     * Evaluates if the given {@link Deactivatable} is active.
-     *
-     * @param targetClass {@link Deactivatable} under test.
-     * @return <code>true</code> if it is active, <code>false</code>
otherwise
-     */
-    public static boolean isActivated(Class<? extends Deactivatable> targetClass)
+    Lifecycle getWrapped()
     {
-        Boolean activatedClassCacheEntry = activationStatusCache.get(targetClass);
-
-        if (activatedClassCacheEntry == null)
-        {
-            initDeactivatableCacheFor(targetClass);
-            activatedClassCacheEntry = activationStatusCache.get(targetClass);
-        }
-        return activatedClassCacheEntry;
+        return wrapped;
     }
 
-    private static synchronized void initDeactivatableCacheFor(Class<? extends Deactivatable>
targetClass)
+    @Override
+    public void addPhaseListener(PhaseListener phaseListener)
     {
-        Boolean activatedClassCacheEntry = activationStatusCache.get(targetClass);
+        this.wrapped.addPhaseListener(phaseListener);
+    }
 
-        if (activatedClassCacheEntry != null) //double-check
+    /**
+     * Broadcasts
+     * {@link org.apache.deltaspike.core.api.lifecycle.Initialized} and
+     * {@link org.apache.deltaspike.core.api.lifecycle.Destroyed}
+     * //TODO StartupEvent
+     */
+    @Override
+    public void execute(FacesContext facesContext)
+    {
+        //can happen due to the window-handling of deltaspike
+        if (facesContext.getResponseComplete())
         {
             return;
         }
 
-        List<ClassDeactivator> classDeactivators = getClassDeactivators();
-
-        Boolean isActivated = Boolean.TRUE;
-        Class<? extends ClassDeactivator> deactivatedBy = null;
+        lazyInit();
 
-        LOG.fine("start evaluation if " + targetClass.getName() + " is de-/activated");
+        //TODO broadcastApplicationStartupBroadcaster();
+        broadcastInitializedJsfRequestEvent(facesContext);
 
-        // we get the classActivators ordered by it's ordinal
-        // thus the last one which returns != null 'wins' ;)
-        for (ClassDeactivator classDeactivator : classDeactivators)
+        // ClientWindow handling
+        String windowId = clientWindow.getWindowId(facesContext);
+        if (windowId != null)
         {
-            Boolean isLocallyActivated = classDeactivator.isActivated(targetClass);
+            windowContext.activateWindow(windowId);
+        }
 
-            if (isLocallyActivated != null)
-            {
-                isActivated = isLocallyActivated;
-
-                /*
-                * Check and log the details across class-deactivators
-                */
-                if (!isActivated)
-                {
-                    deactivatedBy = classDeactivator.getClass();
-                    LOG.fine("Deactivating class " + targetClass);
-                }
-                else if (deactivatedBy != null)
-                {
-                    LOG.fine("Reactivation of: " + targetClass.getName() + " by " +
-                            classDeactivator.getClass().getName() +
-                            " - original deactivated by: " + deactivatedBy.getName() + ".\n"
+
-                            "If that isn't the intended behaviour, you have to use a higher
ordinal for " +
-                            deactivatedBy.getName());
-                }
-            }
+        if (!FacesContext.getCurrentInstance().getResponseComplete())
+        {
+            this.wrapped.execute(facesContext);
         }
+    }
 
-        cacheResult(targetClass, isActivated);
+    @Override
+    public PhaseListener[] getPhaseListeners()
+    {
+        return this.wrapped.getPhaseListeners();
     }
 
-    private static void cacheResult(Class<? extends Deactivatable> targetClass, Boolean
activated)
+    @Override
+    public void removePhaseListener(PhaseListener phaseListener)
     {
-        activationStatusCache.put(targetClass, activated);
-        LOG.info("class: " + targetClass.getName() + " activated=" + activated);
+        this.wrapped.removePhaseListener(phaseListener);
     }
 
     /**
-     * @return the List of configured @{link ClassDeactivator}s for the current context ClassLoader.
+     * Performs cleanup tasks after the rendering process
      */
-    private static List<ClassDeactivator> getClassDeactivators()
+    @Override
+    public void render(FacesContext facesContext)
     {
-        ClassLoader classLoader = ClassUtils.getClassLoader(null);
-        List<ClassDeactivator> classDeactivators = classDeactivatorMap.get(classLoader);
-
-        if (classDeactivators == null)
+        this.wrapped.render(facesContext);
+        
+        if (facesContext.getViewRoot() != null)
         {
-            return initConfiguredClassDeactivators(classLoader);
+            ViewAccessContext viewAccessContext = contextExtension.getViewAccessScopedContext();
+            if (viewAccessContext != null)
+            {
+                viewAccessContext.onRenderingFinished(facesContext.getViewRoot().getViewId());
+            }
         }
-
-        return classDeactivators;
     }
 
-    //synchronized isn't needed - #initDeactivatableCacheFor is already synchronized
-    private static List<ClassDeactivator> initConfiguredClassDeactivators(ClassLoader
classLoader)
+    private void broadcastInitializedJsfRequestEvent(FacesContext facesContext)
     {
-        List<String> classDeactivatorClassNames = ConfigResolver.getAllPropertyValues(ClassDeactivator.class.getName());
-
-        List<ClassDeactivator> classDeactivators = new ArrayList<ClassDeactivator>();
+        if (this.jsfRequestBroadcaster != null)
+        {
+            this.jsfRequestBroadcaster.broadcastInitializedJsfRequestEvent(facesContext);
+        }
+    }
 
-        for (String classDeactivatorClassName : classDeactivatorClassNames)
+    private void lazyInit()
+    {
+        if (this.initialized == null)
         {
-            LOG.fine("processing ClassDeactivator: " + classDeactivatorClassName);
+            init();
+        }
+    }
 
-            try
-            {
-                ClassDeactivator currentClassDeactivator =
-                        (ClassDeactivator) ClassUtils.instantiateClassForName(classDeactivatorClassName);
-                classDeactivators.add(currentClassDeactivator);
-            }
-            catch (Exception e)
+    private synchronized void init()
+    {
+        // switch into paranoia mode
+        if (this.initialized == null)
+        {
+            if (ClassDeactivationUtils.isActivated(JsfRequestBroadcaster.class))
             {
-                LOG.warning(classDeactivatorClassName + " can't be instantiated");
-                throw new IllegalStateException(e);
+                this.jsfRequestBroadcaster =
+                        BeanProvider.getContextualReference(JsfRequestBroadcaster.class,
true);
             }
-        }
 
-        classDeactivatorMap.put(classLoader, classDeactivators);
-        return classDeactivators;
+            clientWindow = BeanProvider.getContextualReference(ClientWindow.class, true);
+            windowContext = BeanProvider.getContextualReference(WindowContext.class, true);
+            contextExtension = BeanProvider.getContextualReference(DeltaSpikeContextExtension.class,
true);
+            
+            this.initialized = true;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e0acd5c7/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 ba6d90c..701e4d0 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
@@ -19,8 +19,6 @@
 package org.apache.deltaspike.core.impl.scope.viewaccess;
 
 import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.spi.Contextual;
@@ -115,28 +113,19 @@ public class ViewAccessContext extends AbstractContext
             destroyExpiredBeans();
             
             // clear list from last request
-            List<String> lastAccessedBeans = viewAccessScopedBeanHistory.getLastAccessedBeans();
-            lastAccessedBeans.clear();
-            
-            // move used beans from this request to last request
-            viewAccessScopedBeanHistory.setLastAccessedBeans(viewAccessScopedBeanHistory.getAccessedBeans());
-            viewAccessScopedBeanHistory.setAccessedBeans(lastAccessedBeans);
+            viewAccessScopedBeanHistory.getAccessedBeans().clear();
         }
     }
     
     private void destroyExpiredBeans()
     {
-        List<String> usedBeans = new ArrayList<String>();
-        usedBeans.addAll(viewAccessScopedBeanHistory.getAccessedBeans());
-        usedBeans.addAll(viewAccessScopedBeanHistory.getLastAccessedBeans());
-
         ContextualStorage storage =
                 viewAccessScopedBeanHolder.getContextualStorage(beanManager, getCurrentWindowId(),
false);
         if (storage != null)
         {
             for (Map.Entry<Object, ContextualInstanceInfo<?>> storageEntry :
storage.getStorage().entrySet())
             {
-                if (!usedBeans.contains((String) storageEntry.getKey()))
+                if (!viewAccessScopedBeanHistory.getAccessedBeans().contains((String) storageEntry.getKey()))
                 {
                     Contextual bean = storage.getBean(storageEntry.getKey());
                     AbstractContext.destroyBean(bean, storageEntry.getValue());

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/e0acd5c7/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java
index b422f07..06ddbe9 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/viewaccess/ViewAccessScopedBeanHistory.java
@@ -30,13 +30,11 @@ public class ViewAccessScopedBeanHistory implements Serializable
     private static final long serialVersionUID = 3617603930728148927L;
     
     private List<String> accessedBeans;
-    private List<String> lastAccessedBeans;
     private String lastView;
 
     public ViewAccessScopedBeanHistory()
     {
         accessedBeans = new ArrayList<String>();
-        lastAccessedBeans = new ArrayList<String>();
     }
     
     public List<String> getAccessedBeans()
@@ -49,16 +47,6 @@ public class ViewAccessScopedBeanHistory implements Serializable
         this.accessedBeans = accessedBeans;
     }
 
-    public List<String> getLastAccessedBeans()
-    {
-        return lastAccessedBeans;
-    }
-
-    public void setLastAccessedBeans(List<String> lastAccessedBeans)
-    {
-        this.lastAccessedBeans = lastAccessedBeans;
-    }
-
     public String getLastView()
     {
         return lastView;


Mime
View raw message