[jboss-cvs] JBossAS SVN: r64647 - branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 16 22:14:32 EDT 2007


Author: ben.wang at jboss.com
Date: 2007-08-16 22:14:32 -0400 (Thu, 16 Aug 2007)
New Revision: 64647

Modified:
   branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces/NamingContext.java
Log:
Added exception catching for NoSuchObject and RemoteException to retry for lookup

Modified: branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces/NamingContext.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces/NamingContext.java	2007-08-16 23:24:14 UTC (rev 64646)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces/NamingContext.java	2007-08-17 02:14:32 UTC (rev 64647)
@@ -620,11 +620,36 @@
          boolean trace = log.isTraceEnabled();
          for (int i = 0; i < maxTries; i++)
          {
+            if( trace )
+               log.trace("Retyring , retry count: "+i);
             try
             {
                res = naming.lookup(n);
                break;
             }
+            // This is the case when the server has been restarted
+            // while the stub hasn't been dgc-ed yet. 
+            // We will simply flush out the server from cache
+            // and do another try. BW.
+            catch (java.rmi.NoSuchObjectException nsoe)
+            {
+               // Even if maxTries is 1, we will still retry it here.
+               int retries = maxTries - i;
+               if( trace )
+                  log.trace("Connect failed with NoSuchObjectException, retry count: "+retries, nsoe);
+               // let's flush the bad server first.
+               if (retries > 0)
+               {
+                  removeServer(refEnv);
+                  naming = null;
+                  checkRef(refEnv);
+
+                  res = naming.lookup(n);
+                  break;
+               }
+               // Still can't resolve the exception. Throw the exception to flush the bad server
+               throw nsoe;
+            }
             catch (ConnectException ce)
             {
                int retries = maxTries - i - 1;
@@ -645,6 +670,28 @@
                // Throw the exception to flush the bad server
                throw ce;
             }
+            catch (java.rmi.RemoteException ioe)
+            {
+               if(ioe.getCause() instanceof java.rmi.NoSuchObjectException)
+               {
+                  // Even if maxTries is 1, we will still retry it here.
+                  int retries = maxTries - i;
+                  if( trace )
+                     log.trace("Connect failed with NoSuchObjectException, retry count: "+retries, ioe.getCause());
+                  // let's flush the bad server first.
+                  if (retries > 0)
+                  {
+                     removeServer(refEnv);
+                     naming = null;
+                     checkRef(refEnv);
+
+                     res = naming.lookup(n);
+                     break;
+                  }
+                  // Still can't resolve the exception. Throw the exception to flush the bad server
+                  throw ioe;
+               }
+            }
          }
          if (res instanceof MarshalledValuePair)
          {




More information about the jboss-cvs-commits mailing list