portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r408514 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java src/webapp/WEB-INF/assembly/jetspeed-spring.xml
Date Sun, 21 May 2006 22:42:55 GMT
Author: ate
Date: Sun May 21 15:42:54 2006
New Revision: 408514

URL: http://svn.apache.org/viewvc?rev=408514&view=rev
Log:
Automatically clear cached but no longer valid PortletWindow/PortletEntity instances.

A PortletEntity normally holds a reference to a PortletDefinition and its PortletApplication.
When a Portlet Application is restarted/redeployed with changes in its portlet.xml, the registry
for it is updated.
Then, cached PortletWindow/PortletEntity instances still holding out-of-sync references to
the "old" registry instances
may cause  rendering problems which can only be solved by restarting the portal!

Now, each PortletWindow and its PortletEntity instance will first be checked when retrieved
from the cache and removed from it when out-of-sync.

Note: this is a light-weight validation checking if the referenced PortletApplication is registered
in the PortletFactory (meaning its active/available).
These checks will have no real performance penalty for "valid" PortletWindows, only for "offline"
Portlet Applications they will (need to) be recreated each and every time. 

Warning: this change requires a mandatory change to the Spring assembly definition for the
PortletWindowAccessorImpl (in jetspeed-spring.xml).   

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/jetspeed-spring.xml

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java?rev=408514&r1=408513&r2=408514&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/container/window/impl/PortletWindowAccessorImpl.java
Sun May 21 15:42:54 2006
@@ -28,7 +28,9 @@
 import org.apache.jetspeed.container.window.FailedToCreateWindowException;
 import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
 import org.apache.jetspeed.container.window.PortletWindowAccessor;
+import org.apache.jetspeed.factory.PortletFactory;
 import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
+import org.apache.jetspeed.om.common.portlet.PortletApplication;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.window.impl.PortletWindowImpl;
 import org.apache.jetspeed.util.ArgUtil;
@@ -49,12 +51,14 @@
     private Map windows = Collections.synchronizedMap(new HashMap());    
         
     private PortletEntityAccessComponent entityAccessor;
+    private PortletFactory portletFactory;
     private boolean validateWindows = false;
     
 
-    public PortletWindowAccessorImpl(PortletEntityAccessComponent entityAccessor, boolean
validateWindows)
+    public PortletWindowAccessorImpl(PortletEntityAccessComponent entityAccessor, PortletFactory
portletFactory, boolean validateWindows)
     {
         this.entityAccessor = entityAccessor;
+        this.portletFactory = portletFactory;
         this.validateWindows = validateWindows;
     }
 
@@ -68,13 +72,18 @@
         PortletWindow found = getWindowFromCache(windowId);
         if (found != null)
         {
+            // remove from cache if invalid entity
+            checkPortletWindowEntity(found);
             ((PortletWindowCtrl)found).setPortletEntity(entity);
             return found;
         }
         
         PortletWindowImpl window = new PortletWindowImpl(windowId);
         window.setPortletEntity(entity);
-        windows.put(windowId, window);
+        if ( isValidPortletEntity(entity))
+        {
+            windows.put(windowId, window);
+        }
         return window;        
     }
 
@@ -83,6 +92,8 @@
         PortletWindow found = getWindowFromCache(windowId);
         if (found != null)
         {
+            // remove from cache if invalid entity
+            checkPortletWindowEntity(found);
             return found;
         }        
         PortletWindowImpl window = new PortletWindowImpl(windowId);
@@ -91,14 +102,20 @@
     
     public PortletWindow getPortletWindow(String windowId)
     {
-        return getWindowFromCache(windowId);
+        PortletWindow window = getWindowFromCache(windowId);
+        if (window != null)
+        {
+            // remove from cache if invalid entity
+            checkPortletWindowEntity(window);
+        }        
+        return window;
     }
     
     public PortletWindow getPortletWindow(ContentFragment fragment) throws FailedToRetrievePortletWindow,
PortletEntityNotStoredException
     {
         ArgUtil.assertNotNull(ContentFragment.class, fragment, this, "getPortletWindow(Fragment
fragment)");
-        PortletWindow portletWindow = getWindowFromCache(fragment);
-        if (portletWindow == null)
+        PortletWindow portletWindow = getWindowFromCache(fragment);        
+        if (portletWindow == null || !checkPortletWindowEntity(portletWindow))
         {
             try
             {
@@ -137,6 +154,8 @@
         if(portletEntity != null)
         {
             ((PortletWindowCtrl) portletWindow).setPortletEntity(portletEntity);
+            // if not a valid entity, remove window from cache
+            checkPortletWindowEntity(portletWindow);
         }
         else
         {
@@ -180,7 +199,7 @@
             {
                 portletEntity = entityAccessor.generateEntityFromFragment(fragment, principal);
                 // not portlet definition most likely means that the portlet has not been
deployed so dont worry about storing off the entity
-                if(portletEntity.getPortletDefinition() != null)
+                if(isValidPortletEntity(portletEntity))
                 {
                     entityAccessor.storePortletEntity(portletEntity);
                 }
@@ -240,5 +259,23 @@
     {
         return (PortletWindow)windows.get(id);
     }
+
+    private boolean checkPortletWindowEntity(PortletWindow window)
+    {
+        if (!isValidPortletEntity(window.getPortletEntity()))
+        {
+            removeWindow(window);
+            return false;
+        }
+        return true;
+    }
     
+    private boolean isValidPortletEntity(PortletEntity pe)
+    {
+        return pe != null
+                && pe.getPortletDefinition() != null
+                && pe.getPortletDefinition().getPortletApplicationDefinition() !=
null
+                && portletFactory.isPortletApplicationRegistered((PortletApplication)
pe.getPortletDefinition()
+                        .getPortletApplicationDefinition());
+    }
 }

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/jetspeed-spring.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/jetspeed-spring.xml?rev=408514&r1=408513&r2=408514&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/jetspeed-spring.xml (original)
+++ portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/jetspeed-spring.xml Sun May 21 15:42:54
2006
@@ -103,6 +103,9 @@
         <constructor-arg>
             <ref bean="org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent"
/>
         </constructor-arg>
+        <constructor-arg>
+            <ref bean="portletFactory" />
+        </constructor-arg>
         <!-- enable window validation -->
         <constructor-arg type="boolean">
             <value>false</value>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message