Author: manik.surtani(a)jboss.com
Date: 2009-02-19 08:21:22 -0500 (Thu, 19 Feb 2009)
New Revision: 7733
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
Log:
JBCACHE-1482: ActivationInterceptor leaks memory
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
---
core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2009-02-19
13:07:43 UTC (rev 7732)
+++
core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2009-02-19
13:21:22 UTC (rev 7733)
@@ -4,7 +4,6 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Modification;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.AbstractVisitor;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
import org.jboss.cache.commands.read.GetKeysCommand;
@@ -19,7 +18,6 @@
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
@@ -45,7 +43,6 @@
protected TransactionManager txMgr = null;
private long activations = 0;
- ActivationModificationsBuilder builder;
/**
* List<Transaction> that we have registered for
@@ -65,12 +62,6 @@
this.txMgr = txMgr;
}
- @Start
- public void createModificationsBuilder()
- {
- builder = new ActivationModificationsBuilder();
- }
-
@Override
public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command)
throws Throwable
{
@@ -297,95 +288,9 @@
}
List<Modification> cacheLoaderModifications = new
ArrayList<Modification>();
- builder.visitCollection(ctx, entry.getModifications());
if (cacheLoaderModifications.size() > 0)
{
loader.prepare(gtx, cacheLoaderModifications, false);
}
}
-
- public class ActivationModificationsBuilder extends AbstractVisitor
- {
-
- private List<Modification> cacheLoaderModifications = new
ArrayList<Modification>();
- private int txActs = 0;
-
- @Override
- public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand
removeNodeCommand) throws Throwable
- {
- Modification mod = new Modification(Modification.ModificationType.REMOVE_NODE,
removeNodeCommand.getFqn());
- cacheLoaderModifications.add(mod);
- return null;
- }
-
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand
command) throws Throwable
- {
- Fqn fqn = command.getFqn();
- handlePutCommand(ctx, fqn);
- return null;
- }
-
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
- {
- Fqn fqn = command.getFqn();
- handlePutCommand(ctx, fqn);
- return null;
- }
-
- // On the way out, remove the node from the cache loader.
- // Only remove the node if it exists in memory, its attributes have
- // been initialized, its children have been loaded
- // AND it was found in the cache loader (nodeLoaded = true).
- // Then notify the listeners that the node has been activated.
- private void handlePutCommand(InvocationContext ctx, Fqn fqn)
- throws Exception
- {
- if (fqn != null && dataContainer.peek(fqn, false, false) != null
&& loader.exists(fqn))
- {
- NodeSPI n = dataContainer.peek(fqn, true, false);// don't load
- // node not null and attributes have been loaded?
- if (n != null && n.isDataLoaded())
- {
- // has children?
- boolean result = childrenLoaded(n);
- if (!n.getChildrenDirect().isEmpty() && result)
- {
- // children have been loaded, remove the node
- addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getDataDirect());
- txActs++;
- }
- // doesn't have children, check the cache loader
- else if (loaderNoChildren(fqn))
- {
- addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getDataDirect());
- txActs++;
- }
- }
- }
- }
-
- private boolean loaderNoChildren(Fqn fqn) throws Exception
- {
- return loader.getChildrenNames(fqn) != null;
- }
-
- private void addRemoveMod(InvocationContext ctx, List<Modification> l, Fqn
fqn, Map data)
- {
- Modification mod = new Modification(Modification.ModificationType.REMOVE_NODE,
fqn);
- l.add(mod);
- notifier.notifyNodeActivated(fqn, false, data, ctx);
- }
-
- public List<Modification> getCacheLoaderModifications()
- {
- return cacheLoaderModifications;
- }
-
- public int getTxActs()
- {
- return txActs;
- }
- }
}