[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/interceptors/dynamic ...
Ben Wang
bwang at jboss.com
Wed Aug 2 11:42:49 EDT 2006
User: bwang
Date: 06/08/02 11:42:49
Added: src-50/org/jboss/cache/pojo/interceptors/dynamic
ReentrancyStopperInterceptor.java
Log:
Added interceptor to check for recursive Collection pojo
Revision Changes Path
1.1 date: 2006/08/02 15:42:49; author: bwang; state: Exp;JBossCache/src-50/org/jboss/cache/pojo/interceptors/dynamic/ReentrancyStopperInterceptor.java
Index: ReentrancyStopperInterceptor.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.interceptors.dynamic;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.FieldInvocation;
import org.jboss.aop.advice.Interceptor;
import java.lang.reflect.Field;
/**
* Main dynamic interceptor to intercept for field replication.
*
* @author Ben Wang
*/
public class ReentrancyStopperInterceptor implements Interceptor
{
private final Log log_ = LogFactory.getLog(ReentrancyStopperInterceptor.class);
ThreadLocal<Boolean> done;
public ReentrancyStopperInterceptor()
{
done = new ThreadLocal();
done.set(false);
}
public String getName()
{
return ReentrancyStopperInterceptor.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())
{
Field field = ((FieldInvocation)invocation).getField();
log_.debug("Detect recursive interception. Will call the target directly: " +field.getName());
}
return invocation.invokeTarget();
}
}
finally
{
if (!wasDone)
{
done.set(false);
}
}
}
}
More information about the jboss-cvs-commits
mailing list