[jboss-cvs] JBossCache/old/src/org/jboss/cache/aop/interceptors ...
Ben Wang
bwang at jboss.com
Tue Oct 31 03:01:16 EST 2006
User: bwang
Date: 06/10/31 03:01:16
Added: old/src/org/jboss/cache/aop/interceptors
PojoEvictionInterceptor.java
Log:
Deprecated files moved to old dir.
Revision Changes Path
1.1 date: 2006/10/31 08:01:16; author: bwang; state: Exp;JBossCache/old/src/org/jboss/cache/aop/interceptors/PojoEvictionInterceptor.java
Index: PojoEvictionInterceptor.java
===================================================================
package org.jboss.cache.aop.interceptors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.TreeCache;
import org.jboss.cache.DataNode;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.aop.AOPInstance;
import org.jboss.cache.aop.InternalDelegate;
import org.jboss.cache.eviction.EvictedEventNode;
import org.jboss.cache.eviction.NodeEventType;
import org.jboss.cache.eviction.Region;
import org.jboss.cache.interceptors.EvictionInterceptor;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.marshall.MethodCall;
import java.util.Iterator;
import java.util.Set;
/**
* AOP specific eviction interceptor implementation.
*
* @author Daniel Huang (dhuang at jboss.org)
*/
public class PojoEvictionInterceptor extends EvictionInterceptor
{
private static final Log log_ = LogFactory.getLog(PojoEvictionInterceptor.class);
private TreeCache cache = null;
public PojoEvictionInterceptor()
{
super();
// now override the handler lookup map with AOP specific handlers.
EvictionMethodHandler handler = new PojoGetNodeEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.getNodeMethodLocal_id, handler);
evictionMethodHandlers.put(MethodDeclarations.getDataMapMethodLocal_id, handler);
handler = new PojoGetKeyEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.getKeyValueMethodLocal_id, handler);
handler = new PojoRemoveNodeEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.removeNodeMethodLocal_id, handler);
evictionMethodHandlers.put(MethodDeclarations.removeDataMethodLocal_id, handler);
handler = new PojoRemoveKeyEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.removeKeyMethodLocal_id, handler);
handler = new PojoPutDataEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.putDataMethodLocal_id, handler);
handler = new PojoPutDataEraseEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.putDataEraseMethodLocal_id, handler);
handler = new PojoPutKeyEvictionMethodHandler();
evictionMethodHandlers.put(MethodDeclarations.putKeyValMethodLocal_id, handler);
}
public void setCache(CacheSPI cache)
{
super.setCache(cache);
}
boolean isAopNode(Fqn fqn)
{
// Use this API so it doesn't go thru the interceptor.
DataNode node;
node = cache.peek(fqn);
return node.get(AOPInstance.KEY) != null;
}
private void visitChildrenRecursively(Region region, Fqn fqn)
{
Set set = null;
try
{
set = cache.getChildrenNames(fqn);
}
catch (CacheException e)
{
log_.error("Caught error", e);
}
int size = (set == null) ? 0 : set.size();
if (log_.isTraceEnabled())
{
log_.trace("nodeVisited(): is an aop node. fqn- " + fqn + " size of children is " + size);
}
if (set == null) return; // barren
Iterator it = set.iterator();
while (it.hasNext())
{
Object childName = it.next();
Fqn fqnKid = new Fqn(fqn, childName);
visitChildrenRecursively(region, fqnKid);
region.setVisitedNode(fqnKid);
}
}
private boolean isInternalNode(Fqn fqn)
{
return InternalDelegate.isInternalNode(fqn);
}
protected class PojoGetNodeEvictionMethodHandler extends GetNodeEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
EvictedEventNode event = super.extractEvictedEventNode(mc, retVal);
if (event != null)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[0];
Region region = regionManager.getRegion(fqn);
if (isAopNode(fqn))
{
visitChildrenRecursively(region, fqn);
}
if (fqn != null && !isInternalNode(fqn))
{
return new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT);
}
}
return null;
}
}
protected class PojoGetKeyEvictionMethodHandler extends GetKeyEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
EvictedEventNode event = super.extractEvictedEventNode(mc, retVal);
if (event != null)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[0];
Region region = regionManager.getRegion(fqn);
if (isAopNode(fqn))
{
visitChildrenRecursively(region, fqn);
}
if (fqn != null && !isInternalNode(fqn))
{
return new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT);
}
}
return null;
}
}
protected class PojoRemoveNodeEvictionMethodHandler extends RemoveNodeEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[1];
if (isInternalNode(fqn)) return null;
return super.extractEvictedEventNode(mc, retVal);
}
}
protected class PojoRemoveKeyEvictionMethodHandler extends RemoveKeyEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[1];
if (isInternalNode(fqn)) return null;
return super.extractEvictedEventNode(mc, retVal);
}
}
protected class PojoPutDataEvictionMethodHandler extends PutDataEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[1];
if (isInternalNode(fqn)) return null;
return super.extractEvictedEventNode(mc, retVal);
}
}
protected class PojoPutDataEraseEvictionMethodHandler extends PutDataEraseEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[1];
if (isInternalNode(fqn)) return null;
return super.extractEvictedEventNode(mc, retVal);
}
}
protected class PojoPutKeyEvictionMethodHandler extends PutKeyEvictionMethodHandler
{
public EvictedEventNode extractEvictedEventNode(MethodCall mc, Object retVal)
{
Object args[] = mc.getArgs();
Fqn fqn = (Fqn) args[1];
if (isInternalNode(fqn)) return null;
return super.extractEvictedEventNode(mc, retVal);
}
}
}
More information about the jboss-cvs-commits
mailing list