[jboss-cvs] JBossAS SVN: r63403 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/session.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 7 17:31:57 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-06-07 17:31:57 -0400 (Thu, 07 Jun 2007)
New Revision: 63403
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheWrapper.java
Log:
Clean up option and exception handling
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheWrapper.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheWrapper.java 2007-06-07 21:30:41 UTC (rev 63402)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/JBossCacheWrapper.java 2007-06-07 21:31:57 UTC (rev 63403)
@@ -27,23 +27,16 @@
import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
-import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
-import org.jboss.cache.config.Option;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.pojo.PojoCache;
public class JBossCacheWrapper
{
- static final Option GRAVITATE_OPTION = new Option();
- static final Option LOCAL_OPTION = new Option();
- static
- {
- GRAVITATE_OPTION.setForceDataGravitation(true);
- LOCAL_OPTION.setCacheModeLocal(true);
- }
-
private static final int RETRY = 3;
+ private static final String RETRY_FAIL_MSG =
+ "Continued to catch TimeoutException during " +
+ RETRY + " retry attempts. Giving up.";
private PojoCache pojoCache_;
private Cache plainCache_;
@@ -54,7 +47,7 @@
}
/**
- * Wrapper to embed retyr logic.
+ * Wrapper to embed retry logic.
*
* @param fqn
* @param id
@@ -66,7 +59,7 @@
}
/**
- * Wrapper to embed retyr logic.
+ * Wrapper to embed retry logic.
*
* @param fqn
* @param id
@@ -74,20 +67,16 @@
*/
Object get(Fqn fqn, String id, boolean gravitate)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
- InvocationContext ctx = null;
- Option existing = null;
try
- {
-
- Object value = null;
+ {
+ Object value = null;
if (gravitate)
{
- ctx = plainCache_.getInvocationContext();
- existing = ctx.getOptionOverrides();
- ctx.setOptionOverrides(GRAVITATE_OPTION);
+ plainCache_.getInvocationContext().getOptionOverrides()
+ .setForceDataGravitation(true);
value = plainCache_.get(fqn, id);
}
else
@@ -100,19 +89,9 @@
{
ex = e;
}
- catch (Exception e)
- {
- if (e instanceof RuntimeException)
- throw (RuntimeException) e;
- throw new RuntimeException("JBossCacheService: exception occurred in cache get ... ", e);
- }
- finally
- {
- if (ctx != null)
- ctx.setOptionOverrides(existing);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache get after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
/**
@@ -125,7 +104,7 @@
*/
void put(Fqn fqn, String id, Object value)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -137,12 +116,9 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache put ... ", e);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache put after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
@@ -154,7 +130,7 @@
*/
void put(Fqn fqn, Map map)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -166,16 +142,13 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache put ... ", e);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache put after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
/**
- * Wrapper to embed retyr logic.
+ * Wrapper to embed retry logic.
*
* @param fqn
* @param id
@@ -183,7 +156,7 @@
*/
Object remove(Fqn fqn, String id)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -194,12 +167,9 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache remove ... ", e);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache remove after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
/**
@@ -209,7 +179,7 @@
*/
void remove(Fqn fqn)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -221,12 +191,9 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache remove ... ", e);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache remove after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
/**
@@ -236,14 +203,13 @@
*/
void removeLocal(Fqn fqn)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
- InvocationContext ctx = plainCache_.getInvocationContext();
- Option existing = ctx.getOptionOverrides();
try
{
- ctx.setOptionOverrides(LOCAL_OPTION);
+ plainCache_.getInvocationContext().getOptionOverrides()
+ .setCacheModeLocal(true);
plainCache_.removeNode(fqn);
return;
}
@@ -251,16 +217,9 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache removeLocal ... ", e);
- }
- finally
- {
- ctx.setOptionOverrides(existing);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache removeLocal after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
/**
@@ -272,7 +231,7 @@
{
// FIXME remove this method if it remains unused
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -284,17 +243,14 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache evict ... ", e);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache evict after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
void evictSubtree(Fqn fqn)
{
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -325,12 +281,9 @@
{
ex = e;
}
- catch (RuntimeException e)
- {
- throw (RuntimeException) e;
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache evictSubtree after retry ... ", ex);
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
}
void removeLocalSubtree(Fqn fqn)
@@ -340,7 +293,7 @@
removeLocal(fqn);
// Next, clear any children
- Exception ex = null;
+ TimeoutException ex = null;
for (int i = 0; i < RETRY; i++)
{
try
@@ -373,12 +326,9 @@
{
ex = e;
}
- catch (Exception e)
- {
- throw new RuntimeException("JBossCacheService: exception occurred in cache removeLocal ... ", e);
- }
}
- throw new RuntimeException("JBossCacheService: exception occurred in cache removeLocalSubtree after retry ... ", ex);
- }
+
+ throw new RuntimeException(RETRY_FAIL_MSG, ex);
+ }
}
More information about the jboss-cvs-commits
mailing list