You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2007/09/21 03:31:51 UTC

svn commit: r577955 - in /webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws: handler/MEPContext.java spi/migrator/ApplicationContextMigratorUtil.java

Author: scheu
Date: Thu Sep 20 18:31:49 2007
New Revision: 577955

URL: http://svn.apache.org/viewvc?rev=577955&view=rev
Log:
AXIS2-3221
Contributors:Mike Rheinheimer and Rich Scheuerle
Performance speedups to Application Property Migrator code.
Reduced scope of locks and unnecessary map copies.

Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/migrator/ApplicationContextMigratorUtil.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java?rev=577955&r1=577954&r2=577955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/MEPContext.java Thu Sep 20 18:31:49 2007
@@ -22,11 +22,14 @@
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.message.Message;
 
+import javax.xml.ws.handler.MessageContext.Scope;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.Map.Entry;
 
 /**
  * The <tt>MEPContext</tt> is the version of the MessageContext
@@ -352,21 +355,20 @@
      */
     public Map<String, Object> getApplicationScopedProperties() {
         Map<String, Object> tempMap = new HashMap<String, Object>();
-        // better performance:
         if (!scopes.containsValue(Scope.APPLICATION)) {
             return tempMap;
         }
-        for(Iterator it = requestMC.getProperties().keySet().iterator(); it.hasNext();) {
-            String key = (String)it.next();
-            if ((getScope(key).equals(Scope.APPLICATION) && (requestMC.getProperties().containsKey(key)))) {
-                tempMap.put(key, get(key));
+        for(Iterator it = requestMC.getProperties().entrySet().iterator(); it.hasNext();) {
+            Entry entry = (Entry)it.next();
+            if (getScope((String)entry.getKey()).equals(Scope.APPLICATION)) {
+                tempMap.put((String)entry.getKey(), entry.getValue());
             }
         }
         if (responseMC != null) {
-            for(Iterator it = responseMC.getProperties().keySet().iterator(); it.hasNext();) {
-                String key = (String)it.next();
-                if ((getScope(key).equals(Scope.APPLICATION) && (responseMC.getProperties().containsKey(key)))) {
-                    tempMap.put(key, get(key));
+            for(Iterator it = responseMC.getProperties().entrySet().iterator(); it.hasNext();) {
+                Entry entry = (Entry)it.next();
+                if (getScope((String)entry.getKey()).equals(Scope.APPLICATION)) {
+                    tempMap.put((String)entry.getKey(), entry.getValue());
                 }
             }
         }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/migrator/ApplicationContextMigratorUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/migrator/ApplicationContextMigratorUtil.java?rev=577955&r1=577954&r2=577955&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/migrator/ApplicationContextMigratorUtil.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/spi/migrator/ApplicationContextMigratorUtil.java Thu Sep 20 18:31:49 2007
@@ -29,6 +29,7 @@
 import javax.xml.ws.handler.MessageContext.Scope;
 
 import java.util.AbstractSet;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -96,17 +97,28 @@
         ServiceDescription sd = messageContext.getEndpointDescription().getServiceDescription();
         if (sd != null) {
             ConfigurationContext configCtx = sd.getAxisConfigContext();
-            List<ApplicationContextMigrator> migratorList = (List<ApplicationContextMigrator>)configCtx.getProperty(contextMigratorListID);
-            synchronized(migratorList){
-                if (migratorList != null) {
-                    ListIterator<ApplicationContextMigrator> itr = migratorList.listIterator();
-                    while (itr.hasNext()) {
-                        ApplicationContextMigrator cpm = itr.next();
-                        if (log.isDebugEnabled()) {
-                            log.debug("migrator: " + cpm.getClass().getName() + ".migratePropertiesToMessageContext");
-                        }
-                        cpm.migratePropertiesToMessageContext(new ApplicationPropertyMapReader(requestContext, messageContext.getMEPContext()), messageContext);
+            List<ApplicationContextMigrator> migratorList = (List<ApplicationContextMigrator>) configCtx.getProperty(contextMigratorListID);
+            if (migratorList != null) {
+                
+                // Create copy to avoid using shared list
+                List listCPM = null;
+                
+                // synchronize on non-null migratorList
+                synchronized(migratorList){
+                     listCPM = new ArrayList(migratorList);
+                }
+                
+                ListIterator<ApplicationContextMigrator> itr = listCPM.listIterator();   // Iterate over non-shared list
+                while (itr.hasNext()) {
+                    ApplicationContextMigrator cpm = itr.next();
+                    if (log.isDebugEnabled()) {
+                        log.debug("migrator: " + cpm.getClass().getName() + ".migratePropertiesToMessageContext");
                     }
+                    
+                    // TODO: Synchronizing here is expensive too.
+                    // If a cpm requires synchronization, it should provide it inside of its migratePropertiesFromMessageContext implementation.
+                    
+                    cpm.migratePropertiesToMessageContext(new ApplicationPropertyMapReader(requestContext, messageContext.getMEPContext()), messageContext);
                 }
             }
         }
@@ -130,16 +142,27 @@
             List<ApplicationContextMigrator> migratorList =
                     (List<ApplicationContextMigrator>)configCtx.getProperty(contextMigratorListID);
 
-            synchronized(migratorList){
-                if (migratorList != null) {
-                    ListIterator<ApplicationContextMigrator> itr = migratorList.listIterator();
-                    while (itr.hasNext()) {
-                        ApplicationContextMigrator cpm = itr.next();
-                        if (log.isDebugEnabled()) {
-                            log.debug("migrator: " + cpm.getClass().getName() + ".migratePropertiesFromMessageContext");
-                        }
-                        cpm.migratePropertiesFromMessageContext(new ApplicationPropertyMapWriter(responseContext, messageContext.getMEPContext()), messageContext);
+            if (migratorList != null) {
+                
+                // Create copy to avoid using shared list
+                List listCPM = null;
+                
+                // synchronize on non-null migratorList
+                synchronized(migratorList){
+                     listCPM = new ArrayList(migratorList);
+                }
+            
+                ListIterator<ApplicationContextMigrator> itr = listCPM.listIterator();   // Iterate over non-shared list
+                while (itr.hasNext()) {
+                    ApplicationContextMigrator cpm = itr.next();
+                    if (log.isDebugEnabled()) {
+                        log.debug("migrator: " + cpm.getClass().getName() + ".migratePropertiesFromMessageContext");
                     }
+
+                    // TODO: Synchronizing here is expensive too.
+                    // If a cpm requires synchronization, it should provide it inside of its migratePropertiesFromMessageContext implementation.
+
+                    cpm.migratePropertiesFromMessageContext(new ApplicationPropertyMapWriter(responseContext, messageContext.getMEPContext()), messageContext);
                 }
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org