[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/interceptors ...
Ben Wang
bwang at jboss.com
Wed Aug 2 06:28:41 EDT 2006
User: bwang
Date: 06/08/02 06:28:41
Added: src-50/org/jboss/cache/pojo/interceptors
MethodReentrancyStopperInterceptor.java
Log:
JBCACHE-694 Recurive toString
Revision Changes Path
1.1 date: 2006/08/02 10:28:41; author: bwang; state: Exp;JBossCache/src-50/org/jboss/cache/pojo/interceptors/MethodReentrancyStopperInterceptor.java
Index: MethodReentrancyStopperInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.interceptors;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.lang.reflect.Method;
/**
*
* @author Ben Wang
*/
public class MethodReentrancyStopperInterceptor implements Interceptor
{
private final Log log_ = LogFactory.getLog(MethodReentrancyStopperInterceptor.class);
ThreadLocal<Boolean> done;
public MethodReentrancyStopperInterceptor()
{
done = new ThreadLocal<Boolean>();
done.set(false);
}
public String getName()
{
return MethodReentrancyStopperInterceptor.class.getName();
}
public Object invoke(Invocation invocation) throws Throwable
{
boolean wasDone = done.get();
try
{
if (!wasDone)
{
done.set(true);
return invocation.invokeNext();
} else
{
//Needs adding, and will invoke target joinpoint skipping the rest of the chain
if(log_.isDebugEnabled())
{
Method method = ((MethodInvocation)invocation).getMethod();
log_.debug("Detect recursive interception. Will call the target directly: " +method.getName());
}
return invocation.getTargetObject().getClass().getName();
}
}
finally
{
if (!wasDone)
{
done.set(false);
}
}
}
}
More information about the jboss-cvs-commits
mailing list