harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r574157 - /harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
Date Mon, 10 Sep 2007 07:32:55 GMT
Author: leoli
Date: Mon Sep 10 00:32:55 2007
New Revision: 574157

URL: http://svn.apache.org/viewvc?rev=574157&view=rev
Log:
Apply patch for ([classlib][jndi] InitialContext.getURLOrDefaultInitCtx() optimization).

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java?rev=574157&r1=574156&r2=574157&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
Mon Sep 10 00:32:55 2007
@@ -17,6 +17,7 @@
 
 package javax.naming;
 
+import java.util.HashMap;
 import java.util.Hashtable;
 import javax.naming.spi.NamingManager;
 
@@ -351,10 +352,20 @@
         String scheme = UrlParser.getScheme(name);
         Context ctx = null;
         if (null != scheme) {
-            // So the first component is a valid URL
-            ctx = NamingManager.getURLContext(scheme, myProps);
+            synchronized (contextCache) {
+                if (contextCache.containsKey(scheme)) {
+                    return contextCache.get(scheme);
+                }
+
+                // So the first component is a valid URL
+                ctx = NamingManager.getURLContext(scheme, myProps);
+                if (null == ctx) {
+                    ctx = getDefaultInitCtx();
+                }
+                contextCache.put(scheme, ctx);                
+            }
         }
-        return null == ctx ? getDefaultInitCtx() : ctx;
+        return getDefaultInitCtx();
     }
 
     public Object lookup(Name name) throws NamingException {
@@ -493,13 +504,19 @@
     }
 
     public Object addToEnvironment(String propName, Object propVal)
-            throws NamingException {
-        this.myProps.put(propName, propVal);
+            throws NamingException {        
+        synchronized (contextCache) {
+            myProps.put(propName, propVal);
+            contextCache.clear();
+        }
         return getDefaultInitCtx().addToEnvironment(propName, propVal);
     }
 
     public Object removeFromEnvironment(String propName) throws NamingException {
-        this.myProps.remove(propName);
+        synchronized (contextCache) {
+            myProps.remove(propName);
+            contextCache.clear();
+        }
         return getDefaultInitCtx().removeFromEnvironment(propName);
     }
 
@@ -516,5 +533,7 @@
     public String getNameInNamespace() throws NamingException {
         return getDefaultInitCtx().getNameInNamespace();
     }
-
+    
+    
+    private HashMap<String, Context> contextCache = new HashMap<String, Context>();
  
 }



Mime
View raw message