portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r707185 - /portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
Date Wed, 22 Oct 2008 20:17:24 GMT
Author: ate
Date: Wed Oct 22 13:17:24 2008
New Revision: 707185

URL: http://svn.apache.org/viewvc?rev=707185&view=rev
Log:
Improvement for JS2-913: PortletFactory should not cache portlet and application definition
oid values to support live redeployment across a cluster
See: https://issues.apache.org/jira/browse/JS2-913

Modified:
    portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java

Modified: portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java?rev=707185&r1=707184&r2=707185&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
(original)
+++ portals/jetspeed-2/portal/branches/JETSPEED-2.1.2-POSTRELEASE/components/portlet-factory/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
Wed Oct 22 13:17:24 2008
@@ -72,7 +72,7 @@
             synchronized (classLoaderMap)
             {
                 unregisterPortletApplication(pa);
-                classLoaderMap.put(pa.getId(), cl);
+                classLoaderMap.put(pa.getName(), cl);
             }
     }
     
@@ -82,19 +82,18 @@
         {
             synchronized (portletCache)
             {
-                ClassLoader cl = (ClassLoader) classLoaderMap.remove(pa.getId());
+                ClassLoader cl = (ClassLoader) classLoaderMap.remove(pa.getName());
                 if (cl != null)
                 {
                     ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
 
-                    Iterator portletDefinitions = pa.getPortletDefinitions().iterator();
-                    while (portletDefinitions.hasNext())
+                    HashMap instanceCache = (HashMap)portletCache.remove(pa.getName());
+                    if (instanceCache != null)
                     {
-                        PortletDefinition pd = (PortletDefinition) portletDefinitions.next();
-                        String pdId = pd.getId().toString();
-                        Portlet portlet = (Portlet) portletCache.remove(pdId);
-                        if (portlet != null)
+                        Iterator instances = instanceCache.values().iterator();
+                        while (instances.hasNext())
                         {
+                            Portlet portlet = (Portlet)instances.next();
                             try
                             {
                                 Thread.currentThread().setContextClassLoader(cl);
@@ -105,8 +104,8 @@
                                 Thread.currentThread().setContextClassLoader(currentContextClassLoader);
                             }
                         }
-                        validatorCache.remove(pdId);
                     }
+                    validatorCache.remove(pa.getName());
                 }
             }
         }
