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 da...@apache.org on 2008/01/15 10:58:15 UTC

svn commit: r612065 - /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java

Author: davidillsley
Date: Tue Jan 15 01:58:14 2008
New Revision: 612065

URL: http://svn.apache.org/viewvc?rev=612065&view=rev
Log:
AXIS2-3283

Add accessor to determine if any operation contexts are
currently registered and remove synchronization blocks
in favour of a ConcurrentHashMap.

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java?rev=612065&r1=612064&r2=612065&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java Tue Jan 15 01:58:14 2008
@@ -40,6 +40,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
@@ -48,7 +50,6 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 /**
  * <p>Axis2 states are held in two information models, called description hierarchy
@@ -70,7 +71,7 @@
      * Map containing <code>MessageID</code> to
      * <code>OperationContext</code> mapping.
      */
-    private final Map operationContextMap = new HashMap();
+    private final ConcurrentHashMap operationContextMap = new ConcurrentHashMap();
     private Hashtable serviceGroupContextMap = new Hashtable();
     private Hashtable applicationSessionServiceGroupContexts = new Hashtable();
     private AxisConfiguration axisConfiguration;
@@ -309,26 +310,34 @@
     public boolean registerOperationContext(String messageID, 
                                             OperationContext mepContext, 
                                             boolean override) {
-        boolean alreadyInMap;
+    	
+    	if(messageID == null){
+    		if(log.isDebugEnabled()){
+    			log.debug("messageID is null. Returning false");
+    		}
+    		return false;
+    	}
+    	
+        boolean alreadyInMap = false;
         mepContext.setKey(messageID);
-        synchronized (operationContextMap) {
-            alreadyInMap = operationContextMap.containsKey(messageID);
-            if (!alreadyInMap || override) {
-                this.operationContextMap.put(messageID, mepContext);
-            }
 
-            if (log.isDebugEnabled())
-            {
-                log.debug("registerOperationContext ("+override+"): "+
-                          mepContext+" with key: "+messageID);
-                HashMap msgContextMap = mepContext.getMessageContexts();
-                Iterator msgContextIterator = msgContextMap.values().iterator();
-                while (msgContextIterator.hasNext())
-                {
-                    MessageContext msgContext = (MessageContext)msgContextIterator.next();
-                    log.debug("msgContext: "+msgContext+" action: "+msgContext.getWSAAction());
-                }
-            }
+        if(override){
+        	operationContextMap.put(messageID, mepContext);
+        }else{
+        	Object previous = operationContextMap.putIfAbsent(messageID, mepContext);
+        	alreadyInMap = (previous!=null);
+        }
+        if (log.isDebugEnabled())
+        {
+        	log.debug("registerOperationContext ("+override+"): "+
+        			mepContext+" with key: "+messageID);
+        	HashMap msgContextMap = mepContext.getMessageContexts();
+        	Iterator msgContextIterator = msgContextMap.values().iterator();
+        	while (msgContextIterator.hasNext())
+        	{
+        		MessageContext msgContext = (MessageContext)msgContextIterator.next();
+        		log.debug("msgContext: "+msgContext+" action: "+msgContext.getWSAAction());
+        	}
         }
         return (!alreadyInMap || override);
     }
@@ -338,13 +347,20 @@
      * @param key
      */
     public void unregisterOperationContext(String key) {
-        synchronized (operationContextMap) {
-            OperationContext opCtx = (OperationContext) operationContextMap.get(key);
-            operationContextMap.remove(key);
-            contextRemoved(opCtx);
-        }
+    	if(key == null){
+    		if(log.isDebugEnabled()){
+    			log.debug("key is null.");
+    		}
+    	}else{
+    		OperationContext opCtx = (OperationContext) operationContextMap.remove(key);
+    		contextRemoved(opCtx);
+    	}
     }
 
+    public boolean isAnyOperationContextRegistered(){
+    	return !operationContextMap.isEmpty();
+    }
+    
     /**
      * Adds the given ServiceGroupContext into the SOAP session table
      * 
@@ -402,14 +418,7 @@
      * @param id
      */
     public OperationContext getOperationContext(String id) {
-        OperationContext opCtx;
-        synchronized (operationContextMap) {
-            if (operationContextMap == null) {
-                return null;
-            }
-            opCtx = (OperationContext) this.operationContextMap.get(id);
-        }
-
+        OperationContext opCtx = (OperationContext) this.operationContextMap.get(id);
         return opCtx;
     }
 
@@ -434,39 +443,36 @@
         // group name is not necessarily a prereq
         // but if the group name is non-null, then it has to match
 
-        synchronized (operationContextMap) {
-            Iterator it = operationContextMap.keySet().iterator();
+        Iterator it = operationContextMap.values().iterator();
 
-            while (it.hasNext()) {
-                Object key = it.next();
-                OperationContext value = (OperationContext) operationContextMap.get(key);
-
-                String valueOperationName;
-                String valueServiceName;
-                String valueServiceGroupName;
-
-                if (value != null) {
-                    valueOperationName = value.getOperationName();
-                    valueServiceName = value.getServiceName();
-                    valueServiceGroupName = value.getServiceGroupName();
-
-                    if ((valueOperationName != null) && (valueOperationName.equals(operationName))) {
-                        if ((valueServiceName != null) && (valueServiceName.equals(serviceName))) {
-                            if ((valueServiceGroupName != null) && (serviceGroupName != null)
-                                && (valueServiceGroupName.equals(serviceGroupName))) {
-                                // match
-                                return value;
-                            }
-
-                            // or, both need to be null
-                            if ((valueServiceGroupName == null) && (serviceGroupName == null)) {
-                                // match
-                                return value;
-                            }
-                        }
-                    }
-                }
-            }
+        while (it.hasNext()) {
+        	OperationContext value = (OperationContext) it.next();
+
+        	String valueOperationName;
+        	String valueServiceName;
+        	String valueServiceGroupName;
+
+        	if (value != null) {
+        		valueOperationName = value.getOperationName();
+        		valueServiceName = value.getServiceName();
+        		valueServiceGroupName = value.getServiceGroupName();
+
+        		if ((valueOperationName != null) && (valueOperationName.equals(operationName))) {
+        			if ((valueServiceName != null) && (valueServiceName.equals(serviceName))) {
+        				if ((valueServiceGroupName != null) && (serviceGroupName != null)
+        						&& (valueServiceGroupName.equals(serviceGroupName))) {
+        					// match
+        					return value;
+        				}
+
+        				// or, both need to be null
+        				if ((valueServiceGroupName == null) && (serviceGroupName == null)) {
+        					// match
+        					return value;
+        				}
+        			}
+        		}
+        	}
         }
 
         // if we got here, we did not find an operation context



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