package org.ehcache.impl.internal.sizeof.listeners;
import org.ehcache.impl.internal.sizeof.listeners.exceptions.VisitorListenerException;
import org.ehcache.sizeof.VisitorListener;
public class EhcacheVisitorListener implements VisitorListener {
private final long maxObjectGraphSize;
private final long maxObjectSize;
private long currentDepth;
private long currentSize;
public EhcacheVisitorListener(long maxObjectGraphSize, long maxObjectSize) {
this.maxObjectGraphSize = maxObjectGraphSize;
this.maxObjectSize = maxObjectSize;
}
@Override
public void visited(Object object, long size) {
if((currentDepth += 1) > maxObjectGraphSize) {
throw new VisitorListenerException("Max Object Graph Size reached for the object : "+ object);
}
if((currentSize += size) > maxObjectSize) {
throw new VisitorListenerException("Max Object Size reached for the object : "+ object);
}
}
}