Author: ivaynberg
Date: Tue Jun 29 16:47:56 2010
New Revision: 959026

URL: http://svn.apache.org/viewvc?rev=959026&view=rev
Log:
optimize access to mount map, making webrequestcodingstrategy more concurrent

Modified:
    
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java

Modified: 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java?rev=959026&r1=959025&r2=959026&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
 (original)
+++ 
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/protocol/http/request/WebRequestCodingStrategy.java
 Tue Jun 29 16:47:56 2010
@@ -21,8 +21,10 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
 import java.util.Map.Entry;
+import java.util.TreeMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.wicket.Application;
 import org.apache.wicket.Component;
@@ -169,6 +171,7 @@ public class WebRequestCodingStrategy im
         * </p>
         */
        private final MountsMap mountsOnPath;
+       private final ReadWriteLock mountsOnPathLock = new 
ReentrantReadWriteLock();
 
        /**
         * Construct.
@@ -402,11 +405,16 @@ public class WebRequestCodingStrategy im
         */
        public IRequestTargetUrlCodingStrategy[] listMounts()
        {
-               synchronized (mountsOnPath)
+               try
                {
+                       mountsOnPathLock.readLock().lock();
                        return mountsOnPath.strategies().toArray(
                                new 
IRequestTargetUrlCodingStrategy[mountsOnPath.size()]);
                }
+               finally
+               {
+                       mountsOnPathLock.readLock().unlock();
+               }
        }
 
        /**
@@ -414,8 +422,9 @@ public class WebRequestCodingStrategy im
         */
        public IRequestTargetUrlCodingStrategy urlCodingStrategyForPath(String 
path)
        {
-               synchronized (mountsOnPath)
+               try
                {
+                       mountsOnPathLock.readLock().lock();
                        if (path == null)
                        {
                                return mountsOnPath.strategyForMount(null);
@@ -428,8 +437,13 @@ public class WebRequestCodingStrategy im
                                        return strategy;
                                }
                        }
+                       return null;
                }
-               return null;
+               finally
+               {
+                       mountsOnPathLock.readLock().unlock();
+               }
+
        }
 
        /**
@@ -461,8 +475,9 @@ public class WebRequestCodingStrategy im
                        path = path.substring(1);
                }
 
-               synchronized (mountsOnPath)
+               try
                {
+                       mountsOnPathLock.writeLock().lock();
                        if (mountsOnPath.strategyForMount(path) != null)
                        {
                                throw new WicketRuntimeException(path + " is 
already mounted for " +
@@ -470,6 +485,10 @@ public class WebRequestCodingStrategy im
                        }
                        mountsOnPath.mount(path, encoder);
                }
+               finally
+               {
+                       mountsOnPathLock.writeLock().unlock();
+               }
        }
 
        /**
@@ -523,10 +542,15 @@ public class WebRequestCodingStrategy im
                        path = path.substring(1);
                }
 
-               synchronized (mountsOnPath)
+               try
                {
+                       mountsOnPathLock.writeLock().lock();
                        mountsOnPath.unmount(path);
                }
+               finally
+               {
+                       mountsOnPathLock.writeLock().unlock();
+               }
        }
 
        /**
@@ -981,8 +1005,9 @@ public class WebRequestCodingStrategy im
 
                if 
(IActivePageBehaviorListener.INTERFACE.getName().equals(listenerName))
                {
-                       url.append(url.indexOf("?") > -1 ? "&" : "?").append(
-                               
IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME).append("=true");
+                       url.append(url.indexOf("?") > -1 ? "&" : "?")
+                               .append(IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME)
+                               .append("=true");
                }
                return url;
        }
@@ -1020,8 +1045,9 @@ public class WebRequestCodingStrategy im
         */
        protected IRequestTargetUrlCodingStrategy 
getMountEncoder(IRequestTarget requestTarget)
        {
-               synchronized (mountsOnPath)
+               try
                {
+                       mountsOnPathLock.readLock().lock();
                        // TODO Post 1.2: Performance: Optimize algorithm if 
possible and/ or
                        // cache lookup results
                        for (IRequestTargetUrlCodingStrategy encoder : 
mountsOnPath.strategies())
@@ -1032,6 +1058,10 @@ public class WebRequestCodingStrategy im
                                }
                        }
                }
+               finally
+               {
+                       mountsOnPathLock.readLock().unlock();
+               }
                return null;
        }
 


Reply via email to