[jboss-cvs] JBossAS SVN: r64720 - trunk/naming/src/main/org/jnp/interfaces.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 20 15:44:19 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-08-20 15:44:19 -0400 (Mon, 20 Aug 2007)
New Revision: 64720
Modified:
trunk/naming/src/main/org/jnp/interfaces/NamingContext.java
Log:
[JBAS-4615] Clean naming stub cache after NoSuchObjectException
Modified: trunk/naming/src/main/org/jnp/interfaces/NamingContext.java
===================================================================
--- trunk/naming/src/main/org/jnp/interfaces/NamingContext.java 2007-08-20 19:38:45 UTC (rev 64719)
+++ trunk/naming/src/main/org/jnp/interfaces/NamingContext.java 2007-08-20 19:44:19 UTC (rev 64720)
@@ -34,6 +34,8 @@
import java.net.InetSocketAddress;
import java.rmi.ConnectException;
import java.rmi.MarshalledObject;
+import java.rmi.NoSuchObjectException;
+import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -56,7 +58,6 @@
import javax.naming.NamingException;
import javax.naming.NotContextException;
import javax.naming.ContextNotEmptyException;
-import javax.naming.OperationNotSupportedException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.ServiceUnavailableException;
@@ -511,7 +512,24 @@
{
className = ((Reference) obj).getClassName();
}
- naming.rebind(getAbsoluteName(name), obj, className);
+ try
+ {
+ naming.rebind(getAbsoluteName(name), obj, className);
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ naming.rebind(getAbsoluteName(name), obj, className);
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
}
catch (CannotProceedException cpe)
{
@@ -568,7 +586,25 @@
className = ((Reference) obj).getClassName();
}
name = getAbsoluteName(name);
- naming.bind(name, obj, className);
+
+ try
+ {
+ naming.bind(name, obj, className);
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ naming.bind(name, obj, className);
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
}
catch (CannotProceedException cpe)
{
@@ -627,7 +663,25 @@
{
try
{
- res = naming.lookup(n);
+ try
+ {
+ res = naming.lookup(n);
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ res = naming.lookup(n);
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
+ // If we got here, we succeeded, so break the loop
break;
}
catch (ConnectException ce)
@@ -754,7 +808,24 @@
try
{
- naming.unbind(getAbsoluteName(name));
+ try
+ {
+ naming.unbind(getAbsoluteName(name));
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ naming.unbind(getAbsoluteName(name));
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
}
catch (CannotProceedException cpe)
{
@@ -802,7 +873,26 @@
try
{
- return new NamingEnumerationImpl(naming.list(getAbsoluteName(name)));
+ Collection c = null;
+ try
+ {
+ c = naming.list(getAbsoluteName(name));
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ c = naming.list(getAbsoluteName(name));
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
+ return new NamingEnumerationImpl(c);
}
catch (CannotProceedException cpe)
{
@@ -838,7 +928,26 @@
try
{
// Get list
- Collection bindings = naming.listBindings(getAbsoluteName(name));
+ Collection bindings = null;
+ try
+ {
+ // Get list
+ bindings = naming.listBindings(getAbsoluteName(name));
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ bindings = naming.listBindings(getAbsoluteName(name));
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
Collection realBindings = new ArrayList(bindings.size());
// Convert marshalled objects
@@ -944,7 +1053,24 @@
try
{
name = getAbsoluteName(name);
- return naming.createSubcontext(name);
+ try
+ {
+ return naming.createSubcontext(name);
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // try again with new naming stub
+ return naming.createSubcontext(name);
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
}
catch (CannotProceedException cpe)
{
@@ -1027,6 +1153,8 @@
public Object lookupLink(Name name)
throws NamingException
{
+ // FIXME JBAS-4616
+
if (name.isEmpty())
return lookup(name);
@@ -1034,7 +1162,25 @@
try
{
Name n = getAbsoluteName(name);
- link = naming.lookup(n);
+ try
+ {
+ link = naming.lookup(n);
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ // TODO if we resolve JBAS-4616, need to use refEnv
+ if (handleStaleNamingStub(re, env))
+ {
+ // try again with new naming stub
+ link = naming.lookup(n);
+ }
+ else
+ {
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
+ throw re;
+ }
+ }
if (!(link instanceof LinkRef) && link instanceof Reference)
link = getObjectInstance(link, name, null);
;
@@ -1518,6 +1664,50 @@
}
return nameEnv;
}
+
+ /**
+ * JBAS-4574. Check if the given exception is because the server has
+ * been restarted while the cached naming stub hasn't been dgc-ed yet.
+ * If yes, we will flush out the naming stub from our cache and
+ * acquire a new stub. BW.
+ *
+ * @param e the exception that may be due to a stale stub
+ * @param refEnv the naming environment associated with the failed call
+ *
+ * @return <code>true</code> if <code>e</code> indicates a stale
+ * 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)
+ {
+ if (e instanceof NoSuchObjectException
+ || e.getCause() instanceof NoSuchObjectException)
+ {
+ try
+ {
+ if( log.isTraceEnabled() )
+ {
+ log.trace("Call failed with NoSuchObjectException, " +
+ "flushing server cache and retrying", e);
+ }
+ naming = null;
+ removeServer(refEnv);
+
+ checkRef(refEnv);
+
+ return true;
+ }
+ catch (Exception e1)
+ {
+ // Just log and return false; let caller continue processing
+ // the original exception passed in to this method
+ log.error("Caught exception flushing server cache and " +
+ "re-establish naming after exception " +
+ e.getLocalizedMessage(), e1);
+ }
+ }
+ return false;
+ }
// Inner classes -------------------------------------------------
}
More information about the jboss-cvs-commits
mailing list