portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r1000341 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/ jetspeed-portal-resources/src/main/resources/assembly/ jetspeed-portal-resources/src/main/resources/assembly/alter...
Date Thu, 23 Sep 2010 07:30:51 GMT
Author: rwatler
Date: Thu Sep 23 07:30:50 2010
New Revision: 1000341

URL: http://svn.apache.org/viewvc?rev=1000341&view=rev
Log:
Add read/write lock to PAMs to limit concurrent write access to registry component; add configuration
property to disable locking in the event of unexpected side effects

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/VersionedPortletApplicationManager.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/versioned-deployment/deployment.xml
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java?rev=1000341&r1=1000340&r2=1000341&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
Thu Sep 23 07:30:50 2010
@@ -20,6 +20,8 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.jetspeed.cluster.NodeManager;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
@@ -56,6 +58,7 @@ public class PortletApplicationManager i
 
     protected PortletFactory             portletFactory;
     protected PortletRegistry            registry;
+    protected ReadWriteLock              registryLock;
     protected SearchEngine               searchEngine;
     protected RoleManager                roleManager;
     protected PermissionManager          permissionManager;
@@ -93,6 +96,9 @@ public class PortletApplicationManager i
         this.nodeManager        = nodeManager;
         this.appRoot            = appRoot;
         this.descriptorService  = descriptorService;
+        
+        // utilize read/write locked access to registry by default
+        setLockRegistryAccess(true);
     }
     
     public void setPAMProxy(PortletApplicationManagement pamProxy)
