[jboss-cvs] JBossAS SVN: r65550 - branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Sep 22 01:19:05 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-09-22 01:19:05 -0400 (Sat, 22 Sep 2007)
New Revision: 65550
Modified:
branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java
Log:
[JBAS-4740] Wrap the cause of ServiceUnavailable, giving preference to wrapping NoSuchObjectException
Modified: branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java
===================================================================
--- branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java 2007-09-22 05:17:57 UTC (rev 65549)
+++ branches/Branch_4_2/cluster/src/main/org/jboss/ha/framework/interfaces/HARMIClient.java 2007-09-22 05:19:05 UTC (rev 65550)
@@ -26,6 +26,10 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
+import java.rmi.ConnectException;
+import java.rmi.ConnectIOException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.UnknownHostException;
import java.util.ArrayList;
import org.jboss.invocation.MarshalledInvocation;
@@ -154,13 +158,56 @@
}
+ /**
+ * Invoke the given method against a remote server. If the call results
+ * in certain {@link RemoteException} subtypes, catch the exception and
+ * attempt to fail over to another server.
+ * <p>
+ * Failover will only be attempted if the remote call throws an exception
+ * whose type indicates the call never reached the server:
+ * <ul>
+ * <li>{@link java.rmi.ConnectException}</li>
+ * <li>{@link java.rmi.ConnectIOException}</li>
+ * <li>{@link java.rmi.NoSuchObjectException}</li>
+ * <li>{@link java.rmi.UnknownHostException}</li>
+ * </ul>
+ * </p>
+ * <p>
+ * All other exception types will not be caught.
+ * </p>
+ * <p>
+ * If one of the above exception types is caught when invoking against the
+ * last known server, then a {@link RemoteException} will be thrown. This
+ * exception will include as its {@link Throwable#getCause() cause} either
+ * <ol>
+ * <li>any {@link java.rmi.NoSuchObjectException} that was caught</li>
+ * <li>or, if no {@link java.rmi.NoSuchObjectException} that was caught,
+ * the exception thrown on the last failover attempt</li>
+ * </ol>
+ * Preference is given to including <code>NoSuchObjectException</code> as
+ * the cause, as that exception indicates that a server was listening on
+ * the expected address and port but that this client has an RMI stub that
+ * is out of sync with the server. This would typically happen due to
+ * a server restart or service redeploy. Knowledge of this failure condition
+ * could potentially be useful to the caller.
+ * </p>
+ *
+ * @param proxy the proxy object that's being invoked
+ * @param method the method to invoke
+ * @param args arguments to the method
+ * @return any return value from the invocation, or <code>null</code>
+ *
+ * @throws Throwable Throwable thrown when making remote call, or the
+ * <code>RemoteException</code> discussed above.
+ */
public Object invokeRemote(Object proxy, Method method, Object[] args) throws Throwable
{
boolean trace = log.isTraceEnabled();
HARMIServer target = (HARMIServer)getRemoteTarget();
+ NoSuchObjectException nsoe = null;
+ Exception lastException = null;
while (target != null)
{
- Exception lastException = null;
try
{
if( trace )
@@ -183,19 +230,21 @@
return rsp.response;
}
- catch (java.rmi.ConnectException e)
+ catch (ConnectException e)
{
lastException = e;
}
- catch (java.rmi.ConnectIOException e)
+ catch (ConnectIOException e)
{
lastException = e;
}
- catch (java.rmi.NoSuchObjectException e)
+ catch (NoSuchObjectException e)
{
+ // JBAS-4740 preserve this exception
+ nsoe = e;
lastException = e;
}
- catch (java.rmi.UnknownHostException e)
+ catch (UnknownHostException e)
{
lastException = e;
}
@@ -206,7 +255,10 @@
target = (HARMIServer)getRemoteTarget();
}
// if we get here this means list was exhausted
- throw new java.rmi.RemoteException("Service unavailable.");
+ // JBAS-4740 wrap any NSOE in preference to 'lastException' since
+ // an NSOE indicates a server was running
+ Exception toWrap = (nsoe == null) ? lastException : nsoe;
+ throw new java.rmi.RemoteException("Service unavailable.", toWrap);
}
@@ -219,6 +271,12 @@
// InvocationHandler implementation ----------------------------------------------
+ /**
+ * Invoke the given method, locally if possible; if not then
+ * {@link #invokeRemote(Object, Method, Object[]) invoke against a remote server}.
+ *
+ * @see #invokeRemote(Object, Method, Object[])
+ */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
// The isLocal call is handled by the proxy
More information about the jboss-cvs-commits
mailing list