You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2006/05/24 05:25:31 UTC

svn commit: r409056 - /portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java

Author: ate
Date: Tue May 23 20:25:31 2006
New Revision: 409056

URL: http://svn.apache.org/viewvc?rev=409056&view=rev
Log:
Reduce the unwielding number of FragmentPortletDefinition instances created for each and every access to PortletEntity.getPortletDefinition().
Now, a ThreadLocal will properly cache one instance per request.

Modified:
    portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java

Modified: portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java?rev=409056&r1=409055&r2=409056&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java (original)
+++ portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java Tue May 23 20:25:31 2006
@@ -93,6 +93,8 @@
     
     private Fragment fragment;
     
+    private static ThreadLocal fragmentPortletDefinition = new ThreadLocal();
+    
     public PortletEntityImpl(Fragment fragment)
     {
         setFragment(fragment);
@@ -220,8 +222,14 @@
             }
         }        
         
-        // Wrap the portlet defintion every request
-        return new FragmentPortletDefinition(this.portletDefinition, fragment);
+        // Wrap the portlet defintion every request thread
+        PortletDefinition fpd = (PortletDefinition)fragmentPortletDefinition.get();
+        if (fpd == null)
+        {
+            fpd = new FragmentPortletDefinition(this.portletDefinition, fragment);
+            fragmentPortletDefinition.set(fpd);
+        }        
+        return fpd;
     }
 
     public PortletApplicationEntity getPortletApplicationEntity()
@@ -377,6 +385,8 @@
         if(composite != null)
         {
             portletDefinition = (PortletDefinitionComposite) composite;
+            // if the portletDefinition is modified, clear threadlocal fragmentPortletDefinition cache
+            fragmentPortletDefinition.set(null);
             this.appName = ((MutablePortletApplication)portletDefinition.getPortletApplicationDefinition()).getName();
             this.portletName = portletDefinition.getName();
         }
@@ -545,7 +555,7 @@
     public void setFragment(Fragment fragment)
     {
         this.fragment = fragment;
-    }
-    
-    
+        // if the fragment is set, clear threadlocal fragmentPortletDefinition cache
+        fragmentPortletDefinition.set(null);
+    }   
 }



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