[jboss-cvs] JBossAS SVN: r64672 - 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
Fri Aug 17 18:55:04 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-08-17 18:55:04 -0400 (Fri, 17 Aug 2007)
New Revision: 64672
Modified:
branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces/NamingContext.java
Log:
[JBAS-4574] Expand flush/retry to all Context methods
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-17 19:55:01 UTC (rev 64671)
+++ branches/JBoss_4_0_5_GA_JBAS-4574/naming/src/main/org/jnp/interfaces/NamingContext.java 2007-08-17 22:55:04 UTC (rev 64672)
@@ -509,7 +509,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)
{
@@ -565,7 +582,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)
{
@@ -626,29 +661,19 @@
{
try
{
- res = naming.lookup(n);
+ res = naming.lookup(n);
}
catch (RemoteException re)
{
- // JBAS-4574. Check for the case when the server has been restarted
- // while the cached naming stub hasn't been dgc-ed yet.
- // We will simply flush out the server from cache
- // and do another try. BW.
- if (re instanceof NoSuchObjectException
- || re.getCause() instanceof NoSuchObjectException)
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
{
- if( trace )
- log.trace("Call failed with NoSuchObjectException, " +
- "flushing server cache and retrying", re);
- naming = null;
- removeServer(refEnv);
-
- checkRef(refEnv);
+ // try again with new naming stub
res = naming.lookup(n);
}
else
{
- // Not JBAS-4574. Throw it on and let outer logic handle it.
+ // Not JBAS-4574. Throw exception and let outer logic handle it.
throw re;
}
}
@@ -779,7 +804,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)
{
@@ -827,7 +869,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)
{
@@ -863,7 +924,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
@@ -969,7 +1049,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)
{
@@ -1049,12 +1146,35 @@
{
if (name.isEmpty())
return lookup(name);
+
+ Hashtable refEnv = getEnv(name);
+ checkRef(refEnv);
+ Name parsedName = (Name) refEnv.get(JNP_PARSED_NAME);
+ if (parsedName != null)
+ name = parsedName;
Object link = null;
try
{
Name n = getAbsoluteName(name);
- link = naming.lookup(n);
+ try
+ {
+ link = naming.lookup(n);
+ }
+ catch (RemoteException re)
+ {
+ // Check for JBAS-4574.
+ if (handleStaleNamingStub(re, refEnv))
+ {
+ // 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);
;
@@ -1508,6 +1628,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