[jboss-cvs] JBossAS SVN: r64975 - branches/JBoss_4_0_5_GA_CP06_JBAS-4631/naming/src/main/org/jnp/interfaces.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 30 16:33:37 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-08-30 16:33:37 -0400 (Thu, 30 Aug 2007)
New Revision: 64975

Modified:
   branches/JBoss_4_0_5_GA_CP06_JBAS-4631/naming/src/main/org/jnp/interfaces/NamingContext.java
Log:
[JBAS-4631] Flush HA stub on any recoverable exception

Modified: branches/JBoss_4_0_5_GA_CP06_JBAS-4631/naming/src/main/org/jnp/interfaces/NamingContext.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP06_JBAS-4631/naming/src/main/org/jnp/interfaces/NamingContext.java	2007-08-30 19:56:28 UTC (rev 64974)
+++ branches/JBoss_4_0_5_GA_CP06_JBAS-4631/naming/src/main/org/jnp/interfaces/NamingContext.java	2007-08-30 20:33:37 UTC (rev 64975)
@@ -27,15 +27,18 @@
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
 import java.net.DatagramPacket;
 import java.net.InetAddress;
 import java.net.MulticastSocket;
 import java.net.Socket;
 import java.net.InetSocketAddress;
 import java.rmi.ConnectException;
+import java.rmi.ConnectIOException;
 import java.rmi.MarshalledObject;
 import java.rmi.NoSuchObjectException;
 import java.rmi.RemoteException;
+import java.rmi.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -1640,16 +1643,16 @@
     *         naming stub and we were able to succesfully flush the
     *         cache and acquire a new stub; <code>false</code> otherwise.
     */
-   private boolean handleStaleNamingStub(Exception e, Hashtable refEnv)
+   private boolean handleStaleNamingStub(RemoteException e, Hashtable refEnv)
    {
       if (e instanceof NoSuchObjectException
-            || e.getCause() instanceof NoSuchObjectException)
+            || isRecoverableHAMRIFailure(e.getCause()))
       {
          try
          {
             if( log.isTraceEnabled() )
             {
-               log.trace("Call failed with NoSuchObjectException, " +
+               log.trace("Call failed with recoverable RMI failure, " +
                          "flushing server cache and reaquiring Naming ref", e);
             }
             naming = null;
@@ -1670,6 +1673,34 @@
       }
       return false;
    }
+   
+   // FIXME. This is really ugly. We're basically coding in knowledge of
+   // how HARMIClient proxies work. We need some kind of typed exception
+   // from the proxy to tell us whether it's safe to retry
+   private boolean isRecoverableHAMRIFailure(Throwable t)
+   {
+      boolean isHARMI = false;
+      
+      // We can only recover if the failure is an RMI failure
+      // that doesn't allow the call to execute on the server
+      if (t instanceof ConnectException
+            || t instanceof ConnectIOException
+            || t instanceof NoSuchObjectException
+            || t instanceof UnknownHostException)
+      {
+         try
+         {
+            Object handler = Proxy.getInvocationHandler(naming);
+            isHARMI = "org.jboss.ha.framework.interfaces.HARMIClient".equals(handler.getClass().getName());
+         }
+         catch (Exception ignored)
+         {
+            // not HARMIClient
+         }
+      }
+      
+      return isHARMI;
+   }
 
    // Inner classes -------------------------------------------------
 }




More information about the jboss-cvs-commits mailing list