@@ -274,7 +280,7 @@ public class PortletApplicationManager i
         try
         {
             PortletApplication pa = null;
-            
+            lockRegistry(RegistryLock.READ);
             try
             {
                 pa = registry.getPortletApplication(paName);
@@ -283,7 +289,10 @@ public class PortletApplicationManager i
             {
                 // ignore errors during portal shutdown
             }
-
+            finally
+            {
+                unlockRegistry(RegistryLock.READ);
+            }
             
             if (pa != null)
             {
@@ -376,7 +385,15 @@ public class PortletApplicationManager i
         // register the portlet application
         try
         {
-            registry.registerPortletApplication(pa);
+            lockRegistry(RegistryLock.WRITE);
+            try
+            {
+                registry.registerPortletApplication(pa);
+            }
+            finally
+            {
+                unlockRegistry(RegistryLock.WRITE);                
+            }
             registered = true;
             log.info("Registered the portlet application " + paName);
 
@@ -493,7 +510,16 @@ public class PortletApplicationManager i
             }
 
             // try to get the PA from database by context name
-            PortletApplication pa = registry.getPortletApplication(contextName);
+            PortletApplication pa = null;
+            lockRegistry(RegistryLock.READ);
+            try
+            {
+                pa = registry.getPortletApplication(contextName);
+            }
+            finally
+            {
+                unlockRegistry(RegistryLock.READ);                
+            }
 
             if (pa != null)
             {
@@ -689,7 +715,7 @@ public class PortletApplicationManager i
         throws RegistryException
     {
         PortletApplication pa = null;
-        
+        lockRegistry(RegistryLock.READ);
         try
         {
             pa = registry.getPortletApplication(contextName);
@@ -698,6 +724,11 @@ public class PortletApplicationManager i
         {
             // ignore errors during portal shutdown
         }
+        finally
+        {
+            unlockRegistry(RegistryLock.READ);                
+        }
+        
         if  (pa != null && pa.getApplicationType() != paType) 
         {
             throw new RegistryException("Cannot stop portlet application "+contextName+":
as Application Types don't match: " + pa.getApplicationType() + " != " + paType);
@@ -746,7 +777,16 @@ public class PortletApplicationManager i
         updateSearchEngine(true,pa);
 
         // todo keep (User)Prefs?
-        registry.removeApplication(pa);
+        lockRegistry(RegistryLock.WRITE);
+        try
+        {
+            registry.removeApplication(pa);
+        }
+        finally
+        {
+            unlockRegistry(RegistryLock.WRITE);                
+        }
+        
         revokeDefaultPermissions(pa.getName());
     }
     
@@ -1130,4 +1170,66 @@ public class PortletApplicationManager i
     {
         return maxRetriedStarts;
     }    
+
+    /**
+     * RegistryLock access type enumeration.
+     */
+    protected enum RegistryLock {READ, WRITE};
+    
+    /**
+     * Lock specified access to registry.
+     * 
+     * @param lockAccess lock access type
+     */
+    protected void lockRegistry(RegistryLock lockAccess)
+    {
+        if (registryLock != null)
+        {
+            switch (lockAccess)
+            {
+                case READ : registryLock.readLock().lock(); break;
+                case WRITE : registryLock.writeLock().lock(); break;
+            }
+        }
+    }
+
+    /**
+     * Unlock specified access to registry.
+     * 
+     * @param lockAccess lock access type
+     */
+    protected void unlockRegistry(RegistryLock lockAccess)
+    {
+        if (registryLock != null)
+        {
+            switch (lockAccess)
+            {
+                case READ : registryLock.readLock().unlock(); break;
+                case WRITE : registryLock.writeLock().unlock(); break;
+            }
+        }
+    }
+    
+    /**
+     * Get read/write lock registry access configuration.
+     * 
+     * @return lock registry access configuration.
+     */
+    public boolean getLockRegistryAccess()
+    {
+        return (registryLock != null);
+    }
+    
+    /**
+     * Set read/write lock registry access configuration.
+     * 
+     * @param lockRegistryAccess lock registry access configuration.
+     */
+    public void setLockRegistryAccess(boolean lockRegistryAccess)
+    {
+        if ((registryLock != null) != lockRegistryAccess)
+        {
+            registryLock = (lockRegistryAccess ? new ReentrantReadWriteLock(true) : null);
+        }
+    }
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/VersionedPortletApplicationManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/VersionedPortletApplicationManager.java?rev=1000341&r1=1000340&r2=1000341&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/VersionedPortletApplicationManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/tools/pamanager/VersionedPortletApplicationManager.java
Thu Sep 23 07:30:50 2010
@@ -58,11 +58,11 @@ public class VersionedPortletApplication
 {
     private static final Logger    log = LoggerFactory.getLogger("deployment");
         
-    public VersionedPortletApplicationManager(PortletFactory portletFactory, PortletRegistry
registry, 
+    public VersionedPortletApplicationManager(PortletFactory portletFactory, PortletRegistry
registry,
             PermissionManager permissionManager, SearchEngine searchEngine,  RoleManager
roleManager,
             List<String> permissionRoles, /* node manager, */ String appRoot, JetspeedDescriptorService
descriptorService)
     {
-        super(portletFactory, registry, permissionManager, 
+        super(portletFactory, registry, permissionManager,
                 searchEngine, roleManager, permissionRoles, null, appRoot, descriptorService);

                
     }
@@ -113,7 +113,17 @@ public class VersionedPortletApplication
                 //register = false;
             }
             
-            PortletApplication regPA = registry.getPortletApplication(contextName); 
+            PortletApplication regPA = null;
+            lockRegistry(RegistryLock.READ);
+            try
+            {
+                regPA = registry.getPortletApplication(contextName);
+            }
+            finally
+            {
+                unlockRegistry(RegistryLock.READ);                
+            }
+            
             PortletApplication newPA = paWar.createPortletApp();
             if (regPA == null)
             {

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/versioned-deployment/deployment.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/versioned-deployment/deployment.xml?rev=1000341&r1=1000340&r2=1000341&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/versioned-deployment/deployment.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/versioned-deployment/deployment.xml
Thu Sep 23 07:30:50 2010
@@ -61,6 +61,11 @@
       see https://issues.apache.org/jira/browse/JS2-666
       <property name="maxRetriedStarts"><value>10</value></property>
     -->
+    <!-- optional read/write locked access to registry used by default to limit concurrent
+         PAM access to registry during registration, this property can be used to disable
this
+         locking by setting value to "false":
+      <property name="lockRegistryAccess"><value>false</value></property>
+    -->
   </bean>
 
 </beans>

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml?rev=1000341&r1=1000340&r2=1000341&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml
Thu Sep 23 07:30:50 2010
@@ -97,6 +97,11 @@
       see https://issues.apache.org/jira/browse/JS2-666
       <property name="maxRetriedStarts"><value>10</value></property>
     -->
+    <!-- optional read/write locked access to registry used by default to limit concurrent
+         PAM access to registry during registration, this property can be used to disable
this
+         locking by setting value to "false":
+      <property name="lockRegistryAccess"><value>false</value></property>
+    -->
   </bean>
 
    <bean id="PAM" parent="baseTransactionProxy">



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