@@ -117,21 +116,22 @@
         PreferencesValidator validator = null;
         try
         {
-            String pdId = pd.getId().toString();
+            String paName = ((PortletApplication)pd.getPortletApplicationDefinition()).getName();
+            String pdName = pd.getName();
             
             synchronized (validatorCache)
             {
-                validator = (PreferencesValidator)validatorCache.get(pdId);
+                HashMap instanceCache = (HashMap)validatorCache.get(paName);
+                validator = instanceCache != null ? (PreferencesValidator)instanceCache.get(pdName)
: null;
                 if ( validator == null )
                 {
                     String className = ((PortletDefinitionComposite)pd).getPreferenceValidatorClassname();
                     if ( className != null )
                     {
-                        PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition();
-                        ClassLoader paCl = (ClassLoader)classLoaderMap.get(pa.getId());
+                        ClassLoader paCl = (ClassLoader)classLoaderMap.get(paName);
                         if ( paCl == null )
                         {
-                            throw new UnavailableException("Portlet Application "+pa.getName()+"
not available");
+                            throw new UnavailableException("Portlet Application "+paName+"
not available");
                         }
                         
                         ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
@@ -142,7 +142,12 @@
                             {
                                 Thread.currentThread().setContextClassLoader(paCl);
                                 validator = (PreferencesValidator)clazz.newInstance();
-                                validatorCache.put(pdId, validator);
+                                if (instanceCache == null)
+                                {
+                                    instanceCache = new HashMap();
+                                    validatorCache.put(paName, instanceCache);
+                                }
+                                instanceCache.put(pdName, validator);
                             }
                             finally
                             {
@@ -151,7 +156,7 @@
                         }
                         catch (Exception e)
                         {
-                            String msg = "Cannot create PreferencesValidator instance "+className+"
for Portlet "+pd.getName();
+                            String msg = "Cannot create PreferencesValidator instance "+className+"
for Portlet "+pdName;
                             log.error(msg,e);
                         }
                     }
@@ -175,23 +180,25 @@
     public PortletInstance getPortletInstance( ServletContext servletContext, PortletDefinition
pd ) throws PortletException
     {
         PortletInstance portlet = null;
-        String pdId = pd.getId().toString();
         PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition();
+        String paName = pa.getName();
+        String pdName = pd.getName();
 
         try
         {                        
           synchronized (portletCache)
           {
-            portlet = (PortletInstance)portletCache.get(pdId);
+            HashMap instanceCache = (HashMap)portletCache.get(paName);
+            portlet = instanceCache != null ? (PortletInstance)instanceCache.get(pdName)
: null;
             if (null != portlet)
             {
                 return portlet;
             }
             
-            ClassLoader paCl = (ClassLoader)classLoaderMap.get(pa.getId());
+            ClassLoader paCl = (ClassLoader)classLoaderMap.get(paName);
             if ( paCl == null )
             {
-                throw new UnavailableException("Portlet Application "+pa.getName()+" not
available");
+                throw new UnavailableException("Portlet Application "+paName+" not available");
             }
             
             ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
@@ -205,7 +212,7 @@
                 // wrap new Portlet inside PortletInstance which ensures the destroy
                 // method will wait for all its invocation threads to complete
                 // and thereby releasing all its ClassLoader locks as needed for local portlets.
-                portlet = new JetspeedPortletInstance(pd.getName(), (Portlet)clazz.newInstance());
+                portlet = new JetspeedPortletInstance(pdName, (Portlet)clazz.newInstance());
             }
               finally
             {
@@ -214,7 +221,7 @@
             }
             catch (Exception e)
             {
-                String msg = "Cannot create Portlet instance "+pd.getClassName()+" for Portlet
Application "+pa.getName();
+                String msg = "Cannot create Portlet instance "+pd.getClassName()+" for Portlet
Application "+paName;
                 log.error(msg,e);
                 throw new UnavailableException(msg);
             }
@@ -236,10 +243,15 @@
             }
             catch (PortletException e1)
             {
-                log.error("Failed to initialize Portlet "+pd.getClassName()+" for Portlet
Application "+pa.getName(), e1);
+                log.error("Failed to initialize Portlet "+pd.getClassName()+" for Portlet
Application "+paName, e1);
                 throw e1;
             }            
-            portletCache.put(pdId, portlet);
+            if (instanceCache == null)
+            {
+                instanceCache = new HashMap();
+                portletCache.put(paName, instanceCache);
+            }
+            instanceCache.put(pdName, portlet);
           }
         }
         catch (PortletException pe)
@@ -258,13 +270,17 @@
     {
         if (pd != null)
         {
-            //System.out.println("$$$$ updating portlet config for " + pd.getName());
-            String key = pd.getId().toString();
-            PortletInstance instance = (PortletInstance)portletCache.get(key);
-            if (instance != null)
+            synchronized (portletCache)
             {
-                JetspeedPortletConfig config = (JetspeedPortletConfig)instance.getConfig();
-                config.setPortletDefinition(pd);
+                //System.out.println("$$$$ updating portlet config for " + pd.getName());
+                String key = pd.getId().toString();
+                HashMap instanceCache = (HashMap)portletCache.get(((PortletApplication)pd.getPortletApplicationDefinition()).getName());
+                PortletInstance instance = instanceCache != null ? (PortletInstance)instanceCache.get(pd.getName())
: null;
+                if (instance != null)
+                {
+                    JetspeedPortletConfig config = (JetspeedPortletConfig)instance.getConfig();
+                    config.setPortletDefinition(pd);
+                }
             }
         }
     }
@@ -275,7 +291,7 @@
         {
           if ( pa != null )
         {
-              return (ClassLoader)classLoaderMap.get(pa.getId());
+              return (ClassLoader)classLoaderMap.get(pa.getName());
         }
           return null;
         }



---------------------------------------------------------------------
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