[jboss-cvs] JBossAS SVN: r111991 - projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/interfaces.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 10 16:15:11 EDT 2011


Author: dereed
Date: 2011-08-10 16:15:11 -0400 (Wed, 10 Aug 2011)
New Revision: 111991

Modified:
   projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java
Log:
[JBNAME-51] Add optional flag to use an available cached connection before trying every provider in order again. 


Modified: projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java
===================================================================
--- projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java	2011-08-10 19:38:23 UTC (rev 111990)
+++ projects/naming/branches/Branch_5_0/jnpserver/src/main/java/org/jnp/interfaces/NamingContext.java	2011-08-10 20:15:11 UTC (rev 111991)
@@ -158,13 +158,28 @@
     * The name to associate with Naming instance to use for the root Context
     */ 
    public static final String JNP_NAMING_INSTANCE_NAME = "jnp.namingInstanceName";
+   /**
+    * Whether or not the order of the provider list is significant.  Default behavior
+    * assumes that it is which can lead to bad behavior if one of the initial URLs is
+    * not contactable.
+    */ 
+   public static final String JNP_UNORDERED_PROVIDER_LIST = "jnp.unorderedProviderList";
 
    /**
-    * Global JNP disable discovery system property: -Djboss.global.jnp.disableDiscover=[true|false]
+    * Global JNP disable discovery system property: -Djboss.global.jnp.disableDiscovery=[true|false]
     * At the VM level, this property controls how disable discovery behaves in 
     * absence of per context jnp.disableDiscovery property.  
     */
    private static final boolean GLOBAL_JNP_DISABLE_DISCOVERY = Boolean.valueOf(System.getProperty("jboss.global.jnp.disableDiscovery", "false"));
+
+   /**
+    * Global JNP unordered provider list system property:
+    *    -Djboss.global.jnp.unorderedProviderList=[true|false]
+    * At the VM level, this property controls how unordered provider list behaves
+    * in absence of per context jnp.unorderedProviderList.  Default is false.
+    */
+   private static final String GLOBAL_UNORDERED_PROVIDER_LIST =
+        System.getProperty("jboss.global.jnp.unorderedProviderList", "false");
    
    /**
     * The default discovery multicast information
@@ -268,6 +283,12 @@
    static Naming getServer(String host, int port, Hashtable serverEnv)
       throws NamingException
    {
+      return getServer(host, port, serverEnv, false);
+   }
+
+   static Naming getServer(String host, int port, Hashtable serverEnv, boolean cachedOnly)
+      throws NamingException
+   {
       // Check the server cache for a host:port entry
       InetSocketAddress key = new InetSocketAddress(host, port);
       WeakReference<Naming> ref = cachedServers.get(key);
@@ -284,6 +305,9 @@
          }
       }
 
+      if ( cachedOnly )
+         return null;
+
       // Server not found; add it to cache
       try
       {
@@ -1727,28 +1751,69 @@
          {
             StringTokenizer tokenizer = new StringTokenizer(urls, ",");
 
-            while (naming == null && tokenizer.hasMoreElements())
+            // If provider list is unordered, first check for a cached connection to any provider
+            String unorderedProviderList = (String) refEnv.get(JNP_UNORDERED_PROVIDER_LIST);
+
+            // If unset, set to global which defaults to false.
+            if (unorderedProviderList == null)
+	    {
+	        unorderedProviderList = GLOBAL_UNORDERED_PROVIDER_LIST;
+            }
+
+            if ( Boolean.valueOf(unorderedProviderList) == Boolean.TRUE )
             {
-               String url = tokenizer.nextToken();
-               // Parse the url into a host:port form, stripping any protocol
-               Name urlAsName = getNameParser("").parse(url);
-               String server = parseNameForScheme(urlAsName, null);
-               if (server != null)
-                  url = server;
-               // 
-               Object[] hostAndPort = {url, 0};
-               parseHostPort(url, hostAndPort, 1099);
-               host = (String) hostAndPort[HOST_INDEX];
-               port = (Integer) hostAndPort[PORT_INDEX];
-               try
+               while (naming == null && tokenizer.hasMoreElements())
                {
-                  // Get server from cache
-                  naming = getServer(host, port, refEnv);
+                  String url = tokenizer.nextToken();
+                  // Parse the url into a host:port form, stripping any protocol
+                  Name urlAsName = getNameParser("").parse(url);
+                  String server = parseNameForScheme(urlAsName, null);
+                  if (server != null)
+                     url = server;
+                  // 
+                  Object[] hostAndPort = {url, 0};
+                  parseHostPort(url, hostAndPort, 1099);
+                  host = (String) hostAndPort[HOST_INDEX];
+                  port = (Integer) hostAndPort[PORT_INDEX];
+                  try
+                  {
+                     // Get server from cache
+                     naming = getServer(host, port, refEnv, true);
+                  }
+                  catch (Exception e)
+                  {
+                     serverEx = e;
+                     log.trace("Error retrieving cached connection to " + host + ":" + port, e);
+                  }
                }
-               catch (Exception e)
+               tokenizer = new StringTokenizer(urls, ",");
+            }
+
+            if (naming == null)
+            {
+               while (naming == null && tokenizer.hasMoreElements())
                {
-                  serverEx = e;
-                  log.debug("Failed to connect to " + host + ":" + port, e);
+                  String url = tokenizer.nextToken();
+                  // Parse the url into a host:port form, stripping any protocol
+                  Name urlAsName = getNameParser("").parse(url);
+                  String server = parseNameForScheme(urlAsName, null);
+                  if (server != null)
+                     url = server;
+                  // 
+                  Object[] hostAndPort = {url, 0};
+                  parseHostPort(url, hostAndPort, 1099);
+                  host = (String) hostAndPort[HOST_INDEX];
+                  port = (Integer) hostAndPort[PORT_INDEX];
+                  try
+                  {
+                     // Get server from cache
+                     naming = getServer(host, port, refEnv);
+                  }
+                  catch (Exception e)
+                  {
+                     serverEx = e;
+                     log.debug("Failed to connect to " + host + ":" + port, e);
+                  }
                }
             }
 



More information about the jboss-cvs-commits mailing list