JBoss Cache SVN: r7196 - in core/trunk/src/main/java/org/jboss/cache: mvcc and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-25 07:21:15 -0500 (Tue, 25 Nov 2008)
New Revision: 7196
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java
Log:
Improvements in logging
By default all new nodes do not have their data loaded flags set
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-11-25 11:48:32 UTC (rev 7195)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-11-25 12:21:15 UTC (rev 7196)
@@ -270,7 +270,7 @@
ctx.getLookedUpNodes().remove(fqn);
n = null;
}
- boolean mustLoad = mustLoad(n, key, allKeys || isMove, shouldLoadIfNodeIsNull);
+ boolean mustLoad = mustLoad(fqn, n, key, allKeys || isMove, shouldLoadIfNodeIsNull);
if (trace) log.trace("load element " + fqn + " mustLoad=" + mustLoad);
@@ -392,11 +392,11 @@
node.setChildrenLoaded(true);
}
- private boolean mustLoad(NodeSPI n, Object key, boolean allKeys, boolean shouldLoadIfNodeIsNull)
+ private boolean mustLoad(Fqn fqn, NodeSPI n, Object key, boolean allKeys, boolean shouldLoadIfNodeIsNull)
{
if (n == null)
{
- if (trace) log.trace("Node null. Must load? " + shouldLoadIfNodeIsNull);
+ if (trace) log.trace("Node [" + fqn + "] is null in memory. Must load? " + shouldLoadIfNodeIsNull);
return shouldLoadIfNodeIsNull;
}
@@ -404,7 +404,10 @@
if (!n.isValid()) // && configuration.getNodeLockingScheme().isVersionedScheme())
{
// attempt to load again; this only happens if we have tombstones lying around, or we are using invalidation.
- if (trace) log.trace("loading again from cache loader since in-memory node is marked as invalid");
+ if (trace)
+ {
+ log.trace("Loading node [" + fqn + "] again from cache loader since in-memory node is marked as invalid");
+ }
return true;
}
@@ -414,20 +417,22 @@
// if we are not looking for a specific key don't bother loading!
if (key == null)
{
- if (trace) log.trace("don't load, key requested is null");
+ if (trace) log.trace("Don't load [" + fqn + "], key requested is null");
return false;
}
if (n.getKeysDirect().contains(key))
{
- if (trace) log.trace("don't load, already have necessary key in memory");
+ if (trace) log.trace("Don't load [" + fqn + "], already have necessary key in memory");
return false;
}
}
if (!n.isDataLoaded())
{
- if (trace) log.trace("must load, uninitialized");
+ if (trace) log.trace("Must load node [" + fqn + "], uninitialized");
return true;
}
+
+ if (trace) log.trace("Don't load node [" + fqn + "], by default");
return false;
}
@@ -468,10 +473,10 @@
private Map loadData(InvocationContext ctx, Fqn fqn) throws Exception
{
-
+ if (trace) log.trace("Attempting to load data for " + fqn);
Map nodeData = loader.get(fqn);
boolean nodeExists = (nodeData != null);
- if (trace) log.trace("nodeExists " + nodeExists);
+ if (trace) log.trace("Node " + fqn + " exists? " + nodeExists);
if (nodeExists) recordNodeLoaded(ctx, fqn);
if (getStatisticsEnabled())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java 2008-11-25 11:48:32 UTC (rev 7195)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java 2008-11-25 12:21:15 UTC (rev 7196)
@@ -279,7 +279,7 @@
{
throw new TimeoutException("Unable to acquire lock on " + fqn + ". Lock info: " + lockManager.printLockInfo(n));
}
- mustLoad = mustLoad(n, key, allKeys || isMove);
+ mustLoad = mustLoad(fqn, n, key, allKeys || isMove);
}
finally
{
@@ -413,11 +413,11 @@
node.setChildrenLoaded(true);
}
- private boolean mustLoad(NodeSPI n, Object key, boolean allKeys)
+ private boolean mustLoad(Fqn fqn, NodeSPI n, Object key, boolean allKeys)
{
if (n == null)
{
- if (trace) log.trace("must load, node null");
+ if (trace) log.trace("Node [" + fqn + "] is null in memory. Must load? true");
return true;
}
@@ -425,7 +425,10 @@
if (!n.isValid() && configuration.getNodeLockingScheme().isVersionedScheme())
{
// attempt to load again; this only happens if we have tombstones lying around, or we are using invalidation.
- if (trace) log.trace("loading again from cache loader since in-memory node is marked as invalid");
+ if (trace)
+ {
+ log.trace("Loading node [" + fqn + "] again from cache loader since in-memory node is marked as invalid");
+ }
return true;
}
@@ -435,20 +438,22 @@
// if we are not looking for a specific key don't bother loading!
if (key == null)
{
- if (trace) log.trace("don't load, key requested is null");
+ if (trace) log.trace("Don't load [" + fqn + "], key requested is null");
return false;
}
if (n.getKeysDirect().contains(key))
{
- if (trace) log.trace("don't load, already have necessary key in memory");
+ if (trace) log.trace("Don't load [" + fqn + "], already have necessary key in memory");
return false;
}
}
if (!n.isDataLoaded())
{
- if (trace) log.trace("must Load, uninitialized");
+ if (trace) log.trace("Must load node [" + fqn + "], uninitialized");
return true;
}
+
+ if (trace) log.trace("Don't load node [" + fqn + "], by default");
return false;
}
@@ -563,10 +568,10 @@
private Map loadData(InvocationContext ctx, Fqn fqn) throws Exception
{
-
+ if (trace) log.trace("Attempting to load data for " + fqn);
Map nodeData = loader.get(fqn);
boolean nodeExists = (nodeData != null);
- if (trace) log.trace("nodeExists " + nodeExists);
+ if (trace) log.trace("Node " + fqn + " exists? " + nodeExists);
if (nodeExists) recordNodeLoaded(ctx, fqn);
if (getStatisticsEnabled())
{
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java 2008-11-25 11:48:32 UTC (rev 7195)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/MVCCNodeFactory.java 2008-11-25 12:21:15 UTC (rev 7196)
@@ -101,6 +101,10 @@
public InternalNode<K, V> createInternalNode(Fqn fqn)
{
UnversionedNode<K, V> un = new UnversionedNode<K, V>(fqn, cache, lockChildForInsertRemove);
+
+ // always assume that new nodes don't have their data loaded, unless root.
+ if (!fqn.isRoot()) un.setDataLoaded(false);
+
return useRepeatableRead ? un : new NodeReference<K, V>(un);
}
15 years, 4 months
JBoss Cache SVN: r7195 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-25 06:48:32 -0500 (Tue, 25 Nov 2008)
New Revision: 7195
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java
Log:
Detection of whether a node is loaded, and accordingly optimize activation
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-11-25 11:08:02 UTC (rev 7194)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-11-25 11:48:32 UTC (rev 7195)
@@ -34,9 +34,11 @@
import javax.transaction.Transaction;
import java.util.Collections;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* A context that holds information regarding the scope of a single invocation. May delegate some calls to a {@link org.jboss.cache.transaction.TransactionContext}
@@ -67,6 +69,8 @@
@Deprecated
private VisitableCommand command;
+ private Set<Fqn> fqnsLoaded;
+
/**
* LinkedHashSet of locks acquired by the invocation. We use a LinkedHashSet because we need efficient Set semantics
* but also need guaranteed ordering for use by lock release code (see JBCCACHE-874).
@@ -415,6 +419,7 @@
invocationLocks = null;
methodCall = null;
command = null;
+ fqnsLoaded = null;
}
/**
@@ -549,7 +554,9 @@
if (!shouldRethtrow)
{
if (trace)
+ {
log.trace("There was a problem handling this request, but failSilently was set, so suppressing exception", e);
+ }
return;
}
throw e;
@@ -568,6 +575,22 @@
copy.transactionContext = transactionContext;
}
+ public void addFqnLoaded(Fqn fqn)
+ {
+ if (fqnsLoaded == null) fqnsLoaded = new HashSet<Fqn>();
+ fqnsLoaded.add(fqn);
+ }
+
+ public Set<Fqn> getFqnsLoaded()
+ {
+ return fqnsLoaded;
+ }
+
+ public void setFqnsLoaded(Set<Fqn> fqnsLoaded)
+ {
+ this.fqnsLoaded = fqnsLoaded;
+ }
+
@Override
public String toString()
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-11-25 11:08:02 UTC (rev 7194)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-11-25 11:48:32 UTC (rev 7195)
@@ -32,7 +32,13 @@
import org.jboss.cache.commands.read.GetNodeCommand;
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.write.*;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+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.jmx.annotations.ManagedAttribute;
@@ -42,7 +48,11 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -53,308 +63,386 @@
* @author <a href="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
* @version $Id$
*/
-public class ActivationInterceptor extends CacheLoaderInterceptor {
+public class ActivationInterceptor extends CacheLoaderInterceptor
+{
- protected TransactionManager txMgr = null;
- private long activations = 0;
- ActivationModificationsBuilder builder;
+ protected TransactionManager txMgr = null;
+ private long activations = 0;
+ ActivationModificationsBuilder builder;
- /**
- * List<Transaction> that we have registered for
- */
- protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
- protected static final Object NULL = new Object();
+ /**
+ * List<Transaction> that we have registered for
+ */
+ protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
+ protected static final Object NULL = new Object();
- public ActivationInterceptor() {
- isActivation = true;
- useCacheStore = false;
- }
+ public ActivationInterceptor()
+ {
+ isActivation = true;
+ useCacheStore = false;
+ }
- @Inject
- public void injectTransactionManager(TransactionManager txMgr) {
- this.txMgr = txMgr;
- }
+ @Inject
+ public void injectTransactionManager(TransactionManager txMgr)
+ {
+ this.txMgr = txMgr;
+ }
- @Start
- public void createModificationsBuilder() {
- builder = new ActivationModificationsBuilder();
- }
+ @Start
+ public void createModificationsBuilder()
+ {
+ builder = new ActivationModificationsBuilder();
+ }
- @Override
- public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable {
- Object returnValue = super.visitClearDataCommand(ctx, command);
- if (trace)
- log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
- loader.removeData(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ Object returnValue = super.visitClearDataCommand(ctx, command);
+ if (trace)
+ {
+ log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
+ }
+ loader.removeData(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable {
- Object returnValue = super.visitRemoveNodeCommand(ctx, command);
- if (trace)
- log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ Object returnValue = super.visitRemoveNodeCommand(ctx, command);
+ if (trace)
+ {
+ log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
+ }
+ loader.remove(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable {
- Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable {
- Object returnValue = super.visitGetKeysCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetKeysCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable {
- Object returnValue = super.visitGetNodeCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetNodeCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
- Object returnValue = super.visitGetKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable {
- return visitPutKeyValueCommand(ctx, command);
- }
+ @Override
+ public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ return visitPutKeyValueCommand(ctx, command);
+ }
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
- Object returnValue = super.visitPutKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ Object returnValue = super.visitPutKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable {
- Object returnValue = super.visitPutDataMapCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ Object returnValue = super.visitPutDataMapCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable {
- Object returnValue = super.visitRemoveKeyCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ Object returnValue = super.visitRemoveKeyCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable {
- Object returnValue = super.visitMoveCommand(ctx, command);
- if (trace)
- log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- removeNodeFromCacheLoader(command.getFqn().getParent());
- removeNodeFromCacheLoader(command.getTo());
- return returnValue;
- }
+ @Override
+ public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ Object returnValue = super.visitMoveCommand(ctx, command);
+ if (trace)
+ {
+ log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
+ }
+ loader.remove(command.getFqn());
+ removeNodeFromCacheLoader(ctx, command.getFqn().getParent());
+ removeNodeFromCacheLoader(ctx, command.getTo());
+ return returnValue;
+ }
+ private boolean wasLoadedIntoMemory(InvocationContext ctx, Fqn fqn)
+ {
+ Set<Fqn> fqnsLoaded = ctx.getFqnsLoaded();
+ return fqnsLoaded != null && fqnsLoaded.contains(fqn);
+ }
- /**
- * Remove the node from the cache loader 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).
- */
- private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable {
- if (fqn == null) return;
- InternalNode n;
- if (((n = dataContainer.peekInternalNode(fqn, true)) != null) && n.isDataLoaded()) {
+ /**
+ * Remove the node from the cache loader 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).
+ */
+ private void removeNodeFromCacheLoader(InvocationContext ctx, Fqn fqn) throws Throwable
+ {
+ if (fqn != null && wasLoadedIntoMemory(ctx, fqn))
+ {
+ InternalNode n;
+ if (((n = dataContainer.peekInternalNode(fqn, true)) != null) && n.isDataLoaded() && loader.exists(fqn))
+ {
// node not null and attributes have been loaded?
- if (n.hasChildren()) {
- boolean result = childrenLoaded(n);
- if (result) {
- log.debug("children all initialized");
- remove(fqn);
- }
- } else if (loaderNoChildren(fqn)) {
- if (log.isDebugEnabled()) log.debug("no children " + n);
- remove(fqn);
+ if (n.hasChildren())
+ {
+ boolean result = childrenLoaded(n);
+ if (result)
+ {
+ log.debug("children all initialized");
+ remove(fqn);
+ }
}
- }
- }
+ else if (loaderNoChildren(fqn))
+ {
+ if (log.isDebugEnabled()) log.debug("no children " + n);
+ remove(fqn);
+ }
+ }
+ }
+ }
- private boolean childrenLoaded(InternalNode<?, ?> node) {
- if (!node.isChildrenLoaded()) {
+ private boolean childrenLoaded(InternalNode<?, ?> node)
+ {
+ if (!node.isChildrenLoaded())
+ {
+ return false;
+ }
+ for (InternalNode child : node.getChildren())
+ {
+ if (!child.isDataLoaded())
+ {
return false;
- }
- for (InternalNode child : node.getChildren()) {
- if (!child.isDataLoaded()) {
- return false;
- }
+ }
- if (child.hasChildren()) {
- if (!childrenLoaded(child))
- return false;
- } else if (!loaderNoChildren(child.getFqn())) {
- return false;
+ if (child.hasChildren())
+ {
+ if (!childrenLoaded(child))
+ {
+ return false;
}
- }
- return true;
+ }
+ else if (!loaderNoChildren(child.getFqn()))
+ {
+ return false;
+ }
+ }
+ return true;
- }
+ }
- @Override
- public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction()) {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction())
+ {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private boolean inTransaction() throws SystemException {
- return txMgr != null && txMgr.getTransaction() != null;
- }
+ private boolean inTransaction() throws SystemException
+ {
+ return txMgr != null && txMgr.getTransaction() != null;
+ }
- @Override
- public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction()) {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction())
+ {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private void remove(Fqn fqn) throws Exception {
- loader.remove(fqn);
- if (getStatisticsEnabled()) activations++;
- }
+ private void remove(Fqn fqn) throws Exception
+ {
+ loader.remove(fqn);
+ if (getStatisticsEnabled()) activations++;
+ }
- /**
- * Returns true if the loader indicates no children for this node.
- * Return false on error.
- */
- private boolean loaderNoChildren(Fqn fqn) {
- try {
- Set childrenNames = loader.getChildrenNames(fqn);
- return (childrenNames == null);
- }
- catch (Exception e) {
- log.error("failed getting the children names for " + fqn + " from the cache loader", e);
- return false;
- }
- }
+ /**
+ * Returns true if the loader indicates no children for this node.
+ * Return false on error.
+ */
+ private boolean loaderNoChildren(Fqn fqn)
+ {
+ try
+ {
+ Set childrenNames = loader.getChildrenNames(fqn);
+ return (childrenNames == null);
+ }
+ catch (Exception e)
+ {
+ log.error("failed getting the children names for " + fqn + " from the cache loader", e);
+ return false;
+ }
+ }
- private void prepareCacheLoader(InvocationContext ctx) throws Throwable {
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionContext tCtx = ctx.getTransactionContext();
- if (tCtx == null) {
- throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
- }
- List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private void prepareCacheLoader(InvocationContext ctx) throws Throwable
+ {
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+ TransactionContext tCtx = ctx.getTransactionContext();
+ if (tCtx == null)
+ {
+ throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
+ }
+ List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- builder.visitCollection(ctx, tCtx.getModifications());
- if (cacheLoaderModifications.size() > 0) {
- loader.prepare(gtx, cacheLoaderModifications, false);
- }
- }
+ builder.visitCollection(ctx, tCtx.getModifications());
+ if (cacheLoaderModifications.size() > 0)
+ {
+ loader.prepare(gtx, cacheLoaderModifications, false);
+ }
+ }
- public class ActivationModificationsBuilder extends AbstractVisitor {
+ public class ActivationModificationsBuilder extends AbstractVisitor
+ {
- private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- private int txActs = 0;
+ 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 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 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;
- }
+ @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.exists(fqn) && loader.exists(fqn)) {
- InternalNode n = dataContainer.peekInternalNode(fqn, true);// don't load
- // node not null and attributes have been loaded?
- if (n != null && n.isDataLoaded()) {
- // has children?
- boolean result = childrenLoaded(n);
- if (n.hasChildren() && result) {
- // children have been loaded, remove the node
- addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
- txActs++;
- }
- // doesn't have children, check the cache loader
- else if (loaderNoChildren(fqn)) {
- addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
- txActs++;
- }
- }
+ // 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.exists(fqn) && loader.exists(fqn))
+ {
+ InternalNode n = dataContainer.peekInternalNode(fqn, true);// don't load
+ // node not null and attributes have been loaded?
+ if (n != null && n.isDataLoaded())
+ {
+ // has children?
+ boolean result = childrenLoaded(n);
+ if (n.hasChildren() && result)
+ {
+ // children have been loaded, remove the node
+ addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
+ txActs++;
+ }
+ // doesn't have children, check the cache loader
+ else if (loaderNoChildren(fqn))
+ {
+ addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
+ txActs++;
+ }
}
- }
+ }
+ }
- private boolean loaderNoChildren(Fqn fqn) throws Exception {
- return loader.getChildrenNames(fqn) != null;
- }
+ 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);
- }
+ 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 List<Modification> getCacheLoaderModifications()
+ {
+ return cacheLoaderModifications;
+ }
- public int getTxActs() {
- return txActs;
- }
+ public int getTxActs()
+ {
+ return txActs;
+ }
- }
+ }
- @ManagedAttribute(description = "number of cache node activations")
- public long getActivations() {
- return activations;
- }
+ @ManagedAttribute(description = "number of cache node activations")
+ public long getActivations()
+ {
+ return activations;
+ }
- @ManagedOperation
- public void resetStatistics() {
- super.resetStatistics();
- activations = 0;
- }
+ @ManagedOperation
+ public void resetStatistics()
+ {
+ super.resetStatistics();
+ activations = 0;
+ }
- @ManagedOperation
- public Map<String, Object> dumpStatistics() {
- Map<String, Object> retval = super.dumpStatistics();
- if (retval == null) {
- retval = new HashMap<String, Object>();
- }
- retval.put("Activations", activations);
- return retval;
- }
+ @ManagedOperation
+ public Map<String, Object> dumpStatistics()
+ {
+ Map<String, Object> retval = super.dumpStatistics();
+ if (retval == null)
+ {
+ retval = new HashMap<String, Object>();
+ }
+ retval.put("Activations", activations);
+ return retval;
+ }
+
+ @Override
+ protected void recordNodeLoaded(InvocationContext ctx, Fqn fqn)
+ {
+ ctx.addFqnLoaded(fqn);
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-11-25 11:08:02 UTC (rev 7194)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-11-25 11:48:32 UTC (rev 7195)
@@ -294,7 +294,7 @@
}
else
{
- nodeData = loadData(fqn);
+ nodeData = loadData(ctx, fqn);
exists = nodeData != null;
}
if (n == null && exists)
@@ -380,7 +380,7 @@
if ((isMove || isActivation) && recursive)
{
// load data for children as well!
- child.setInternalState(loader.get(child.getFqn()));
+ child.setInternalState(loadData(ctxt, child.getFqn()));
child.setDataLoaded(true);
}
@@ -466,13 +466,13 @@
}
}
- private Map loadData(Fqn fqn) throws Exception
+ private Map loadData(InvocationContext ctx, Fqn fqn) throws Exception
{
Map nodeData = loader.get(fqn);
boolean nodeExists = (nodeData != null);
if (trace) log.trace("nodeExists " + nodeExists);
-
+ if (nodeExists) recordNodeLoaded(ctx, fqn);
if (getStatisticsEnabled())
{
if (nodeExists)
@@ -516,4 +516,9 @@
retval.put("CacheLoaderMisses", cacheMisses);
return retval;
}
+
+ protected void recordNodeLoaded(InvocationContext ctx, Fqn fqn)
+ {
+ // this is a no-op. Only used by subclasses.
+ }
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java 2008-11-25 11:08:02 UTC (rev 7194)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java 2008-11-25 11:48:32 UTC (rev 7195)
@@ -32,7 +32,13 @@
import org.jboss.cache.commands.read.GetNodeCommand;
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.write.*;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+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.jmx.annotations.ManagedOperation;
@@ -41,7 +47,11 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -54,306 +64,386 @@
* @deprecated will be removed along with optimistic and pessimistic locking.
*/
@Deprecated
-public class LegacyActivationInterceptor extends LegacyCacheLoaderInterceptor {
+public class LegacyActivationInterceptor extends LegacyCacheLoaderInterceptor
+{
- protected TransactionManager txMgr = null;
- private long activations = 0;
- ActivationModificationsBuilder builder;
+ protected TransactionManager txMgr = null;
+ private long activations = 0;
+ ActivationModificationsBuilder builder;
- /**
- * List<Transaction> that we have registered for
- */
- protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
- protected static final Object NULL = new Object();
+ /**
+ * List<Transaction> that we have registered for
+ */
+ protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
+ protected static final Object NULL = new Object();
- public LegacyActivationInterceptor() {
- isActivation = true;
- useCacheStore = false;
- }
+ public LegacyActivationInterceptor()
+ {
+ isActivation = true;
+ useCacheStore = false;
+ }
- @Inject
- public void injectTransactionManager(TransactionManager txMgr) {
- this.txMgr = txMgr;
- }
+ @Inject
+ public void injectTransactionManager(TransactionManager txMgr)
+ {
+ this.txMgr = txMgr;
+ }
- @Start
- public void createModificationsBuilder() {
- builder = new ActivationModificationsBuilder();
- }
+ @Start
+ public void createModificationsBuilder()
+ {
+ builder = new ActivationModificationsBuilder();
+ }
- @Override
- public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable {
- Object returnValue = super.visitClearDataCommand(ctx, command);
- if (trace)
- log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
- loader.removeData(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ Object returnValue = super.visitClearDataCommand(ctx, command);
+ if (trace)
+ {
+ log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
+ }
+ loader.removeData(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable {
- Object returnValue = super.visitRemoveNodeCommand(ctx, command);
- if (trace)
- log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ Object returnValue = super.visitRemoveNodeCommand(ctx, command);
+ if (trace)
+ {
+ log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
+ }
+ loader.remove(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable {
- Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable {
- Object returnValue = super.visitGetKeysCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetKeysCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable {
- Object returnValue = super.visitGetNodeCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetNodeCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
- Object returnValue = super.visitGetKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ Object returnValue = super.visitGetKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable {
- return visitPutKeyValueCommand(ctx, command);
- }
+ @Override
+ public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ return visitPutKeyValueCommand(ctx, command);
+ }
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
- Object returnValue = super.visitPutKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ Object returnValue = super.visitPutKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable {
- Object returnValue = super.visitPutDataMapCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ Object returnValue = super.visitPutDataMapCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable {
- Object returnValue = super.visitRemoveKeyCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ Object returnValue = super.visitRemoveKeyCommand(ctx, command);
+ removeNodeFromCacheLoader(ctx, command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable {
- Object returnValue = super.visitMoveCommand(ctx, command);
- if (trace)
- log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- removeNodeFromCacheLoader(command.getFqn().getParent());
- removeNodeFromCacheLoader(command.getTo());
- return returnValue;
- }
+ @Override
+ public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ Object returnValue = super.visitMoveCommand(ctx, command);
+ if (trace)
+ {
+ log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
+ }
+ loader.remove(command.getFqn());
+ removeNodeFromCacheLoader(ctx, command.getFqn().getParent());
+ removeNodeFromCacheLoader(ctx, command.getTo());
+ return returnValue;
+ }
+ private boolean wasLoadedIntoMemory(InvocationContext ctx, Fqn fqn)
+ {
+ Set<Fqn> fqnsLoaded = ctx.getFqnsLoaded();
+ return fqnsLoaded != null && fqnsLoaded.contains(fqn);
+ }
- /**
- * Remove the node from the cache loader 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).
- */
- private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable {
- NodeSPI n;
- if (((n = dataContainer.peek(fqn, true, false)) != null) && n.isDataLoaded()) {
+ /**
+ * Remove the node from the cache loader 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).
+ */
+ private void removeNodeFromCacheLoader(InvocationContext ctx, Fqn fqn) throws Throwable
+ {
+ // only bother with this if the node has been loaded by the cache loader previous to this call.
+ if (fqn != null && wasLoadedIntoMemory(ctx, fqn))
+ {
+ NodeSPI n;
+ if (((n = dataContainer.peek(fqn, true, false)) != null) && n.isDataLoaded() && loader.exists(fqn))
+ {
// node not null and attributes have been loaded?
- if (!n.getChildrenDirect().isEmpty()) {
- boolean result = childrenLoaded(n);
- if (result) {
- log.debug("children all initialized");
- remove(fqn);
- }
- } else if (loaderNoChildren(fqn)) {
- if (log.isDebugEnabled()) log.debug("no children " + n);
- remove(fqn);
+ if (!n.getChildrenDirect().isEmpty())
+ {
+ boolean result = childrenLoaded(n);
+ if (result)
+ {
+ log.debug("children all initialized");
+ remove(fqn);
+ }
}
- }
- }
+ else if (loaderNoChildren(fqn))
+ {
+ if (log.isDebugEnabled()) log.debug("no children " + n);
+ remove(fqn);
+ }
+ }
+ }
+ }
- private boolean childrenLoaded(NodeSPI<?, ?> node) {
- if (!node.isChildrenLoaded()) {
+ private boolean childrenLoaded(NodeSPI<?, ?> node)
+ {
+ if (!node.isChildrenLoaded())
+ {
+ return false;
+ }
+ for (NodeSPI child : node.getChildrenDirect())
+ {
+ if (!child.isDataLoaded())
+ {
return false;
- }
- for (NodeSPI child : node.getChildrenDirect()) {
- if (!child.isDataLoaded()) {
- return false;
- }
+ }
- if (child.getChildrenDirect().size() > 0) {
- if (!childrenLoaded(child))
- return false;
- } else if (!loaderNoChildren(child.getFqn())) {
- return false;
+ if (child.getChildrenDirect().size() > 0)
+ {
+ if (!childrenLoaded(child))
+ {
+ return false;
}
- }
- return true;
+ }
+ else if (!loaderNoChildren(child.getFqn()))
+ {
+ return false;
+ }
+ }
+ return true;
- }
+ }
- @Override
- public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction()) {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction())
+ {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private boolean inTransaction() throws SystemException {
- return txMgr != null && txMgr.getTransaction() != null;
- }
+ private boolean inTransaction() throws SystemException
+ {
+ return txMgr != null && txMgr.getTransaction() != null;
+ }
- @Override
- public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction()) {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction())
+ {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private void remove(Fqn fqn) throws Exception {
- loader.remove(fqn);
- if (getStatisticsEnabled()) activations++;
- }
+ private void remove(Fqn fqn) throws Exception
+ {
+ loader.remove(fqn);
+ if (getStatisticsEnabled()) activations++;
+ }
- /**
- * Returns true if the loader indicates no children for this node.
- * Return false on error.
- */
- private boolean loaderNoChildren(Fqn fqn) {
- try {
- Set childrenNames = loader.getChildrenNames(fqn);
- return (childrenNames == null);
- }
- catch (Exception e) {
- log.error("failed getting the children names for " + fqn + " from the cache loader", e);
- return false;
- }
- }
+ /**
+ * Returns true if the loader indicates no children for this node.
+ * Return false on error.
+ */
+ private boolean loaderNoChildren(Fqn fqn)
+ {
+ try
+ {
+ Set childrenNames = loader.getChildrenNames(fqn);
+ return (childrenNames == null);
+ }
+ catch (Exception e)
+ {
+ log.error("failed getting the children names for " + fqn + " from the cache loader", e);
+ return false;
+ }
+ }
- public long getActivations() {
- return activations;
- }
+ public long getActivations()
+ {
+ return activations;
+ }
- private void prepareCacheLoader(InvocationContext ctx) throws Throwable {
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionContext tCtx = ctx.getTransactionContext();
- if (tCtx == null) {
- throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
- }
- List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private void prepareCacheLoader(InvocationContext ctx) throws Throwable
+ {
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+ TransactionContext tCtx = ctx.getTransactionContext();
+ if (tCtx == null)
+ {
+ throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
+ }
+ List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- builder.visitCollection(ctx, tCtx.getModifications());
- if (cacheLoaderModifications.size() > 0) {
- loader.prepare(gtx, cacheLoaderModifications, false);
- }
- }
+ builder.visitCollection(ctx, tCtx.getModifications());
+ if (cacheLoaderModifications.size() > 0)
+ {
+ loader.prepare(gtx, cacheLoaderModifications, false);
+ }
+ }
- public class ActivationModificationsBuilder extends AbstractVisitor {
+ public class ActivationModificationsBuilder extends AbstractVisitor
+ {
- private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- private int txActs = 0;
+ 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 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 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;
- }
+ @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++;
- }
- }
+ // 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 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);
- }
+ 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 List<Modification> getCacheLoaderModifications()
+ {
+ return cacheLoaderModifications;
+ }
- public int getTxActs() {
- return txActs;
- }
+ public int getTxActs()
+ {
+ return txActs;
+ }
- }
+ }
- @ManagedOperation
- public void resetStatistics() {
- super.resetStatistics();
- activations = 0;
- }
+ @ManagedOperation
+ public void resetStatistics()
+ {
+ super.resetStatistics();
+ activations = 0;
+ }
- @ManagedOperation
- public Map<String, Object> dumpStatistics() {
- Map<String, Object> retval = super.dumpStatistics();
- if (retval == null) {
- retval = new HashMap<String, Object>();
- }
- retval.put("Activations", activations);
- return retval;
- }
+ @ManagedOperation
+ public Map<String, Object> dumpStatistics()
+ {
+ Map<String, Object> retval = super.dumpStatistics();
+ if (retval == null)
+ {
+ retval = new HashMap<String, Object>();
+ }
+ retval.put("Activations", activations);
+ return retval;
+ }
+
+ @Override
+ protected void recordNodeLoaded(InvocationContext ctx, Fqn fqn)
+ {
+ ctx.addFqnLoaded(fqn);
+ }
}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java 2008-11-25 11:08:02 UTC (rev 7194)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyCacheLoaderInterceptor.java 2008-11-25 11:48:32 UTC (rev 7195)
@@ -400,7 +400,7 @@
if ((isMove || isActivation) && recursive)
{
// load data for children as well!
- child.setInternalState(loader.get(child.getFqn()));
+ child.setInternalState(loadData(ctxt, child.getFqn()));
child.setDataLoaded(true);
}
@@ -457,9 +457,13 @@
if (configuration.getNodeLockingScheme() == NodeLockingScheme.OPTIMISTIC) return;
if (recursive)
+ {
lockManager.lockAllAndRecord(fqn, lockType, ctx);
+ }
else
+ {
lockManager.lockAndRecord(fqn, lockType, ctx);
+ }
}
/**
@@ -487,7 +491,7 @@
private NodeSPI loadNode(InvocationContext ctx, Fqn fqn, NodeSPI n, TransactionContext transactionContext) throws Exception
{
if (trace) log.trace("loadNode " + fqn);
- Map nodeData = loadData(fqn);
+ Map nodeData = loadData(ctx, fqn);
if (nodeData != null)
{
if (trace) log.trace("Node data is not null, loading");
@@ -557,13 +561,13 @@
return (NodeSPI) results[1];
}
- private Map loadData(Fqn fqn) throws Exception
+ private Map loadData(InvocationContext ctx, Fqn fqn) throws Exception
{
Map nodeData = loader.get(fqn);
boolean nodeExists = (nodeData != null);
if (trace) log.trace("nodeExists " + nodeExists);
-
+ if (nodeExists) recordNodeLoaded(ctx, fqn);
if (getStatisticsEnabled())
{
if (nodeExists)
@@ -606,4 +610,8 @@
return retval;
}
+ protected void recordNodeLoaded(InvocationContext ctx, Fqn fqn)
+ {
+ // this is a no-op. Only used by subclasses.
+ }
}
\ No newline at end of file
15 years, 4 months
JBoss Cache SVN: r7194 - core/trunk/src/main/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-25 06:08:02 -0500 (Tue, 25 Nov 2008)
New Revision: 7194
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java
Log:
Passivation efficiency improvements
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-11-24 22:07:40 UTC (rev 7193)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-11-25 11:08:02 UTC (rev 7194)
@@ -32,13 +32,7 @@
import org.jboss.cache.commands.read.GetNodeCommand;
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.commands.write.*;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.jmx.annotations.ManagedAttribute;
@@ -48,11 +42,7 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -63,366 +53,308 @@
* @author <a href="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
* @version $Id$
*/
-public class ActivationInterceptor extends CacheLoaderInterceptor
-{
+public class ActivationInterceptor extends CacheLoaderInterceptor {
- protected TransactionManager txMgr = null;
- private long activations = 0;
- ActivationModificationsBuilder builder;
+ protected TransactionManager txMgr = null;
+ private long activations = 0;
+ ActivationModificationsBuilder builder;
- /**
- * List<Transaction> that we have registered for
- */
- protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
- protected static final Object NULL = new Object();
+ /**
+ * List<Transaction> that we have registered for
+ */
+ protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
+ protected static final Object NULL = new Object();
- public ActivationInterceptor()
- {
- isActivation = true;
- useCacheStore = false;
- }
+ public ActivationInterceptor() {
+ isActivation = true;
+ useCacheStore = false;
+ }
- @Inject
- public void injectTransactionManager(TransactionManager txMgr)
- {
- this.txMgr = txMgr;
- }
+ @Inject
+ public void injectTransactionManager(TransactionManager txMgr) {
+ this.txMgr = txMgr;
+ }
- @Start
- public void createModificationsBuilder()
- {
- builder = new ActivationModificationsBuilder();
- }
+ @Start
+ public void createModificationsBuilder() {
+ builder = new ActivationModificationsBuilder();
+ }
- @Override
- public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
- {
- Object returnValue = super.visitClearDataCommand(ctx, command);
- if (trace)
- log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
- loader.removeData(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable {
+ Object returnValue = super.visitClearDataCommand(ctx, command);
+ if (trace)
+ log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
+ loader.removeData(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
- {
- Object returnValue = super.visitRemoveNodeCommand(ctx, command);
- if (trace)
- log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable {
+ Object returnValue = super.visitRemoveNodeCommand(ctx, command);
+ if (trace)
+ log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
+ loader.remove(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
- {
- Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable {
+ Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- Object returnValue = super.visitGetKeysCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable {
+ Object returnValue = super.visitGetKeysCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
- {
- Object returnValue = super.visitGetNodeCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable {
+ Object returnValue = super.visitGetNodeCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- Object returnValue = super.visitGetKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
+ Object returnValue = super.visitGetKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- return visitPutKeyValueCommand(ctx, command);
- }
+ @Override
+ public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable {
+ return visitPutKeyValueCommand(ctx, command);
+ }
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
- {
- Object returnValue = super.visitPutKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
+ Object returnValue = super.visitPutKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
- {
- Object returnValue = super.visitPutDataMapCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable {
+ Object returnValue = super.visitPutDataMapCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- Object returnValue = super.visitRemoveKeyCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable {
+ Object returnValue = super.visitRemoveKeyCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
- {
- Object returnValue = super.visitMoveCommand(ctx, command);
- if (trace)
- log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- removeNodeFromCacheLoader(command.getFqn().getParent());
- removeNodeFromCacheLoader(command.getTo());
- return returnValue;
- }
+ @Override
+ public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable {
+ Object returnValue = super.visitMoveCommand(ctx, command);
+ if (trace)
+ log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
+ loader.remove(command.getFqn());
+ removeNodeFromCacheLoader(command.getFqn().getParent());
+ removeNodeFromCacheLoader(command.getTo());
+ return returnValue;
+ }
- /**
- * Remove the node from the cache loader 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 removeNodeFromCacheLoader(Fqn fqn) throws Throwable
- {
- if (fqn == null) return;
- InternalNode n;
- if (((n = dataContainer.peekInternalNode(fqn, true)) != null) && n.isDataLoaded() && loader.exists(fqn))
- {
- // node not null and attributes have been loaded?
- if (n.hasChildren())
- {
- boolean result = childrenLoaded(n);
- if (result)
- {
- log.debug("children all initialized");
- remove(fqn);
+ /**
+ * Remove the node from the cache loader 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).
+ */
+ private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable {
+ if (fqn == null) return;
+ InternalNode n;
+ if (((n = dataContainer.peekInternalNode(fqn, true)) != null) && n.isDataLoaded()) {
+ // node not null and attributes have been loaded?
+ if (n.hasChildren()) {
+ boolean result = childrenLoaded(n);
+ if (result) {
+ log.debug("children all initialized");
+ remove(fqn);
+ }
+ } else if (loaderNoChildren(fqn)) {
+ if (log.isDebugEnabled()) log.debug("no children " + n);
+ remove(fqn);
}
- }
- else if (loaderNoChildren(fqn))
- {
- if (log.isDebugEnabled()) log.debug("no children " + n);
- remove(fqn);
- }
- }
- }
+ }
+ }
- private boolean childrenLoaded(InternalNode<?, ?> node)
- {
- if (!node.isChildrenLoaded())
- {
- return false;
- }
- for (InternalNode child : node.getChildren())
- {
- if (!child.isDataLoaded())
- {
+ private boolean childrenLoaded(InternalNode<?, ?> node) {
+ if (!node.isChildrenLoaded()) {
return false;
- }
+ }
+ for (InternalNode child : node.getChildren()) {
+ if (!child.isDataLoaded()) {
+ return false;
+ }
- if (child.hasChildren())
- {
- if (!childrenLoaded(child))
- return false;
- }
- else if (!loaderNoChildren(child.getFqn()))
- {
- return false;
- }
- }
- return true;
+ if (child.hasChildren()) {
+ if (!childrenLoaded(child))
+ return false;
+ } else if (!loaderNoChildren(child.getFqn())) {
+ return false;
+ }
+ }
+ return true;
- }
+ }
- @Override
- public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
- {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction())
- {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction()) {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private boolean inTransaction() throws SystemException
- {
- return txMgr != null && txMgr.getTransaction() != null;
- }
+ private boolean inTransaction() throws SystemException {
+ return txMgr != null && txMgr.getTransaction() != null;
+ }
- @Override
- public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
- {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction())
- {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction()) {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private void remove(Fqn fqn) throws Exception
- {
- loader.remove(fqn);
- if (getStatisticsEnabled()) activations++;
- }
+ private void remove(Fqn fqn) throws Exception {
+ loader.remove(fqn);
+ if (getStatisticsEnabled()) activations++;
+ }
- /**
- * Returns true if the loader indicates no children for this node.
- * Return false on error.
- */
- private boolean loaderNoChildren(Fqn fqn)
- {
- try
- {
- Set childrenNames = loader.getChildrenNames(fqn);
- return (childrenNames == null);
- }
- catch (Exception e)
- {
- log.error("failed getting the children names for " + fqn + " from the cache loader", e);
- return false;
- }
- }
+ /**
+ * Returns true if the loader indicates no children for this node.
+ * Return false on error.
+ */
+ private boolean loaderNoChildren(Fqn fqn) {
+ try {
+ Set childrenNames = loader.getChildrenNames(fqn);
+ return (childrenNames == null);
+ }
+ catch (Exception e) {
+ log.error("failed getting the children names for " + fqn + " from the cache loader", e);
+ return false;
+ }
+ }
- private void prepareCacheLoader(InvocationContext ctx) throws Throwable
- {
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionContext tCtx = ctx.getTransactionContext();
- if (tCtx == null)
- {
- throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
- }
- List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private void prepareCacheLoader(InvocationContext ctx) throws Throwable {
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+ TransactionContext tCtx = ctx.getTransactionContext();
+ if (tCtx == null) {
+ throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
+ }
+ List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- builder.visitCollection(ctx, tCtx.getModifications());
- if (cacheLoaderModifications.size() > 0)
- {
- loader.prepare(gtx, cacheLoaderModifications, false);
- }
- }
+ builder.visitCollection(ctx, tCtx.getModifications());
+ if (cacheLoaderModifications.size() > 0) {
+ loader.prepare(gtx, cacheLoaderModifications, false);
+ }
+ }
- public class ActivationModificationsBuilder extends AbstractVisitor
- {
+ public class ActivationModificationsBuilder extends AbstractVisitor {
- private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- private int txActs = 0;
+ 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 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 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;
- }
+ @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.exists(fqn) && loader.exists(fqn))
- {
- InternalNode n = dataContainer.peekInternalNode(fqn, true);// don't load
- // node not null and attributes have been loaded?
- if (n != null && n.isDataLoaded())
- {
- // has children?
- boolean result = childrenLoaded(n);
- if (n.hasChildren() && result)
- {
- // children have been loaded, remove the node
- addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
- txActs++;
- }
- // doesn't have children, check the cache loader
- else if (loaderNoChildren(fqn))
- {
- addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
- txActs++;
- }
+ // 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.exists(fqn) && loader.exists(fqn)) {
+ InternalNode n = dataContainer.peekInternalNode(fqn, true);// don't load
+ // node not null and attributes have been loaded?
+ if (n != null && n.isDataLoaded()) {
+ // has children?
+ boolean result = childrenLoaded(n);
+ if (n.hasChildren() && result) {
+ // children have been loaded, remove the node
+ addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
+ txActs++;
+ }
+ // doesn't have children, check the cache loader
+ else if (loaderNoChildren(fqn)) {
+ addRemoveMod(ctx, cacheLoaderModifications, fqn, n.getData());
+ txActs++;
+ }
+ }
}
- }
- }
+ }
- private boolean loaderNoChildren(Fqn fqn) throws Exception
- {
- return loader.getChildrenNames(fqn) != null;
- }
+ 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);
- }
+ 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 List<Modification> getCacheLoaderModifications() {
+ return cacheLoaderModifications;
+ }
- public int getTxActs()
- {
- return txActs;
- }
+ public int getTxActs() {
+ return txActs;
+ }
- }
+ }
- @ManagedAttribute(description = "number of cache node activations")
- public long getActivations()
- {
- return activations;
- }
+ @ManagedAttribute(description = "number of cache node activations")
+ public long getActivations() {
+ return activations;
+ }
- @ManagedOperation
- public void resetStatistics()
- {
- super.resetStatistics();
- activations = 0;
- }
+ @ManagedOperation
+ public void resetStatistics() {
+ super.resetStatistics();
+ activations = 0;
+ }
- @ManagedOperation
- public Map<String, Object> dumpStatistics()
- {
- Map<String, Object> retval = super.dumpStatistics();
- if (retval == null)
- {
- retval = new HashMap<String, Object>();
- }
- retval.put("Activations", activations);
- return retval;
- }
+ @ManagedOperation
+ public Map<String, Object> dumpStatistics() {
+ Map<String, Object> retval = super.dumpStatistics();
+ if (retval == null) {
+ retval = new HashMap<String, Object>();
+ }
+ retval.put("Activations", activations);
+ return retval;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java 2008-11-24 22:07:40 UTC (rev 7193)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyActivationInterceptor.java 2008-11-25 11:08:02 UTC (rev 7194)
@@ -32,13 +32,7 @@
import org.jboss.cache.commands.read.GetNodeCommand;
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
-import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.MoveCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.commands.write.RemoveKeyCommand;
-import org.jboss.cache.commands.write.RemoveNodeCommand;
+import org.jboss.cache.commands.write.*;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.jmx.annotations.ManagedOperation;
@@ -47,11 +41,7 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -64,364 +54,306 @@
* @deprecated will be removed along with optimistic and pessimistic locking.
*/
@Deprecated
-public class LegacyActivationInterceptor extends LegacyCacheLoaderInterceptor
-{
+public class LegacyActivationInterceptor extends LegacyCacheLoaderInterceptor {
- protected TransactionManager txMgr = null;
- private long activations = 0;
- ActivationModificationsBuilder builder;
+ protected TransactionManager txMgr = null;
+ private long activations = 0;
+ ActivationModificationsBuilder builder;
- /**
- * List<Transaction> that we have registered for
- */
- protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
- protected static final Object NULL = new Object();
+ /**
+ * List<Transaction> that we have registered for
+ */
+ protected ConcurrentHashMap transactions = new ConcurrentHashMap(16);
+ protected static final Object NULL = new Object();
- public LegacyActivationInterceptor()
- {
- isActivation = true;
- useCacheStore = false;
- }
+ public LegacyActivationInterceptor() {
+ isActivation = true;
+ useCacheStore = false;
+ }
- @Inject
- public void injectTransactionManager(TransactionManager txMgr)
- {
- this.txMgr = txMgr;
- }
+ @Inject
+ public void injectTransactionManager(TransactionManager txMgr) {
+ this.txMgr = txMgr;
+ }
- @Start
- public void createModificationsBuilder()
- {
- builder = new ActivationModificationsBuilder();
- }
+ @Start
+ public void createModificationsBuilder() {
+ builder = new ActivationModificationsBuilder();
+ }
- @Override
- public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
- {
- Object returnValue = super.visitClearDataCommand(ctx, command);
- if (trace)
- log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
- loader.removeData(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable {
+ Object returnValue = super.visitClearDataCommand(ctx, command);
+ if (trace)
+ log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
+ loader.removeData(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
- {
- Object returnValue = super.visitRemoveNodeCommand(ctx, command);
- if (trace)
- log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable {
+ Object returnValue = super.visitRemoveNodeCommand(ctx, command);
+ if (trace)
+ log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
+ loader.remove(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
- {
- Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable {
+ Object returnValue = super.visitGetChildrenNamesCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
- {
- Object returnValue = super.visitGetKeysCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable {
+ Object returnValue = super.visitGetKeysCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
- {
- Object returnValue = super.visitGetNodeCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable {
+ Object returnValue = super.visitGetNodeCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
- {
- Object returnValue = super.visitGetKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
+ Object returnValue = super.visitGetKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
- {
- return visitPutKeyValueCommand(ctx, command);
- }
+ @Override
+ public Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable {
+ return visitPutKeyValueCommand(ctx, command);
+ }
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
- {
- Object returnValue = super.visitPutKeyValueCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
+ Object returnValue = super.visitPutKeyValueCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
- {
- Object returnValue = super.visitPutDataMapCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable {
+ Object returnValue = super.visitPutDataMapCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
- {
- Object returnValue = super.visitRemoveKeyCommand(ctx, command);
- removeNodeFromCacheLoader(command.getFqn());
- return returnValue;
- }
+ @Override
+ public Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable {
+ Object returnValue = super.visitRemoveKeyCommand(ctx, command);
+ removeNodeFromCacheLoader(command.getFqn());
+ return returnValue;
+ }
- @Override
- public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
- {
- Object returnValue = super.visitMoveCommand(ctx, command);
- if (trace)
- log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
- loader.remove(command.getFqn());
- removeNodeFromCacheLoader(command.getFqn().getParent());
- removeNodeFromCacheLoader(command.getTo());
- return returnValue;
- }
+ @Override
+ public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable {
+ Object returnValue = super.visitMoveCommand(ctx, command);
+ if (trace)
+ log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
+ loader.remove(command.getFqn());
+ removeNodeFromCacheLoader(command.getFqn().getParent());
+ removeNodeFromCacheLoader(command.getTo());
+ return returnValue;
+ }
- /**
- * Remove the node from the cache loader 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 removeNodeFromCacheLoader(Fqn fqn) throws Throwable
- {
- NodeSPI n;
- if (((n = dataContainer.peek(fqn, true, false)) != null) && n.isDataLoaded() && loader.exists(fqn))
- {
- // node not null and attributes have been loaded?
- if (!n.getChildrenDirect().isEmpty())
- {
- boolean result = childrenLoaded(n);
- if (result)
- {
- log.debug("children all initialized");
- remove(fqn);
+ /**
+ * Remove the node from the cache loader 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).
+ */
+ private void removeNodeFromCacheLoader(Fqn fqn) throws Throwable {
+ NodeSPI n;
+ if (((n = dataContainer.peek(fqn, true, false)) != null) && n.isDataLoaded()) {
+ // node not null and attributes have been loaded?
+ if (!n.getChildrenDirect().isEmpty()) {
+ boolean result = childrenLoaded(n);
+ if (result) {
+ log.debug("children all initialized");
+ remove(fqn);
+ }
+ } else if (loaderNoChildren(fqn)) {
+ if (log.isDebugEnabled()) log.debug("no children " + n);
+ remove(fqn);
}
- }
- else if (loaderNoChildren(fqn))
- {
- if (log.isDebugEnabled()) log.debug("no children " + n);
- remove(fqn);
- }
- }
- }
+ }
+ }
- private boolean childrenLoaded(NodeSPI<?, ?> node)
- {
- if (!node.isChildrenLoaded())
- {
- return false;
- }
- for (NodeSPI child : node.getChildrenDirect())
- {
- if (!child.isDataLoaded())
- {
+ private boolean childrenLoaded(NodeSPI<?, ?> node) {
+ if (!node.isChildrenLoaded()) {
return false;
- }
+ }
+ for (NodeSPI child : node.getChildrenDirect()) {
+ if (!child.isDataLoaded()) {
+ return false;
+ }
- if (child.getChildrenDirect().size() > 0)
- {
- if (!childrenLoaded(child))
- return false;
- }
- else if (!loaderNoChildren(child.getFqn()))
- {
- return false;
- }
- }
- return true;
+ if (child.getChildrenDirect().size() > 0) {
+ if (!childrenLoaded(child))
+ return false;
+ } else if (!loaderNoChildren(child.getFqn())) {
+ return false;
+ }
+ }
+ return true;
- }
+ }
- @Override
- public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
- {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction())
- {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction()) {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private boolean inTransaction() throws SystemException
- {
- return txMgr != null && txMgr.getTransaction() != null;
- }
+ private boolean inTransaction() throws SystemException {
+ return txMgr != null && txMgr.getTransaction() != null;
+ }
- @Override
- public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
- {
- Object retval = invokeNextInterceptor(ctx, command);
- if (inTransaction())
- {
- prepareCacheLoader(ctx);
- }
- return retval;
- }
+ @Override
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable {
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (inTransaction()) {
+ prepareCacheLoader(ctx);
+ }
+ return retval;
+ }
- private void remove(Fqn fqn) throws Exception
- {
- loader.remove(fqn);
- if (getStatisticsEnabled()) activations++;
- }
+ private void remove(Fqn fqn) throws Exception {
+ loader.remove(fqn);
+ if (getStatisticsEnabled()) activations++;
+ }
- /**
- * Returns true if the loader indicates no children for this node.
- * Return false on error.
- */
- private boolean loaderNoChildren(Fqn fqn)
- {
- try
- {
- Set childrenNames = loader.getChildrenNames(fqn);
- return (childrenNames == null);
- }
- catch (Exception e)
- {
- log.error("failed getting the children names for " + fqn + " from the cache loader", e);
- return false;
- }
- }
+ /**
+ * Returns true if the loader indicates no children for this node.
+ * Return false on error.
+ */
+ private boolean loaderNoChildren(Fqn fqn) {
+ try {
+ Set childrenNames = loader.getChildrenNames(fqn);
+ return (childrenNames == null);
+ }
+ catch (Exception e) {
+ log.error("failed getting the children names for " + fqn + " from the cache loader", e);
+ return false;
+ }
+ }
- public long getActivations()
- {
- return activations;
- }
+ public long getActivations() {
+ return activations;
+ }
- private void prepareCacheLoader(InvocationContext ctx) throws Throwable
- {
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- TransactionContext tCtx = ctx.getTransactionContext();
- if (tCtx == null)
- {
- throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
- }
- List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private void prepareCacheLoader(InvocationContext ctx) throws Throwable {
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
+ TransactionContext tCtx = ctx.getTransactionContext();
+ if (tCtx == null) {
+ throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
+ }
+ List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- builder.visitCollection(ctx, tCtx.getModifications());
- if (cacheLoaderModifications.size() > 0)
- {
- loader.prepare(gtx, cacheLoaderModifications, false);
- }
- }
+ builder.visitCollection(ctx, tCtx.getModifications());
+ if (cacheLoaderModifications.size() > 0) {
+ loader.prepare(gtx, cacheLoaderModifications, false);
+ }
+ }
- public class ActivationModificationsBuilder extends AbstractVisitor
- {
+ public class ActivationModificationsBuilder extends AbstractVisitor {
- private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
+ private List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- private int txActs = 0;
+ 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 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 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;
- }
+ @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++;
- }
+ // 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 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);
- }
+ 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 List<Modification> getCacheLoaderModifications() {
+ return cacheLoaderModifications;
+ }
- public int getTxActs()
- {
- return txActs;
- }
+ public int getTxActs() {
+ return txActs;
+ }
- }
+ }
- @ManagedOperation
- public void resetStatistics()
- {
- super.resetStatistics();
- activations = 0;
- }
+ @ManagedOperation
+ public void resetStatistics() {
+ super.resetStatistics();
+ activations = 0;
+ }
- @ManagedOperation
- public Map<String, Object> dumpStatistics()
- {
- Map<String, Object> retval = super.dumpStatistics();
- if (retval == null)
- {
- retval = new HashMap<String, Object>();
- }
- retval.put("Activations", activations);
- return retval;
- }
+ @ManagedOperation
+ public Map<String, Object> dumpStatistics() {
+ Map<String, Object> retval = super.dumpStatistics();
+ if (retval == null) {
+ retval = new HashMap<String, Object>();
+ }
+ retval.put("Activations", activations);
+ return retval;
+ }
}
\ No newline at end of file
15 years, 4 months
JBoss Cache SVN: r7193 - in core/tags/3.0.1.CR1: src/main/java/org/jboss/cache and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-24 17:07:40 -0500 (Mon, 24 Nov 2008)
New Revision: 7193
Modified:
core/tags/3.0.1.CR1/pom.xml
core/tags/3.0.1.CR1/src/main/java/org/jboss/cache/Version.java
Log:
JBoss Cache Release Script: Updating 3.0.1.CR1
Modified: core/tags/3.0.1.CR1/pom.xml
===================================================================
--- core/tags/3.0.1.CR1/pom.xml 2008-11-24 22:06:43 UTC (rev 7192)
+++ core/tags/3.0.1.CR1/pom.xml 2008-11-24 22:07:40 UTC (rev 7193)
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
- <jbosscache-core-version>3.0.0-SNAPSHOT</jbosscache-core-version>
+ <jbosscache-core-version>3.0.1.CR1</jbosscache-core-version>
<!-- By default only run tests in the "unit" group -->
<defaultTestGroup>unit</defaultTestGroup>
<!-- By default only generate Javadocs when we install the module. -->
@@ -443,7 +443,7 @@
<activeByDefault>false</activeByDefault>
</activation>
<properties>
- <jbosscache-core-version>3.0.0-SNAPSHOT-JBossAS</jbosscache-core-version>
+ <jbosscache-core-version>3.0.1.CR1-JBossAS</jbosscache-core-version>
</properties>
<dependencies>
<dependency>
Modified: core/tags/3.0.1.CR1/src/main/java/org/jboss/cache/Version.java
===================================================================
--- core/tags/3.0.1.CR1/src/main/java/org/jboss/cache/Version.java 2008-11-24 22:06:43 UTC (rev 7192)
+++ core/tags/3.0.1.CR1/src/main/java/org/jboss/cache/Version.java 2008-11-24 22:07:40 UTC (rev 7193)
@@ -32,10 +32,10 @@
@Immutable
public class Version
{
- public static final String version = "3.0.0-SNAPSHOT";
+ public static final String version = "3.0.1.CR1";
public static final String codename = "Naga";
//public static final String cvs = "$Id$";
- static final byte[] version_id = {'0', '3', '0', '0', 'S'};
+ static final byte[] version_id = {'0','3','0','1','C','R','1'};
private static final int MAJOR_SHIFT = 11;
private static final int MINOR_SHIFT = 6;
15 years, 4 months
JBoss Cache SVN: r7192 - core/tags/3.0.1.CR1.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-11-24 17:06:43 -0500 (Mon, 24 Nov 2008)
New Revision: 7192
Added:
core/tags/3.0.1.CR1/trunk/
Log:
JBoss Cache Release Script: Tagging 3.0.1.CR1
Copied: core/tags/3.0.1.CR1/trunk (from rev 7191, core/trunk)
15 years, 4 months
JBoss Cache SVN: r7191 - in core/trunk: src/main/java/org/jboss/cache and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-11-24 13:14:30 -0500 (Mon, 24 Nov 2008)
New Revision: 7191
Modified:
core/trunk/pom.xml
core/trunk/src/main/java/org/jboss/cache/Version.java
Log:
updated version
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2008-11-24 18:11:39 UTC (rev 7190)
+++ core/trunk/pom.xml 2008-11-24 18:14:30 UTC (rev 7191)
@@ -443,7 +443,7 @@
<activeByDefault>false</activeByDefault>
</activation>
<properties>
- <jbosscache-core-version>3.0.0-SNAPSHOT-JBossAS</jbosscache-core-version>
+ <jbosscache-core-version>3.0.1-SNAPSHOT-JBossAS</jbosscache-core-version>
</properties>
<dependencies>
<dependency>
Modified: core/trunk/src/main/java/org/jboss/cache/Version.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Version.java 2008-11-24 18:11:39 UTC (rev 7190)
+++ core/trunk/src/main/java/org/jboss/cache/Version.java 2008-11-24 18:14:30 UTC (rev 7191)
@@ -32,7 +32,7 @@
@Immutable
public class Version
{
- public static final String version = "3.0.0-SNAPSHOT";
+ public static final String version = "3.0.1-SNAPSHOT";
public static final String codename = "Naga";
//public static final String cvs = "$Id$";
static final byte[] version_id = {'0', '3', '0', '0', 'S'};
15 years, 4 months
JBoss Cache SVN: r7190 - core/tags.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-11-24 13:11:39 -0500 (Mon, 24 Nov 2008)
New Revision: 7190
Added:
core/tags/3.0.1.CR1/
Log:
Copied: core/tags/3.0.1.CR1 (from rev 7189, core/trunk)
15 years, 4 months
JBoss Cache SVN: r7189 - core/trunk.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-11-24 13:02:53 -0500 (Mon, 24 Nov 2008)
New Revision: 7189
Modified:
core/trunk/pom.xml
Log:
one thread only for now
Modified: core/trunk/pom.xml
===================================================================
--- core/trunk/pom.xml 2008-11-24 18:01:37 UTC (rev 7188)
+++ core/trunk/pom.xml 2008-11-24 18:02:53 UTC (rev 7189)
@@ -132,7 +132,7 @@
<version>2.4.3-JBOSS</version>
<configuration>
<parallel>tests</parallel>
- <threadCount>10</threadCount>
+ <threadCount>1</threadCount>
<forkMode>none</forkMode>
<trimStackTrace>false</trimStackTrace>
<properties>
15 years, 4 months
JBoss Cache SVN: r7188 - in core/trunk/src: test/java/org/jboss/cache/buddyreplication and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-11-24 13:01:37 -0500 (Mon, 24 Nov 2008)
New Revision: 7188
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
Log:
fix and ut for https://jira.jboss.org/jira/browse/JBCACHE-1445
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java 2008-11-24 07:17:06 UTC (rev 7187)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java 2008-11-24 18:01:37 UTC (rev 7188)
@@ -32,6 +32,7 @@
import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
import org.jboss.cache.commands.read.GetDataMapCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
@@ -41,6 +42,8 @@
import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
import org.jboss.cache.commands.tx.CommitCommand;
import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -143,9 +146,35 @@
}
}
+
+ /**
+ * Make sure you also run a cleanup if we have an 1pc.
+ */
@Override
+ public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ if (command.isOnePhaseCommit())
+ {
+ return dataGravitationCleanupOnCommit(ctx, command);
+ }
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
{
+ return dataGravitationCleanupOnCommit(ctx, command);
+ }
+
+ @Override
+ public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ return visitPrepareCommand(ctx, command);
+ }
+
+ private Object dataGravitationCleanupOnCommit(InvocationContext ctx, VisitableCommand command)
+ throws Throwable
+ {
GlobalTransaction gtx = ctx.getGlobalTransaction();
try
{
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java 2008-11-24 07:17:06 UTC (rev 7187)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java 2008-11-24 18:01:37 UTC (rev 7188)
@@ -2,10 +2,14 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.util.CachePrinter;
import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
import java.util.List;
/**
@@ -39,6 +43,45 @@
testBuddy(true);
}
+ /**
+ * UT for https://jira.jboss.org/jira/browse/JBCACHE-1445.
+ */
+ public void testDataGravitationCleanup1Pc() throws Exception
+ {
+ CacheSPI cache0 = createCache(1, null, true, false);
+ cache0.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+ CacheSPI cache1 = createCache(1, null, true, false);
+ cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+ cache0.start();
+ cache1.start();
+ try
+ {
+ waitForSingleBuddy(cache0, cache1);
+
+ Fqn fqn = Fqn.fromString("/a/b/c");
+
+ assert null == cache0.get(fqn, "k");
+ cache0.put(fqn, "key", "val");
+
+ ReplicationListener replicationListener = ReplicationListener.getReplicationListener(cache0);
+ replicationListener.expect(DataGravitationCleanupCommand.class);
+ TransactionManager transactionManager = cache1.getTransactionManager();
+
+ transactionManager.begin();
+ assert cache1.get(fqn, "key").equals("val");
+ transactionManager.commit();
+ replicationListener.waitForReplicationToOccur(1000);
+
+ assert !cache0.exists(fqn);
+
+ System.out.println(CachePrinter.printCacheDetails(cache0));
+ } finally
+ {
+ TestingUtil.killCaches(cache0, cache1);
+ }
+ }
+
+
private void testDataOwner(boolean optimistic) throws Exception
{
List<CacheSPI<Object, Object>> caches = createCaches(1, 2, false, true, optimistic);
15 years, 4 months