JBoss Cache SVN: r4976 - cache-bench-fwk/trunk/lib.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-04 04:45:35 -0500 (Fri, 04 Jan 2008)
New Revision: 4976
Added:
cache-bench-fwk/trunk/lib/smartfrog-3.12.014.jar
Log:
SF integration
Added: cache-bench-fwk/trunk/lib/smartfrog-3.12.014.jar
===================================================================
(Binary files differ)
Property changes on: cache-bench-fwk/trunk/lib/smartfrog-3.12.014.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
16 years, 11 months
JBoss Cache SVN: r4975 - in cache-bench-fwk/trunk: conf and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-04 04:44:30 -0500 (Fri, 04 Jan 2008)
New Revision: 4975
Added:
cache-bench-fwk/trunk/smartfrog/cacheBenchComponent.sf
cache-bench-fwk/trunk/smartfrog/main.sf
cache-bench-fwk/trunk/src/org/cachebench/smartfrog/
cache-bench-fwk/trunk/src/org/cachebench/smartfrog/CacheBenchmarkPrim.java
Modified:
cache-bench-fwk/trunk/build.xml
cache-bench-fwk/trunk/conf/cachebench.xml
cache-bench-fwk/trunk/runNode.sh
cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java
cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java
Log:
SF integration
Modified: cache-bench-fwk/trunk/build.xml
===================================================================
--- cache-bench-fwk/trunk/build.xml 2008-01-04 02:36:51 UTC (rev 4974)
+++ cache-bench-fwk/trunk/build.xml 2008-01-04 09:44:30 UTC (rev 4975)
@@ -60,6 +60,7 @@
<pathelement location="${module.framework.basedir}/lib/commons-digester.jar"/>
<pathelement location="${module.framework.basedir}/lib/commons-beanutils.jar"/>
<pathelement location="${module.framework.basedir}/lib/commons-math-1.0.jar"/>
+ <pathelement location="${module.framework.basedir}/lib/smartfrog-3.12.014.jar"/>
<pathelement location="${module.framework.basedir}/conf"/>
</path>
@@ -149,6 +150,7 @@
<target name="clean.module.framework" description="cleanup module">
<delete dir="${framework.output.dir}"/>
<delete dir="${framework.testoutput.dir}"/>
+ <delete dir="${basedir}/smartfrog/sfClasses"/>
</target>
@@ -504,4 +506,15 @@
</java>
</target>
+ <target name="deploy.sf" depends="compile.module.framework" description="builds the smartfrog jar and deploys it">
+ <rmic classname="org.cachebench.smartfrog.CacheBenchmarkPrim" base="${framework.output.dir}" verify="true" debug="true">
+ <classpath refid="framework.module.classpath"/>
+ </rmic>
+ <delete dir="${basedir}/smartfrog/sfClasses"/>
+ <mkdir dir="${basedir}/smartfrog/sfClasses"/>
+ <jar destfile="${basedir}/smartfrog/sfClasses/cacheBenchmark-sf.jar">
+ <fileset dir="${framework.output.dir}" includes="**/smartfrog/**"/>
+ <fileset dir="${basedir}/smartfrog" excludes="**/sfClasses/**"/>
+ </jar>
+ </target>
</project>
Modified: cache-bench-fwk/trunk/conf/cachebench.xml
===================================================================
--- cache-bench-fwk/trunk/conf/cachebench.xml 2008-01-04 02:36:51 UTC (rev 4974)
+++ cache-bench-fwk/trunk/conf/cachebench.xml 2008-01-04 09:44:30 UTC (rev 4975)
@@ -21,8 +21,8 @@
-->
<cluster bindAddress="127.0.0.1">
<member host="127.0.0.1" port="7800"/>
- <!--<member host="127.0.0.1" port="7801"/>-->
- <!--<member host="127.0.0.1" port="7802"/>-->
+ <member host="127.0.0.1" port="7801"/>
+ <member host="127.0.0.1" port="7802"/>
</cluster>
<!-- Each testcase represents either a single configuration or a cacheing product.
Modified: cache-bench-fwk/trunk/runNode.sh
===================================================================
--- cache-bench-fwk/trunk/runNode.sh 2008-01-04 02:36:51 UTC (rev 4974)
+++ cache-bench-fwk/trunk/runNode.sh 2008-01-04 09:44:30 UTC (rev 4975)
@@ -45,7 +45,7 @@
echo executing command $START_NODE_COMMAND
$START_NODE_COMMAND
else
- TO_EXECUTE="java -cp $CLASSPATH $SYS_PROPS org.cachebench.CacheBenchmarkRunner $3"
+ TO_EXECUTE="java -cp $CLASSPATH $3 $SYS_PROPS org.cachebench.CacheBenchmarkRunner $4"
echo executing $TO_EXECUTE
java -cp $CLASSPATH $3 $SYS_PROPS org.cachebench.CacheBenchmarkRunner $4
fi
Added: cache-bench-fwk/trunk/smartfrog/cacheBenchComponent.sf
===================================================================
--- cache-bench-fwk/trunk/smartfrog/cacheBenchComponent.sf (rev 0)
+++ cache-bench-fwk/trunk/smartfrog/cacheBenchComponent.sf 2008-01-04 09:44:30 UTC (rev 4975)
@@ -0,0 +1,20 @@
+#include "org/smartfrog/components.sf"
+
+BaseCacheBenchPrim extends Prim {
+ sfClass "org.cachebench.smartfrog.CacheBenchmarkPrim";
+
+ scriptToExec "runNode.sh"
+
+ //FQN of the directory where the framework was checked out (noramally is th eparent of the dir that contains this file)
+ //this should be edited
+ cacheBenchmarkHome "c:/projects/jboss/cache/benchmark/cache-bench-fwk";
+
+ //should be the name of a subdirectory of 'cache-products' directory.
+ cacheDistribution "jbosscache-2.0.0";
+
+ //defines on how many nodes the benchmark will run
+ clusterSize 1;
+
+ //might take a value from 0..max_nr_of_nodes, representing the index of the current node in the cluster
+ nodeIndex TBD;
+}
\ No newline at end of file
Added: cache-bench-fwk/trunk/smartfrog/main.sf
===================================================================
--- cache-bench-fwk/trunk/smartfrog/main.sf (rev 0)
+++ cache-bench-fwk/trunk/smartfrog/main.sf 2008-01-04 09:44:30 UTC (rev 4975)
@@ -0,0 +1,13 @@
+#include "org/smartfrog/components.sf"
+#include "cacheBenchComponent.sf"
+
+sfConfig extends Compound {
+
+ node1 extends BaseCacheBenchPrim{
+ sfProcessHost "localhost";
+ nodeIndex 1;
+ scriptToExec "runNode.bat"
+ }
+
+}
+
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java 2008-01-04 02:36:51 UTC (rev 4974)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java 2008-01-04 09:44:30 UTC (rev 4975)
@@ -1,5 +1,8 @@
package org.cachebench.config;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
@@ -11,8 +14,13 @@
*/
public class ClusterConfig
{
+
+ public static final Log log = LogFactory.getLog(ClusterConfig.class);
+
private int currentNodeIndex = -1;
+ private int clusterSize = -1;
+
private List<NodeAddress> members = new ArrayList<NodeAddress>();
private String bindAddress;
@@ -35,18 +43,36 @@
public List<NodeAddress> getMembers()
{
+ if (members.size() > getClusterSize())
+ {
+ return members.subList(0, clusterSize);
+ }
return members;
}
public int getPortForThisNode()
{
- NodeAddress address = members.get(getCurrentNodeIndex());
+ NodeAddress address = getMembers().get(getCurrentNodeIndex());
return Integer.parseInt(address.getPort());
}
public int getClusterSize()
{
- return members.size();
+ if (clusterSize < 0)
+ {
+ String clusterSizeStr = System.getProperty("clusterSize");
+ if (clusterSizeStr != null)
+ {
+ int size = Integer.parseInt(clusterSizeStr);
+ log.info("Received cluster size: " + size);
+ clusterSize = size;
+ }
+ else
+ {
+ return members.size();
+ }
+ }
+ return clusterSize;
}
public boolean isMaster()
@@ -59,11 +85,6 @@
members.add(member);
}
- public void setCurrentNodeIndex(int currentNodeIndex)
- {
- this.currentNodeIndex = currentNodeIndex;
- }
-
public String getBindAddress()
{
return bindAddress;
@@ -86,6 +107,6 @@
public String toString()
{
- return "{bindAddress:" + bindAddress + ", members:" + members + "}";
+ return "{bindAddress:" + bindAddress + ", members:" + getMembers() + ", clusterSize:" + getClusterSize() + "}";
}
}
Added: cache-bench-fwk/trunk/src/org/cachebench/smartfrog/CacheBenchmarkPrim.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/smartfrog/CacheBenchmarkPrim.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/smartfrog/CacheBenchmarkPrim.java 2008-01-04 09:44:30 UTC (rev 4975)
@@ -0,0 +1,90 @@
+package org.cachebench.smartfrog;
+
+import org.smartfrog.sfcore.common.SmartFrogException;
+import org.smartfrog.sfcore.common.SmartFrogResolutionException;
+import org.smartfrog.sfcore.logging.LogSF;
+import org.smartfrog.sfcore.prim.Prim;
+import org.smartfrog.sfcore.prim.PrimImpl;
+import org.smartfrog.sfcore.prim.TerminationRecord;
+
+import java.io.File;
+import java.rmi.RemoteException;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class CacheBenchmarkPrim extends PrimImpl implements Prim
+{
+ private static LogSF log;
+
+ private int nodeIndex = -1;
+ private String cacheDistribution;
+ private File toRunIn;
+ private int clusterSize = -1;
+ private String scriptToExec;
+
+ public CacheBenchmarkPrim() throws RemoteException
+ {
+ }
+
+ public synchronized void sfDeploy() throws SmartFrogException, RemoteException
+ {
+ super.sfDeploy();
+ log = super.sfGetApplicationLog();
+ log.setLevel(LogSF.LOG_LEVEL_ALL);
+ log.trace("deploy started");
+ //reading the attributes here
+ nodeIndex = (Integer) sfResolve("nodeIndex");
+ log.info("Received current index: " + nodeIndex);
+ cacheDistribution = (String) sfResolve("cacheDistribution");
+ log.info("Received cache distribution: " + cacheDistribution);
+ toRunIn = getFwkHomeDir();
+ log.info("Received homedir: " + toRunIn);
+ clusterSize = (Integer)sfResolve("clusterSize");
+ log.info("Received cluster size: " + clusterSize);
+ scriptToExec = (String) sfResolve("scriptToExec");
+ log.info("Received stringToExec: " + scriptToExec);
+ log.trace("Deploy finished");
+ }
+
+ public synchronized void sfStart() throws SmartFrogException, RemoteException
+ {
+ super.sfStart();
+ log.trace("parsing the configuration...");
+ try
+ {
+ String command = scriptToExec + " " + nodeIndex + " " + cacheDistribution + " -DclusterSize=" + clusterSize;
+ log.info("Executing command: " + command);
+ Process process = Runtime.getRuntime().exec(command, null, toRunIn);
+ int exitValue = process.waitFor();
+ if (exitValue != 0)
+ {
+ sfTerminate(new TerminationRecord(TerminationRecord.ABNORMAL, "we have an not 0 exit code: " + exitValue, null));
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Unexpected error:" + e.getMessage(), e);
+ throw new RemoteException("Unexpected error",e);
+ }
+ }
+
+ private File getFwkHomeDir()
+ throws SmartFrogResolutionException, RemoteException
+ {
+ File toRunIn;
+ String cacheBenchmarkHome = sfResolve("cacheBenchmarkHome") + "";
+ toRunIn = new File(cacheBenchmarkHome);
+ if (!toRunIn.isDirectory())
+ {
+ log.error("cacheBenchmarkHome is not specified correctly: " + cacheBenchmarkHome);
+ }
+ return toRunIn;
+ }
+
+ protected synchronized void sfTerminateWith(TerminationRecord terminationRecord)
+ {
+ super.sfTerminateWith(terminationRecord);
+ log.trace("sfTerminateWith called with value:" + terminationRecord);
+ }
+}
Modified: cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java 2008-01-04 02:36:51 UTC (rev 4974)
+++ cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java 2008-01-04 09:44:30 UTC (rev 4975)
@@ -191,7 +191,6 @@
cache.put(key + cycleNumber, value);
long statValue = (System.currentTimeMillis() - startTime);
stats.addValue(statValue);
- log.debug("The Put stat : " + statValue);
}
else
{
@@ -201,7 +200,6 @@
sCache.putSerializable(key + cycleNumber, sValue);
long statValue = (System.currentTimeMillis() - startTime);
stats.addValue(statValue);
- log.debug("The Put stat : " + statValue);
}
}
catch (Exception e)
16 years, 11 months
JBoss Cache SVN: r4974 - core/trunk/src/main/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 21:36:51 -0500 (Thu, 03 Jan 2008)
New Revision: 4974
Modified:
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
Log:
Perf improvements
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-01-04 01:59:48 UTC (rev 4973)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2008-01-04 02:36:51 UTC (rev 4974)
@@ -230,11 +230,11 @@
private Fqn extractFqnRegion(MethodCall call) throws Exception
{
Fqn fqn;
- if (call.getMethod().equals(MethodDeclarations.replicateMethod))
+ if (isReplicateMethod(call))
{
fqn = extractFqnFromMethodCall(call);
}
- else if (call.getMethod().equals(MethodDeclarations.replicateAllMethod))
+ else if (isReplicateAllMethod(call))
{
fqn = extractFqnFromListOfMethodCall(call);
}
@@ -247,6 +247,15 @@
return r == null ? null : r.getFqn();
}
+ protected boolean isReplicateMethod(MethodCall call)
+ {
+ return call.getMethodId() == MethodDeclarations.replicateMethod_id || call.getMethod().equals(MethodDeclarations.replicateMethod);
+ }
+
+ protected boolean isReplicateAllMethod(MethodCall call)
+ {
+ return call.getMethodId() == MethodDeclarations.replicateAllMethod_id || call.getMethod().equals(MethodDeclarations.replicateAllMethod);
+ }
// --------- Marshalling methods
private void marshallObject(Object o, ObjectOutputStream out, Map<Object, Integer> refMap) throws Exception
@@ -445,9 +454,9 @@
if (!isRoot)
{
out.writeShort(fqn.size());
- for (int i = 0; i < fqn.size(); i++)
+ for (Object o : fqn.peekElements())
{
- marshallObject(fqn.get(i), out, refMap);
+ marshallObject(o, out, refMap);
}
}
}
16 years, 11 months
JBoss Cache SVN: r4973 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 20:59:48 -0500 (Thu, 03 Jan 2008)
New Revision: 4973
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
Log:
JBCACHE-881 - cache node references in invocation context to save on multiple expensive cache.peek() calls.
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-01-04 01:59:29 UTC (rev 4972)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-01-04 01:59:48 UTC (rev 4973)
@@ -11,6 +11,8 @@
import org.jboss.cache.transaction.GlobalTransaction;
import javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
/**
* This context holds information specific to a method invocation.
@@ -28,12 +30,49 @@
private boolean localRollbackOnly;
private MethodCall methodCall;
+ // used to store cache peeks within the scope of a single context. Performing a cache peek can be a huge bottle neck.
+ // See JBCACHE-811
+ private Map<Fqn, NodeSPI> peekedNodes = new HashMap<Fqn, NodeSPI>();
+
+ /**
+ * Retrieves a node that may have previously been "peeked" within the scope of the same invocation.
+ *
+ * @param f fqn of node to find
+ * @return node, if previously peeked, or null if not.
+ * @since 2.1.0
+ */
+ public NodeSPI getPeekedNode(Fqn f)
+ {
+ return peekedNodes.get(f);
+ }
+
+ /**
+ * Adds a node to the previously peeked list.
+ *
+ * @param n node to add
+ * @param f fqn of node
+ * @since 2.1.0
+ */
+ public void savePeekedNode(NodeSPI n, Fqn f)
+ {
+ peekedNodes.put(f, n);
+ }
+
+ /**
+ * Wipe list of previously peeked nodes.
+ *
+ * @since 2.1.0
+ */
+ public void wipePeekedNodes()
+ {
+ peekedNodes.clear();
+ }
+
public void setLocalRollbackOnly(boolean localRollbackOnly)
{
this.localRollbackOnly = localRollbackOnly;
}
-
/**
* Retrieves the transaction associated with this invocation
*
16 years, 11 months
JBoss Cache SVN: r4972 - core/trunk/src/main/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 20:59:29 -0500 (Thu, 03 Jan 2008)
New Revision: 4972
Modified:
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/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
JBCACHE-881 - cache node references in invocation context to save on multiple expensive cache.peek() calls.
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -49,6 +49,7 @@
{
initLogger();
isActivation = true;
+ useCacheStore = false;
}
@Override
@@ -176,7 +177,7 @@
private void removeNodeFromCacheLoader(InvocationContext ctx, Fqn fqn) throws Throwable
{
NodeSPI n;
- if (((n = getNode(fqn)) != null) && n.isDataLoaded() && loader.exists(fqn))
+ if (((n = peekNode(ctx, fqn, false, true)) != null) && n.isDataLoaded() && loader.exists(fqn))
{
// node not null and attributes have been loaded?
if (!n.getChildrenDirect().isEmpty())
@@ -338,9 +339,9 @@
// AND it was found in the cache loader (nodeLoaded = true).
// Then notify the listeners that the node has been activated.
Fqn fqn = (Fqn) args[1];
- if (fqn != null && cache.peek(fqn, false) != null && loader.exists(fqn))
+ if (fqn != null && peekNode(ctx, fqn, false, false) != null && loader.exists(fqn))
{
- NodeSPI n = getNode(fqn);// don't load
+ NodeSPI n = peekNode(ctx, fqn, false, true);// don't load
// node not null and attributes have been loaded?
if (n != null && n.isDataLoaded())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -468,16 +468,6 @@
// nextInterceptor(m);
}
- /**
- * Retrieves a node from memory; doesn't access the cache loader
- *
- * @param fqn
- */
- protected NodeSPI getNode(Fqn fqn)
- {
- return cache.peek(fqn, true);
- }
-
private TransactionEntry getTransactionEntry(InvocationContext ctx)
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -212,7 +212,7 @@
{
loader.removeData(fqn);
// we need to mark this node as data loaded
- NodeSPI n = cache.peek(fqn, false);
+ NodeSPI n = peekNode(ctx, fqn, false, false);//cache.peek(fqn, false);
if (n != null)
{
n.setDataLoaded(true);
@@ -245,7 +245,7 @@
}
loader.removeData(fqn);
// if we are erasing all the data then consider this node loaded
- NodeSPI n = cache.peek(fqn, false);
+ NodeSPI n = peekNode(ctx, fqn, false, false);//cache.peek(fqn, false);
n.setDataLoaded(true);
return returnValue;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -172,7 +172,7 @@
}
else
{
- if (cache.peek(fqn, false) == null)
+ if (peekNode(ctx, fqn, false, false) == null)
{
if (trace) log.trace("Gravitating from local backup tree");
BackupData data = localBackupGet(fqn, ctx);
@@ -192,7 +192,7 @@
// Make sure I replicate to my buddies.
if (trace)
log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
- createNode(data.backupData, false);
+ createNode(ctx, data.backupData, false);
// very strange, the invocation contexts get twisted up here, and will need preservation.
// a bit crappy and hacky, all will be solved when we move to JBoss AOP in 2.1.0
@@ -379,13 +379,14 @@
}
@SuppressWarnings("unchecked")
- private void createNode(List<NodeData> nodeData, boolean localOnly) throws CacheException
+ private void createNode(InvocationContext ctx, List<NodeData> nodeData, boolean localOnly) throws CacheException
{
for (NodeData data : nodeData)
{
if (localOnly)
{
- if (cache.peek(data.getFqn(), false) == null)
+// if (cache.peek(data.getFqn(), false) == null)
+ if (peekNode(ctx, data.getFqn(), false, false) == null)
{
createNodesLocally(data.getFqn(), data.getAttributes());
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -68,7 +68,7 @@
{
if (fqn != null && !canIgnoreEvent(fqn, NodeEventType.ADD_NODE_EVENT))
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT, 0));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT, 0), ctx);
}
}
return retVal;
@@ -86,7 +86,7 @@
Object retVal = nextInterceptor(ctx);
if (fqn != null && key != null && !canIgnoreEvent(fqn, NodeEventType.ADD_ELEMENT_EVENT))
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_ELEMENT_EVENT, 1));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_ELEMENT_EVENT, 1), ctx);
}
return retVal;
}
@@ -113,7 +113,7 @@
}
EvictedEventNode event = new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT, size);
event.setResetElementCount(eraseContents);
- registerEvictionEventToRegionManager(event);
+ registerEvictionEventToRegionManager(event, ctx);
}
}
return retVal;
@@ -140,7 +140,7 @@
{
size = data.size();
}
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT, size));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT, size), ctx);
}
}
return retVal;
@@ -162,7 +162,7 @@
{
if (fqn != null && key != null && !canIgnoreEvent(fqn, NodeEventType.REMOVE_ELEMENT_EVENT))
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.REMOVE_ELEMENT_EVENT, 1));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.REMOVE_ELEMENT_EVENT, 1), ctx);
}
}
return retVal;
@@ -183,7 +183,7 @@
{
if (fqn != null && !canIgnoreEvent(fqn, NodeEventType.VISIT_NODE_EVENT))
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT), ctx);
}
}
return retVal;
@@ -208,7 +208,7 @@
}
else if (fqn != null && key != null && !canIgnoreEvent(fqn, NodeEventType.VISIT_NODE_EVENT))
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.VISIT_NODE_EVENT), ctx);
}
return retVal;
}
@@ -219,7 +219,7 @@
Object retVal = nextInterceptor(ctx);
if (fqn != null && !canIgnoreEvent(fqn, NodeEventType.REMOVE_NODE_EVENT))
{
- registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.REMOVE_NODE_EVENT));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.REMOVE_NODE_EVENT), ctx);
}
return retVal;
}
@@ -230,7 +230,7 @@
return handleRemoveNodeMethod(ctx, tx, fqn, createUndoOps);
}
- private void registerEvictionEventToRegionManager(EvictedEventNode event)
+ private void registerEvictionEventToRegionManager(EvictedEventNode event, InvocationContext ctx)
{
if (event == null)
{
@@ -238,7 +238,7 @@
return;
}
- NodeSPI<?, ?> nodeSPI = cache.peek(event.getFqn(), false);
+ NodeSPI<?, ?> nodeSPI = peekNode(ctx, event.getFqn(), false, false);//cache.peek(event.getFqn(), false);
//we do not trigger eviction events for resident nodes
if (nodeSPI != null && nodeSPI.isResident())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -25,7 +25,9 @@
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
@@ -220,4 +222,29 @@
+ (getLast() == null ? null : getLast().getClass())
+ "}";
}
+
+ /**
+ * First checks the invocation context for previously obtained reference to a node, if this doesn't exist, performs
+ * a cache.peek() and holds on to the node reference.
+ *
+ * @param ctx invocation context
+ * @param f fqn to find
+ * @param forceRefresh forces calling cache.peek() even if we hold a reference to the relevant node.
+ * @param includeDeletedNodes includes nodes marked for deletion if this is true
+ * @return a node, or null if one cannot be found.
+ * @since 2.1.0
+ */
+ public NodeSPI peekNode(InvocationContext ctx, Fqn f, boolean forceRefresh, boolean includeDeletedNodes)
+ {
+ NodeSPI n;
+ if (forceRefresh || (n = ctx.getPeekedNode(f)) == null)
+ {
+ n = cache.peek(f, true);
+ // put this in the invocation cache
+ ctx.savePeekedNode(n, f);
+ }
+
+ if (n != null && !includeDeletedNodes && n.isDeleted()) return null;
+ return n;
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -107,6 +107,8 @@
copyInvocationScopeOptionsToTxScope(ctx);
}
}
+
+ ctx.wipePeekedNodes();
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -136,7 +136,8 @@
*/
private void createNode(InvocationContext ctx, Fqn targetFqn, boolean suppressNotification) throws CacheException
{
- if (cache.peek(targetFqn, false) != null) return;
+// if (cache.peek(targetFqn, false) != null) return;
+ if (peekNode(ctx, targetFqn, false, false) != null) return;
// we do nothing if targetFqn is null
if (targetFqn == null) return;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -47,7 +47,7 @@
{
// evict method local doesn't hold attributes therefore we have
// to get them manually
- Map attributes = getNodeAttributes(fqn);
+ Map attributes = getNodeAttributes(ctx, fqn);
// notify listeners that this node is about to be passivated
cache.getNotifier().notifyNodePassivated(fqn, true, attributes, ctx);
loader.put(fqn, attributes);
@@ -88,13 +88,13 @@
/**
* Returns attributes for a node.
*/
- private Map getNodeAttributes(Fqn fqn) throws NodeNotLoadedException
+ private Map getNodeAttributes(InvocationContext ctx, Fqn fqn) throws NodeNotLoadedException
{
if (fqn == null)
{
throw new NodeNotLoadedException();
}
- NodeSPI n = cache.peek(fqn, true);
+ NodeSPI n = peekNode(ctx, fqn, false, true);
if (n != null)
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-04 01:58:33 UTC (rev 4971)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-04 01:59:29 UTC (rev 4972)
@@ -133,7 +133,8 @@
acquireLocksWithTimeout(ctx, fqn, lockType, false, false, false, false);
if (recursive)
{
- acquireLocksOnChildren(cache.peek(fqn, false), lockType, ctx);
+ //acquireLocksOnChildren(cache.peek(fqn, false), lockType, ctx);
+ acquireLocksOnChildren(peekNode(ctx, fqn, false, false), lockType, ctx);
}
return null;
}
@@ -208,18 +209,18 @@
{
cache.getTransactionTable().get(ctx.getGlobalTransaction()).addRemovedNode(from);
}
- acquireLocksOnChildren(cache.peek(from, true), NodeLock.LockType.WRITE, ctx);
+ acquireLocksOnChildren(peekNode(ctx, from, false, true), NodeLock.LockType.WRITE, ctx);
}
if (to != null && !(configuration.getIsolationLevel() == IsolationLevel.NONE))
{
//now for an RL for the new parent.
if (trace) log.trace("Attempting to get RL on new parent [" + to + "]");
lock(ctx, to, NodeLock.LockType.READ, false, timeout, false, false);
- acquireLocksOnChildren(cache.peek(to, true), NodeLock.LockType.READ, ctx);
+ acquireLocksOnChildren(peekNode(ctx, to, false, true), NodeLock.LockType.READ, ctx);
}
Object retValue = nextInterceptor(ctx);
// do a REAL remove here.
- NodeSPI n = cache.peek(from, true);
+ NodeSPI n = peekNode(ctx, from, false, true);
if (n != null)
{
n.getLock().releaseAll(Thread.currentThread());
@@ -239,7 +240,7 @@
if (ctx.getGlobalTransaction() == null)
{
cacheImpl.realRemove(fqn, true);
- NodeSPI n = cache.peek(fqn, true);
+ NodeSPI n = peekNode(ctx, fqn, false, true);
if (n != null)
{
n.getLock().releaseAll(Thread.currentThread());
@@ -336,7 +337,7 @@
created = lock(ctx, fqn, lockType, createIfNotExists, timeout, acquireLockOnParent, reverseRemoveCheck);
firstTry = false;
}
- while (createIfNotExists && cache.peek(fqn, true) == null);// keep trying until we have the lock (fixes concurrent remove())
+ while (createIfNotExists && peekNode(ctx, fqn, false, true) == null);// keep trying until we have the lock (fixes concurrent remove())
return created;
}
@@ -489,7 +490,8 @@
{
return true;// we're doing a remove and we've reached the PARENT node of the target to be removed.
}
- if (!isTargetNode && cache.peek(targetFqn.getAncestor(currentNodeIndex + 2), false) == null)
+ if (!isTargetNode && peekNode(ctx, targetFqn.getAncestor(currentNodeIndex + 2), false, false) == null)
+ //if (!isTargetNode && cache.peek(targetFqn.getAncestor(currentNodeIndex + 2), false) == null)
//if (!isTargetNode && cache.peek(new Fqn(currentNode.getFqn(), targetFqn.get(currentNodeIndex + 1)), false) == null)
{
return createIfNotExists;// we're at a node in the tree, not yet at the target node, and we need to create the next node. So we need a WL here.
16 years, 11 months
JBoss Cache SVN: r4971 - core/trunk/src/test/java/org/jboss/cache/loader/deadlock.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 20:58:33 -0500 (Thu, 03 Jan 2008)
New Revision: 4971
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java
Log:
re-added test
Modified: core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java 2008-01-04 01:07:18 UTC (rev 4970)
+++ core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java 2008-01-04 01:58:33 UTC (rev 4971)
@@ -7,6 +7,7 @@
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.loader.AbstractCacheLoaderTestBase;
+import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -62,7 +63,7 @@
* CacheLoader/StoreInterceptor's...</li>
* </ul>
*/
-@Test(groups = {"functional"}, enabled = false)
+@Test(groups = {"functional"}, enabled = true)
// Disabling since this has issues with ReadWriteWithUpgradeLock. See JBCACHE-461
public class ConcurrentCreationDeadlockTest extends AbstractCacheLoaderTestBase
{
@@ -161,47 +162,8 @@
cache.start();
}
- /**
- * Test for a local cache without cache loader and single modification per
- * transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestLocalNoCacheLoader1Modification() throws Exception
- {
- startCache(Configuration.CacheMode.LOCAL, null);
- performTest(1);
- }
/**
- * Test for a local cache without cache loader and two modifications per
- * transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestLocalNoCacheLoader2Modifications()
- throws Exception
- {
- startCache(Configuration.CacheMode.LOCAL, null);
- performTest(2);
- }
-
- /**
- * Test for a local cache with cache loader and single modification per
- * transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestLocalCacheLoader1Modification() throws Exception
- {
- startCache(Configuration.CacheMode.LOCAL, "org.jboss.cache.loader.DummyCacheLoader");
- performTest(1);
- }
-
- /**
* Test for a local cache with cache loader and two modifications per
* transaction.<br>
* This test does very often fail with a TimeoutException.
@@ -210,109 +172,11 @@
*/
public void testLocalCacheLoader2Modifications() throws Exception
{
- startCache(Configuration.CacheMode.LOCAL, "org.jboss.cache.loader.DummyCacheLoader");
+ startCache(Configuration.CacheMode.LOCAL, DummyInMemoryCacheLoader.class.getName());
performTest(2);
}
/**
- * Test for an asynchronously replicated cache without cache loader and
- * single modification per transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplAsyncNoCacheLoader1Modification()
- throws Exception
- {
- startCache(Configuration.CacheMode.REPL_ASYNC, null);
- performTest(1);
- }
-
- /**
- * Test for an asynchronously replicated cache without cache loader and two
- * modifications per transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplAsyncNoCacheLoader2Modifications()
- throws Exception
- {
- startCache(Configuration.CacheMode.REPL_ASYNC, null);
- performTest(2);
- }
-
- /**
- * Test for an asynchronously replicated cache with cache loader and single
- * modification per transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplAsyncCacheLoader1Modification()
- throws Exception
- {
- startCache(Configuration.CacheMode.REPL_ASYNC, "org.jboss.cache.loader.DummyCacheLoader");
- performTest(1);
- }
-
- /**
- * Test for an asynchronously replicated cache with cache loader and two
- * modification per transaction.<br>
- * This test mysteriously never fails, although it should as the LOCAL
- * and REPL_SYNC do.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplAsyncCacheLoader2Modifications()
- throws Exception
- {
- startCache(Configuration.CacheMode.REPL_ASYNC, "org.jboss.cache.loader.DummyCacheLoader");
- performTest(2);
- }
-
- /**
- * Test for a synchronously replicated cache without cache loader and single
- * modification per transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplSyncNoCacheLoader1Modification()
- throws Exception
- {
- startCache(Configuration.CacheMode.REPL_SYNC, null);
- performTest(1);
- }
-
- /**
- * Test for a synchronously replicated cache without cache loader and two
- * modification per transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplSyncNoCacheLoader2Modifications()
- throws Exception
- {
- startCache(Configuration.CacheMode.REPL_SYNC, null);
- performTest(2);
- }
-
- /**
- * Test for a synchronously replicated cache with cache loader and single
- * modification per transaction.<br>
- * This test has never failed up to now.
- *
- * @throws Exception Any exception if thrown by the cache.
- */
- public void disabledtestReplSyncCacheLoader1Modification() throws Exception
- {
- startCache(Configuration.CacheMode.REPL_SYNC, "org.jboss.cache.loader.DummyCacheLoader");
- performTest(1);
- }
-
- /**
* Test for a synchronously replicated cache with cache loader and two
* modifications per transaction.<br>
* This test fails very often with a TimeoutException.
@@ -322,7 +186,7 @@
public void testReplSyncCacheLoader2Modifications()
throws Exception
{
- startCache(Configuration.CacheMode.REPL_SYNC, "org.jboss.cache.loader.DummyCacheLoader");
+ startCache(Configuration.CacheMode.REPL_SYNC, DummyInMemoryCacheLoader.class.getName());
performTest(2);
}
16 years, 11 months
JBoss Cache SVN: r4970 - core/trunk/src/main/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 20:07:18 -0500 (Thu, 03 Jan 2008)
New Revision: 4970
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
Log:
restored setting isActivation flag
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-04 00:48:28 UTC (rev 4969)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-04 01:07:18 UTC (rev 4970)
@@ -48,6 +48,7 @@
public ActivationInterceptor()
{
initLogger();
+ isActivation = true;
}
@Override
16 years, 11 months
JBoss Cache SVN: r4969 - in core/trunk/src: main/java/org/jboss/cache/util and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 19:48:28 -0500 (Thu, 03 Jan 2008)
New Revision: 4969
Added:
core/trunk/src/main/java/org/jboss/cache/util/BitEncodedIntegerSet.java
core/trunk/src/test/java/org/jboss/cache/util/BitEncodedIntegerSetTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
Log:
Moved bit encoding of method ints into separate utility class
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-01-04 00:48:28 UTC (rev 4969)
@@ -8,6 +8,7 @@
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.util.BitEncodedIntegerSet;
import org.jgroups.Address;
import java.util.List;
@@ -34,22 +35,15 @@
public abstract class MethodDispacherInterceptor extends Interceptor
{
/**
- * Methods that have been overridden. This is encoded in the bits of an integer, with each ordinal position representing a method id.
- * This was originally a Set but that proved way too inefficient with constant boxing/unboxing of ints and doing Set.contains()
- * for each invocation for each interceptor. - Manik, Jan '08.
+ * Methods that have been overridden.
*/
- private long overriddenMethods = 0;
+ private BitEncodedIntegerSet overriddenMethods = new BitEncodedIntegerSet();
protected MethodDispacherInterceptor()
{
findOverriddenMethods();
}
- private boolean noHandlersRegistered(int id)
- {
- return (overriddenMethods & ((long) 1 << id)) < 1;
- }
-
/**
* Acts like a 'switch case' that delegates the call to the appropriate method.
*/
@@ -62,7 +56,7 @@
return nextInterceptor(ctx);
}
MethodCall m = ctx.getMethodCall();
- if (noHandlersRegistered(m.getMethodId()))
+ if (!overriddenMethods.contains(m.getMethodId()))
{
if (trace) log.trace("Not registered for any handlers, passing up the chain.");
return nextInterceptor(ctx);
@@ -524,7 +518,7 @@
try
{
currentClass.getDeclaredMethod(methodName, args);
- overriddenMethods |= ((long) 1 << methodId);
+ overriddenMethods.add(methodId);
}
catch (NoSuchMethodException e)
{
Added: core/trunk/src/main/java/org/jboss/cache/util/BitEncodedIntegerSet.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/BitEncodedIntegerSet.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/util/BitEncodedIntegerSet.java 2008-01-04 00:48:28 UTC (rev 4969)
@@ -0,0 +1,92 @@
+package org.jboss.cache.util;
+
+import net.jcip.annotations.NotThreadSafe;
+
+/**
+ * A Set that encodes integers as bits in a long. Does not implement java.util.Set since autoboxing is unnecessarily
+ * expensive for the ints stored, but follows very similar semantics to Set: no nulls, no duplicates, and order not guaranteed,
+ * and adds one more: this can only store ints from 0 to 63, inclusive.
+ * <p/>
+ * Integers in this set are packed into a single long, setting bit values accordingly and hence the strict range on allowable
+ * integers. The upshot is a guaranteed limit on how much memory is consumed, as well as very efficient operations on the set.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@NotThreadSafe
+public class BitEncodedIntegerSet
+{
+ private long encoded = 0;
+
+ /**
+ * Adds an integer to the set.
+ *
+ * @param i integer to add
+ */
+ public void add(int i)
+ {
+ encoded |= ((long) 1 << i);
+ }
+
+ /**
+ * Removes an integer from the set
+ *
+ * @param i integer to remove
+ */
+ public void remove(int i)
+ {
+ encoded &= ~((long) 1 << i);
+ }
+
+ /**
+ * Tests whether the set contains an integer
+ *
+ * @param i integer to check for
+ * @return true if contained; false otherwise
+ */
+ public boolean contains(int i)
+ {
+ return (encoded & ((long) 1 << i)) != 0;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BitEncodedIntegerSet that = (BitEncodedIntegerSet) o;
+
+ return encoded == that.encoded;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (int) (encoded ^ (encoded >>> 32));
+ }
+
+ /**
+ * Clears the set
+ */
+ public void clear()
+ {
+ encoded = 0;
+ }
+
+ /**
+ * Tests if the set is empty
+ *
+ * @return true if empty
+ */
+ public boolean isEmpty()
+ {
+ return encoded == 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BitEncodedSet (encoded as: " + Long.toBinaryString(encoded) + ")";
+ }
+}
Added: core/trunk/src/test/java/org/jboss/cache/util/BitEncodedIntegerSetTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/BitEncodedIntegerSetTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/util/BitEncodedIntegerSetTest.java 2008-01-04 00:48:28 UTC (rev 4969)
@@ -0,0 +1,113 @@
+package org.jboss.cache.util;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Test(groups = "functional")
+public class BitEncodedIntegerSetTest
+{
+ public void testLimits()
+ {
+ BitEncodedIntegerSet set = new BitEncodedIntegerSet();
+ set.add(0);
+ set.add(1);
+ set.add(62);
+ set.add(63);
+
+ for (int i = 0; i < 64; i++)
+ {
+ if (i == 0 || i == 1 || i == 62 || i == 63)
+ {
+ assert set.contains(i) : "Should contain " + i;
+ }
+ else
+ {
+ assert !set.contains(i) : "Should not contain " + i;
+ }
+ }
+ }
+
+ public void testRemoval()
+ {
+ BitEncodedIntegerSet set = new BitEncodedIntegerSet();
+ set.add(0);
+ set.add(1);
+ set.add(62);
+ set.add(63);
+
+ set.remove(0);
+ set.remove(63);
+
+ for (int i = 0; i < 64; i++)
+ {
+ if (i == 1 || i == 62)
+ {
+ assert set.contains(i);
+ }
+ else
+ {
+ assert !set.contains(i);
+ }
+ }
+
+ }
+
+ public void testClear()
+ {
+ BitEncodedIntegerSet set = new BitEncodedIntegerSet();
+ set.add(0);
+ set.add(1);
+ set.add(62);
+ set.add(63);
+
+ for (int i = 0; i < 64; i++)
+ {
+ if (i == 0 || i == 1 || i == 62 || i == 63)
+ {
+ assert set.contains(i);
+ }
+ else
+ {
+ assert !set.contains(i);
+ }
+ }
+ set.clear();
+
+ assert set.isEmpty();
+ }
+
+ public void testIsEmpty()
+ {
+ BitEncodedIntegerSet set = new BitEncodedIntegerSet();
+ assert set.isEmpty();
+ }
+
+ public void testEquals()
+ {
+ BitEncodedIntegerSet set1 = new BitEncodedIntegerSet();
+ BitEncodedIntegerSet set2 = new BitEncodedIntegerSet();
+
+ assert set1.equals(set2);
+ assert set2.equals(set1);
+
+ set1.add(1);
+
+ assert !set1.equals(set2);
+ assert !set2.equals(set1);
+
+ set2.add(1);
+
+ assert set1.equals(set2);
+ assert set2.equals(set1);
+
+ set2.add(2);
+
+ assert !set1.equals(set2);
+ assert !set2.equals(set1);
+ }
+
+
+}
16 years, 11 months
JBoss Cache SVN: r4968 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 14:17:09 -0500 (Thu, 03 Jan 2008)
New Revision: 4968
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/Fqn.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
core/trunk/src/test/java/org/jboss/cache/FqnTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java
core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Optimised fqns and interceptors
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -183,6 +183,8 @@
private CacheSPI spi;
private Interceptor interceptorChain;
+ private boolean trace;
+
/**
* Constructs an uninitialized CacheImpl.
*/
@@ -1074,7 +1076,7 @@
return;// node does not exist. Maybe it has been recursively removed.
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_evictSubtree(" + subtree + ")");
}
@@ -1124,7 +1126,7 @@
boolean localTx = deadOwner.getAddress().equals(getLocalAddress());
boolean broken = LockUtil.breakTransactionLock(lock, deadOwner, localTx, this);
- if (broken && log.isTraceEnabled())
+ if (broken && trace)
{
log.trace("Broke lock for node " + node.getFqn() +
" held by " + deadOwner);
@@ -1244,7 +1246,7 @@
public Object _get(Fqn<?> fqn, Object key, boolean sendNodeEvent) throws CacheException
{
InvocationContext ctx = spi.getInvocationContext();
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(new StringBuffer("_get(").append("\"").append(fqn).append("\", \"").append(key).append("\", \"").
append(sendNodeEvent).append("\")"));
@@ -1888,14 +1890,14 @@
}
if (validMembers.isEmpty())
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("destination list is empty, discarding call");
}
return null;
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("callRemoteMethods(): valid members are " + validMembers + " methods: " + method_call.getArgs()[0]);
}
@@ -1921,7 +1923,7 @@
return Collections.EMPTY_LIST;// async case
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("(" + getLocalAddress() + "): responses for method " + method_call.getName() + ":\n" + rsps);
}
@@ -1949,7 +1951,7 @@
if (value instanceof Exception && !(value instanceof ReplicationException))
{
// if we have any application-level exceptions make sure we throw them!!
- if (log.isTraceEnabled()) log.trace("Recieved exception'" + value + "' from " + rsp.getSender());
+ if (trace) log.trace("Recieved exception'" + value + "' from " + rsp.getSender());
throw (Exception) value;
}
retval.add(value);
@@ -2105,7 +2107,7 @@
public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, boolean erase_contents)
throws CacheException
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_put(" + tx + ", \"" + fqn + "\", " + data + " undo=" + create_undo_ops + " erase=" + erase_contents + ")");
}
@@ -2167,7 +2169,7 @@
public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean create_undo_ops)
throws CacheException
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(new StringBuffer("_put(").append(tx).append(", \"").
append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
@@ -2268,7 +2270,7 @@
NodeSPI parent_node;
MethodCall undo_op = null;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_remove(" + tx + ", \"" + fqn + "\", undo=" + create_undo_ops + ")");
}
@@ -2296,7 +2298,7 @@
n = findNode(fqn, version, true);
if (n == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("node " + fqn + " not found");
}
@@ -2389,7 +2391,7 @@
MethodCall undo_op = null;
Object old_value = null;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_remove(" + tx + ", \"" + fqn + "\", key=" + key + ")");
}
@@ -2469,7 +2471,7 @@
{
MethodCall undo_op = null;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_removeData(" + tx + ", \"" + fqn + "\")");
}
@@ -2560,7 +2562,7 @@
boolean create_undo_ops = false;
boolean sendNodeEvent = false;
boolean eviction = true;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_evict(" + fqn + ")");
}
@@ -2591,7 +2593,7 @@
if (!exists(fqn))
return true;// node does not exist
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_evict(" + fqn + ", " + version + ")");
}
@@ -2696,7 +2698,7 @@
throws CacheException
{
NodeSPI childNode = (NodeSPI) cn;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("_addChild(\"" + parent_fqn + "\", \"" + child_name + "\", node=" + childNode + ")");
}
@@ -2794,7 +2796,7 @@
// for now, perform a very simple series of getData calls.
InvocationContext ctx = spi.getInvocationContext();
- if (log.isTraceEnabled()) log.trace("Caller is asking for " + fqn);
+ if (trace) log.trace("Caller is asking for " + fqn);
try
{
@@ -2806,7 +2808,7 @@
Node actualNode = spi.getNode(fqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
- if (log.isTraceEnabled()) log.trace("In local tree, this is " + actualNode);
+ if (trace) log.trace("In local tree, this is " + actualNode);
Fqn backupNodeFqn = null;
if (actualNode == null && searchSubtrees)
@@ -2829,7 +2831,7 @@
ctx.getOptionOverrides().setSkipDataGravitation(true);
actualNode = spi.getNode(backupNodeFqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Looking for " + backupNodeFqn + ". Search result: " + actualNode);
if (actualNode != null) break;
}
@@ -3101,6 +3103,7 @@
}
// replace .s with _s otherwise Log4J will strip them out
log = LogFactory.getLog(category.toString());
+ trace = log.isTraceEnabled();
}
/**
@@ -3322,7 +3325,7 @@
TransactionEntry ent = configuration.isNodeLockingOptimistic() ? new OptimisticTransactionEntry() : new TransactionEntry();
ent.setTransaction(tx);
transactionTable.put(gtx, ent);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("created new GTX: " + gtx + ", local TX=" + tx);
}
@@ -3409,7 +3412,7 @@
if (n == null)
{
String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(errStr);
}
@@ -3433,7 +3436,7 @@
}
- if (log.isTraceEnabled()) log.trace("Performing a real remove for node " + f + ", marked for removal.");
+ if (trace) log.trace("Performing a real remove for node " + f + ", marked for removal.");
if (skipMarkerCheck || n.isDeleted())
{
if (n.getFqn().isRoot())
@@ -3482,7 +3485,7 @@
{
// we need to check the version of the data node...
DataVersion nodeVersion = toReturn.getVersion();
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("looking for optimistic node [" + fqn + "] with version [" + version + "]. My version is [" + nodeVersion + "]");
}
@@ -3569,7 +3572,7 @@
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Cache cluster properties: " + configuration.getClusterConfig());
}
@@ -3597,7 +3600,7 @@
disp.setRequestMarshaller(marshaller);
disp.setResponseMarshaller(marshaller);
- if (log.isTraceEnabled()) log.trace("Started with RpcDispatcher " + disp);
+ if (trace) log.trace("Started with RpcDispatcher " + disp);
}
private JChannel getMultiplexerChannel() throws CacheException
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -68,23 +68,24 @@
* Separator between FQN elements.
*/
public static final String SEPARATOR = "/";
-
+
private static final long serialVersionUID = -5351930616956603651L;
-
+
private static final Log log = LogFactory.getLog(Fqn.class);
-
+
private List<E> elements;
private transient int hash_code = 0;
+ private int size = 0;
/**
* Immutable root FQN.
*/
@SuppressWarnings("unchecked")
public static final Fqn ROOT = new Fqn();
-
+
/**
* A cached string representation of this Fqn, used by toString to it isn't calculated again every time.
- */
+ */
private String cachedStringRep;
/**
@@ -93,6 +94,7 @@
public Fqn()
{
elements = Collections.emptyList();
+ size = 0;
}
/**
@@ -120,10 +122,12 @@
{
// if not safe make a defensive copy
elements = safe ? names : new ArrayList<E>(names);
+ size = elements.size();
}
else
{
elements = Collections.emptyList();
+ size = 0;
}
}
@@ -162,6 +166,7 @@
elements.addAll(base.elements);
elements.addAll(relative);
this.elements = elements;
+ size = elements.size();
}
/**
@@ -176,6 +181,7 @@
elements.addAll(base.elements);
elements.addAll(Arrays.asList(childNames));
this.elements = elements;
+ size = elements.size();
}
/**
@@ -244,7 +250,7 @@
*/
public Fqn<E> getSubFqn(int startIndex, int endIndex)
{
- return new Fqn<E>(elements.subList(startIndex, endIndex));
+ return new Fqn<E>(elements.subList(startIndex, endIndex), true);
}
/**
@@ -252,7 +258,7 @@
*/
public int size()
{
- return elements.size();
+ return size;
}
/**
@@ -271,7 +277,7 @@
public E getLastElement()
{
if (isRoot()) return null;
- return elements.get(elements.size() - 1);
+ return elements.get(size - 1);
}
/**
@@ -280,7 +286,7 @@
*/
public boolean hasElement(E element)
{
- return elements.lastIndexOf(element) != -1;
+ return elements.indexOf(element) != -1;
}
/**
@@ -314,7 +320,7 @@
return false;
}
Fqn<?> other = (Fqn<?>) obj;
- return elements.equals(other.elements);
+ return size == other.size() && elements.equals(other.elements);
}
/**
@@ -362,7 +368,7 @@
public void writeExternal(ObjectOutput out) throws IOException
{
- out.writeShort(elements.size());
+ out.writeShort(size);
for (E element : elements)
{
out.writeObject(element);
@@ -372,9 +378,9 @@
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
- short length = in.readShort();
- this.elements = new ArrayList<E>(length);
- for (int i = 0; i < length; i++)
+ size = in.readShort();
+ this.elements = new ArrayList<E>(size);
+ for (int i = 0; i < size; i++)
{
E e = (E) in.readObject();
elements.add(e);
@@ -398,7 +404,7 @@
*/
public boolean isChildOf(Fqn<E> parentFqn)
{
- return parentFqn.elements.size() != elements.size() && isChildOrEquals(parentFqn);
+ return parentFqn.size() != size && isChildOrEquals(parentFqn);
}
/**
@@ -418,7 +424,7 @@
public boolean isChildOrEquals(Fqn<E> parentFqn)
{
List<E> parentList = parentFqn.elements;
- if (parentList.size() > elements.size())
+ if (parentList.size() > size)
{
return false;
}
@@ -470,18 +476,19 @@
*/
public Fqn<E> getParent()
{
- switch (elements.size())
+ switch (size)
{
case 0:
case 1:
return root();
default:
- return new Fqn<E>(elements.subList(0, elements.size() - 1));
+ return new Fqn<E>(elements.subList(0, size - 1));
}
}
-
+
@SuppressWarnings("unchecked")
- public static <T> Fqn<T> root() {
+ public static <T> Fqn<T> root()
+ {
return ROOT;
}
@@ -492,7 +499,7 @@
*/
public boolean isRoot()
{
- return elements.isEmpty();
+ return size == 0;
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -211,8 +211,7 @@
public static String getGroupNameFromAddress(Object address)
{
- String s = address.toString();
- return s.replace(':', '_');
+ return address.toString().replace(':', '_');
}
/**
@@ -622,12 +621,13 @@
{
if (isBackupFqn(origFqn))
throw new CacheException("Cannot make a backup Fqn from a backup Fqn! Attempting to create a backup of " + origFqn);
- List<Object> elements = new ArrayList<Object>();
+
+ List<Object> elements = new ArrayList<Object>(origFqn.size() + 2);
elements.add(BUDDY_BACKUP_SUBTREE);
elements.add(buddyGroupName);
elements.addAll(origFqn.peekElements());
- return new Fqn(elements);
+ return new Fqn(elements, true);
}
/**
@@ -640,17 +640,15 @@
*/
public static Fqn getBackupFqn(Fqn buddyGroupRoot, Fqn origFqn)
{
- if (origFqn.isChildOf(buddyGroupRoot))
- {
- return origFqn;
- }
+ if (isBackupFqn(origFqn))
+ throw new CacheException("Cannot make a backup Fqn from a backup Fqn! Attempting to create a backup of " + origFqn);
- List<Object> elements = new ArrayList<Object>();
+ List<Object> elements = new ArrayList<Object>(origFqn.size() + 2);
elements.add(BUDDY_BACKUP_SUBTREE);
elements.add(buddyGroupRoot.get(1));
elements.addAll(origFqn.peekElements());
- return new Fqn(elements);
+ return new Fqn(elements, true);
}
public static boolean isBackupFqn(Fqn name)
@@ -683,7 +681,7 @@
public MethodCall transformFqns(MethodCall call, boolean transformForCurrentCall)
{
- if (call != null && call.getArgs() != null)
+ if (call != null && call.getArgs() != null && call.getMethodId() != MethodDeclarations.commitMethod_id)
{
MethodCall call2 = MethodCallFactory.create(call.getMethod(), call.getArgs().clone());
handleArgs(call2.getArgs(), transformForCurrentCall);
@@ -1009,13 +1007,7 @@
if (args[i] instanceof MethodCall)
{
MethodCall call = (MethodCall) args[i];
- boolean transformFqns = true;
- if (call.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
- {
- transformFqns = false;
- }
-
- args[i] = transformFqns((MethodCall) args[i], transformFqns);
+ args[i] = transformFqns((MethodCall) args[i], call.getMethodId() != MethodDeclarations.dataGravitationCleanupMethod_id);
}
if (args[i] instanceof List && args[i] != null)
@@ -1023,8 +1015,6 @@
Object[] asArray = ((List) args[i]).toArray();
handleArgs(asArray, transformForCurrentCall);
List<Object> newList = new ArrayList<Object>(asArray.length);
- // Oops! JDK 5.0!
- //Collections.addAll(newList, asArray);
newList.addAll(Arrays.asList(asArray));
args[i] = newList;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -47,18 +47,15 @@
public ActivationInterceptor()
{
- this.useCacheStore = false;
- isActivation = true;
+ initLogger();
}
@Override
protected Object handleRemoveDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps) throws Throwable
{
Object returnValue = super.handleRemoveDataMethod(ctx, tx, fqn, createUndoOps);
- if (log.isTraceEnabled())
- {
+ if (trace)
log.trace("This is a remove data operation; removing the data from the loader, no activation processing needed.");
- }
loader.removeData(fqn);
return returnValue;
}
@@ -67,10 +64,8 @@
protected Object handleRemoveNodeMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, boolean createUndoOps) throws Throwable
{
Object returnValue = super.handleRemoveNodeMethod(ctx, tx, fqn, createUndoOps);
- if (log.isTraceEnabled())
- {
+ if (trace)
log.trace("This is a remove operation; removing the node from the loader, no activation processing needed.");
- }
loader.remove(fqn);
return returnValue;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -70,24 +70,24 @@
}
}
- protected void replicateCall(MethodCall call, boolean sync, Option o) throws Throwable
+ protected void replicateCall(InvocationContext ctx, MethodCall call, boolean sync, Option o) throws Throwable
{
- replicateCall(null, call, sync, o);
+ replicateCall(ctx, null, call, sync, o);
}
- protected void replicateCall(List<Address> recipients, MethodCall call, boolean sync, Option o) throws Throwable
+ protected void replicateCall(InvocationContext ctx, List<Address> recipients, MethodCall call, boolean sync, Option o) throws Throwable
{
- replicateCall(recipients, call, sync, o, true);
+ replicateCall(ctx, recipients, call, sync, o, true);
}
- protected void replicateCall(List<Address> recipients, MethodCall call, boolean sync, Option o, boolean wrapMethodCallInReplicateMethod) throws Throwable
+ protected void replicateCall(InvocationContext ctx, List<Address> recipients, MethodCall call, boolean sync, Option o, boolean wrapMethodCallInReplicateMethod) throws Throwable
{
- if (log.isTraceEnabled()) log.trace("Broadcasting call " + call + " to recipient list " + recipients);
- Transaction tx = null;
- if (cache.getTransactionManager() != null && (tx = cache.getTransactionManager().getTransaction()) != null)
+ if (trace) log.trace("Broadcasting call " + call + " to recipient list " + recipients);
+ Transaction tx = ctx.getTransaction();
+ if (tx != null)
{
- GlobalTransaction gtx = cache.getTransactionTable().get(tx);
+ GlobalTransaction gtx = ctx.getGlobalTransaction();
TransactionEntry te = cache.getTransactionTable().get(gtx);
if (te != null)
{
@@ -107,7 +107,7 @@
if (callRecipients == null)
{
callRecipients = usingBuddyReplication ? buddyManager.getBuddyAddresses() : cache.getMembers();
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Setting call recipients to " + callRecipients + " since the original list of recipients passed in is null.");
}
@@ -121,10 +121,7 @@
sync, // is synchronised?
true, // ignore self?
(int) syncReplTimeout);
- if (log.isTraceEnabled())
- {
- log.trace("responses=" + rsps);
- }
+ if (trace) log.trace("responses=" + rsps);
if (sync) checkResponses(rsps);
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseTransactionalContextInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -44,8 +44,11 @@
protected void setTransactionalContext(Transaction tx, GlobalTransaction gtx, InvocationContext ctx)
{
- log.trace("Setting up transactional context.");
- if (log.isTraceEnabled()) log.trace("Setting tx as " + tx + " and gtx as " + gtx);
+ if (trace)
+ {
+ log.trace("Setting up transactional context.");
+ log.trace("Setting tx as " + tx + " and gtx as " + gtx);
+ }
ctx.setTransaction(tx);
ctx.setGlobalTransaction(gtx);
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -45,7 +44,7 @@
public CacheLoaderInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
/**
@@ -211,8 +210,7 @@
protected Object handleRollbackMethod(InvocationContext ctx, GlobalTransaction globalTransaction) throws Throwable
{
// clean up nodesCreated map
- boolean traceEnabled = log.isTraceEnabled();
- log.trace("Removing temporarily created nodes from treecache");
+ if (trace) log.trace("Removing temporarily created nodes from treecache");
// this needs to be done in reverse order.
List list = getTransactionEntry(ctx).getDummyNodesCreatedByCacheLoader();
@@ -228,7 +226,7 @@
}
catch (CacheException e)
{
- if (traceEnabled) log.trace("Unable to evict node " + fqn, e);
+ if (trace) log.trace("Unable to evict node " + fqn, e);
}
}
}
@@ -270,7 +268,7 @@
NodeSPI n = cache.peek(fqn, true, true);
boolean mustLoad = mustLoad(n, key, allKeys);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("load element " + fqn + " mustLoad=" + mustLoad);
}
@@ -333,12 +331,12 @@
if (node != null && node.isChildrenLoaded())
{
- log.trace("Children already loaded!");
+ if (trace) log.trace("Children already loaded!");
return;
}
Set children_names = loader.getChildrenNames(fqn);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("load children " + fqn + " children=" + children_names);
}
@@ -396,7 +394,7 @@
{
if (n == null)
{
- log.trace("must load, node null");
+ if (trace) log.trace("must load, node null");
return true;
}
@@ -404,7 +402,7 @@
if (!n.isValid() && cache.getConfiguration().isNodeLockingOptimistic())
{
// attempt to load again; this only happens if we have tombstones lying around, or we are using invalidation.
- log.trace("loading again from cache loader since in-memory node is marked as invalid");
+ if (trace) log.trace("loading again from cache loader since in-memory node is marked as invalid");
return true;
}
@@ -414,18 +412,18 @@
// if we are not looking for a specific key don't bother loading!
if (key == null)
{
- log.trace("don't load, key requested is null");
+ if (trace) log.trace("don't load, key requested is null");
return false;
}
if (n.getKeysDirect().contains(key))
{
- log.trace("don't load, already have necessary key in memory");
+ if (trace) log.trace("don't load, already have necessary key in memory");
return false;
}
}
if (!n.isDataLoaded())
{
- log.trace("must Load, uninitialized");
+ if (trace) log.trace("must Load, uninitialized");
return true;
}
return false;
@@ -520,11 +518,11 @@
*/
private NodeSPI loadNode(InvocationContext ctx, Fqn fqn, NodeSPI n, TransactionEntry entry) throws Exception
{
- if (log.isTraceEnabled()) log.trace("loadNode " + fqn);
+ if (trace) log.trace("loadNode " + fqn);
Map nodeData = loadData(fqn);
if (nodeData != null)
{
- log.trace("Node data is not null, loading");
+ if (trace) log.trace("Node data is not null, loading");
cache.getNotifier().notifyNodeLoaded(fqn, true, Collections.emptyMap(), ctx);
if (isActivation)
@@ -548,7 +546,7 @@
if (n != null && !n.isDataLoaded())
{
- log.trace("Setting dataLoaded to true");
+ if (trace) log.trace("Setting dataLoaded to true");
n.setDataLoaded(true);
}
return n;
@@ -561,7 +559,7 @@
{
NodeSPI n = createNodes(fqn, entry);
n.setDataLoaded(false);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("createTempNode n " + n);
}
@@ -623,7 +621,7 @@
Map nodeData = loader.get(fqn);
boolean nodeExists = (nodeData != null);
- if (log.isTraceEnabled()) log.trace("nodeExists " + nodeExists);
+ if (trace) log.trace("nodeExists " + nodeExists);
if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -21,7 +21,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.optimistic.DataVersion;
@@ -50,7 +49,7 @@
public CacheMgmtInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -48,7 +47,7 @@
public CacheStoreInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Start
@@ -68,7 +67,7 @@
{
if (!ctx.isOriginLocal() && loaderConfig.isShared())
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Passing up method call and bypassing this interceptor since the cache loader is shared and this call originated remotely.");
}
@@ -82,11 +81,11 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader yet.");
if (ctx.isTxHasMods())
{
// this is a commit call.
- if (log.isTraceEnabled()) log.trace("Calling loader.commit() for gtx " + gtx);
+ if (trace) log.trace("Calling loader.commit() for gtx " + gtx);
// sync call (a write) on the loader
// ignore modified FQNs
// List fqnsModified = getFqnsFromModificationList(tx_table.get(gtx).getCacheLoaderModifications());
@@ -119,7 +118,7 @@
}
else
{
- log.trace("Commit called with no modifications; ignoring.");
+ if (trace) log.trace("Commit called with no modifications; ignoring.");
}
}
return nextInterceptor(ctx);
@@ -130,7 +129,7 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader yet.");
if (ctx.isTxHasMods())
{
// this is a rollback method
@@ -146,7 +145,7 @@
}
else
{
- log.trace("Rollback called with no modifications; ignoring.");
+ if (trace) log.trace("Rollback called with no modifications; ignoring.");
}
}
return nextInterceptor(ctx);
@@ -157,7 +156,7 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader yet.");
prepareCacheLoader(gtx, ctx.getMethodCall().isOnePhaseCommitPrepareMehod());
}
return nextInterceptor(ctx);
@@ -168,7 +167,7 @@
{
if (inTransaction())
{
- log.trace("transactional so don't put stuff in the cloader yet.");
+ if (trace) log.trace("transactional so don't put stuff in the cloader yet.");
prepareCacheLoader(gtx, ctx.getMethodCall().isOnePhaseCommitPrepareMehod());
}
return nextInterceptor(ctx);
@@ -368,10 +367,10 @@
modifications = entry.getCacheLoaderModifications();
if (modifications.size() == 0)
{
- log.trace("Transaction has not logged any modifications!");
+ if (trace) log.trace("Transaction has not logged any modifications!");
return;
}
- if (log.isTraceEnabled()) log.trace("Cache loader modification list: " + modifications);
+ if (trace) log.trace("Cache loader modification list: " + modifications);
List cache_loader_modifications = new ArrayList();
for (MethodCall methodCall : modifications)
{
@@ -388,7 +387,7 @@
}
}
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Converted method calls to cache loader modifications. List size: " + cache_loader_modifications.size());
}
@@ -410,7 +409,7 @@
*/
private Modification convertMethodCallToModification(MethodCall methodCall, Set<Fqn> affectedFqns) throws Exception
{
- if (log.isTraceEnabled()) log.trace("Converting method call " + methodCall + " to modification.");
+ if (trace) log.trace("Converting method call " + methodCall + " to modification.");
Method method = methodCall.getMethod();
Object[] args;
if (method == null)
@@ -457,7 +456,7 @@
throw new CacheException("method call " + method.getName() + " cannot be converted to a modification");
}
affectedFqns.add(fqn);
- if (log.isTraceEnabled()) log.trace("Converted " + methodCall + " to Modification of type " + mod.getType());
+ if (trace) log.trace("Converted " + methodCall + " to Modification of type " + mod.getType());
return mod;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -28,6 +28,11 @@
private CacheImpl cacheImpl;
private CacheSPI remoteDelegate;
+ public CallInterceptor()
+ {
+ initLogger();
+ }
+
@Inject
private void injectDependencies(CacheImpl cacheImpl, @ComponentName("remoteDelegate")CacheSPI remoteDelegate)
{
@@ -42,7 +47,7 @@
if (!MethodDeclarations.isTransactionLifecycleMethod(m.getMethodId()))
{
- if (log.isTraceEnabled()) log.trace("Passing up method " + m + " so it gets invoked on cache.");
+ if (trace) log.trace("Passing up method " + m + " so it gets invoked on cache.");
try
{
retval = m.invoke(m.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id ? remoteDelegate : cacheImpl);
@@ -54,7 +59,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("Suppressing invocation of method " + m + " on cache.");
+ if (trace) log.trace("Suppressing invocation of method " + m + " on cache.");
}
Transaction tx = ctx.getTransaction();
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/DataGravitatorInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
@@ -61,7 +60,7 @@
public DataGravitatorInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -166,7 +165,7 @@
if (isGravitationEnabled(ctx))
{
// test that the Fqn being requested exists locally in the cache.
- if (log.isTraceEnabled()) log.trace("Checking local existence of fqn " + fqn);
+ if (trace) log.trace("Checking local existence of fqn " + fqn);
if (BuddyManager.isBackupFqn(fqn))
{
log.info("Is call for a backup Fqn, not performing any gravitation. Direct calls on internal backup nodes are *not* supported.");
@@ -175,12 +174,12 @@
{
if (cache.peek(fqn, false) == null)
{
- log.trace("Gravitating from local backup tree");
+ if (trace) log.trace("Gravitating from local backup tree");
BackupData data = localBackupGet(fqn, ctx);
if (data == null)
{
- log.trace("Gravitating from remote backup tree");
+ if (trace) log.trace("Gravitating from remote backup tree");
// gravitate remotely.
data = remoteBackupGet(fqn);
}
@@ -191,7 +190,8 @@
// when I do the put() call to the cluster!
//createNode(data.backupData, true);
// Make sure I replicate to my buddies.
- log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
+ if (trace)
+ log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
createNode(data.backupData, false);
// very strange, the invocation contexts get twisted up here, and will need preservation.
@@ -204,13 +204,13 @@
}
else
{
- log.trace("No need to gravitate; have this already.");
+ if (trace) log.trace("No need to gravitate; have this already.");
}
}
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Suppressing data gravitation for this call.");
}
@@ -234,7 +234,7 @@
private void doPrepare(GlobalTransaction gtx, InvocationContext ctx) throws Throwable
{
MethodCall cleanup = transactionMods.get(gtx);
- if (log.isTraceEnabled()) log.trace("Broadcasting prepare for cleanup ops " + cleanup);
+ if (trace) log.trace("Broadcasting prepare for cleanup ops " + cleanup);
if (cleanup != null)
{
MethodCall prepare;
@@ -249,11 +249,11 @@
prepare = MethodCallFactory.create(MethodDeclarations.prepareMethod, gtx, mods, cache.getLocalAddress(), syncCommunications);
}
- replicateCall(getMembersOutsideBuddyGroup(), prepare, syncCommunications, ctx.getOptionOverrides());
+ replicateCall(ctx, getMembersOutsideBuddyGroup(), prepare, syncCommunications, ctx.getOptionOverrides());
}
else
{
- if (log.isTraceEnabled()) log.trace("Nothing to broadcast in prepare phase for gtx " + gtx);
+ if (trace) log.trace("Nothing to broadcast in prepare phase for gtx " + gtx);
}
}
@@ -261,12 +261,12 @@
{
if (transactionMods.containsKey(gtx))
{
- if (log.isTraceEnabled()) log.trace("Broadcasting commit for gtx " + gtx);
- replicateCall(getMembersOutsideBuddyGroup(), MethodCallFactory.create(MethodDeclarations.commitMethod, gtx), syncCommunications, ctx.getOptionOverrides());
+ if (trace) log.trace("Broadcasting commit for gtx " + gtx);
+ replicateCall(ctx, getMembersOutsideBuddyGroup(), MethodCallFactory.create(MethodDeclarations.commitMethod, gtx), syncCommunications, ctx.getOptionOverrides());
}
else
{
- if (log.isTraceEnabled()) log.trace("Nothing to broadcast in commit phase for gtx " + gtx);
+ if (trace) log.trace("Nothing to broadcast in commit phase for gtx " + gtx);
}
}
@@ -287,7 +287,7 @@
if (gr.isDataFound())
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Got response " + gr);
}
@@ -303,18 +303,18 @@
MethodCall cleanup = MethodCallFactory.create(MethodDeclarations.dataGravitationCleanupMethod, backup.primaryFqn, backup.backupFqn);
- if (log.isTraceEnabled()) log.trace("Performing cleanup on [" + backup.primaryFqn + "]");
+ if (trace) log.trace("Performing cleanup on [" + backup.primaryFqn + "]");
if (gtx == null)
{
// broadcast removes
// remove main Fqn
- if (log.isTraceEnabled()) log.trace("Performing cleanup on [" + backup.backupFqn + "]");
+ if (trace) log.trace("Performing cleanup on [" + backup.backupFqn + "]");
// remove backup Fqn
- replicateCall(cache.getMembers(), cleanup, syncCommunications, ctx.getOptionOverrides(), false);
+ replicateCall(ctx, cache.getMembers(), cleanup, syncCommunications, ctx.getOptionOverrides(), false);
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Data gravitation performed under global transaction " + gtx + ". Not broadcasting cleanups until the tx commits. Adding to tx mod list instead.");
}
@@ -326,7 +326,7 @@
private GravitateResult gravitateData(Fqn fqn) throws Exception
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("cache=" + cache.getLocalAddress() + "; requesting data gravitation for Fqn " + fqn);
}
@@ -336,7 +336,7 @@
// doing a GET_ALL is crappy but necessary since JGroups' GET_FIRST could return null results from nodes that do
// not have either the primary OR backup, and stop polling other valid nodes.
List resps = cache.getRPCManager().callRemoteMethods(mbrs, dGrav, GroupRequest.GET_ALL, true, buddyManager.getBuddyCommunicationTimeout(), new ResponseValidityFilter(mbrs, cache.getLocalAddress()));
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("got responses " + resps);
}
@@ -409,7 +409,7 @@
NodeSPI child_node = n.addChildDirect(new Fqn<Object>(child_name));
if (child_node == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("failed to find or create child " + child_name + " of node " + n.getFqn());
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -7,7 +7,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
@@ -42,13 +41,13 @@
@Inject
void setRegionManager(RegionManager regionManager)
{
- log.trace("Having region manager " + regionManager + " injected.");
+ if (trace) log.trace("Having region manager " + regionManager + " injected.");
this.regionManager = regionManager;
}
public EvictionInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -100,7 +99,7 @@
{
if (newData == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Putting null data under fqn " + fqn + ".");
}
@@ -128,7 +127,7 @@
{
if (data == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Putting null data under fqn " + fqn + ".");
}
@@ -153,7 +152,7 @@
Object retVal = nextInterceptor(ctx);
if (retVal == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("No event added. Element does not exist");
}
@@ -175,7 +174,7 @@
Object retVal = nextInterceptor(ctx);
if (retVal == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("No event added. Node does not exist");
}
@@ -202,7 +201,7 @@
Object retVal = nextInterceptor(ctx);
if (retVal == null)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("No event added. Element does not exist");
}
@@ -249,12 +248,12 @@
Region region = regionManager.getRegion(event.getFqn(), false);
region.putNodeEvent(event);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Adding event " + event + " to region at " + region.getFqn());
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Finished updating node");
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -49,10 +49,17 @@
protected Log log = null;
protected Configuration configuration;
private boolean statsEnabled = false;
+ protected boolean trace;
public Interceptor()
{
+ initLogger();
+ }
+
+ protected void initLogger()
+ {
log = LogFactory.getLog(getClass());
+ trace = log.isTraceEnabled();
}
public void setNext(Interceptor i)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -56,7 +55,7 @@
public InvalidationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
public void setCache(CacheSPI cache)
@@ -81,7 +80,7 @@
// skip replication!!
return true;
}
- if (log.isTraceEnabled()) log.trace("(" + cache.getLocalAddress() + ") method call " + ctx.getMethodCall());
+ if (trace) log.trace("(" + cache.getLocalAddress() + ") method call " + ctx.getMethodCall());
return false;
}
@@ -338,7 +337,7 @@
if (log.isDebugEnabled()) log.debug("Cache [" + cache.getLocalAddress() + "] replicating " + call);
// voila, invalidated!
- replicateCall(call, synchronous, ctx.getOptionOverrides());
+ replicateCall(ctx, call, synchronous, ctx.getOptionOverrides());
}
protected DataVersion getNodeVersion(TransactionWorkspace w, Fqn f)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Option;
import org.jboss.cache.marshall.MethodCall;
@@ -25,7 +24,7 @@
{
public InvocationContextInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -37,9 +36,11 @@
Transaction suspendedTransaction = null;
boolean resumeSuspended = false;
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Invoked on cache instance [" + cache.getLocalAddress() + "] and InvocationContext [" + ctx + "]");
+ if (MethodDeclarations.isBlockUnblockMethod(call.getMethodId())) return nextInterceptor(ctx);
+
try
{
Transaction tx = getTransaction();
@@ -56,12 +57,12 @@
{
suspendedTransaction = txManager.suspend();
setTransactionalContext(null, null, ctx);
- if (log.isTraceEnabled()) log.trace("Suspending transaction " + suspendedTransaction);
+ if (trace) log.trace("Suspending transaction " + suspendedTransaction);
resumeSuspended = true;
}
else
{
- log.trace("No ongoing transaction to suspend");
+ if (trace) log.trace("No ongoing transaction to suspend");
}
}
}
@@ -92,7 +93,7 @@
finally
{
// clean up any invocation-scope options set up
- log.trace("Resetting invocation-scope options");
+ if (trace) log.trace("Resetting invocation-scope options");
ctx.getOptionOverrides().reset();
if (resumeSuspended)
@@ -111,16 +112,9 @@
private GlobalTransaction getGlobalTransaction(Transaction tx, MethodCall call)
{
- GlobalTransaction gtx = null;
- if (MethodDeclarations.isTransactionLifecycleMethod(call.getMethodId()))
- {
- gtx = findGlobalTransaction(call.getArgs());
- gtx.setRemote(isRemoteGlobalTx(gtx));
- }
- else
- {
- gtx = cache.getCurrentTransaction(tx, false);
- }
+ GlobalTransaction gtx = findGlobalTransaction(call.getArgs());
+ if (gtx == null) gtx = cache.getCurrentTransaction(tx, false);
+ if (gtx != null) gtx.setRemote(isRemoteGlobalTx(gtx));
return gtx;
}
@@ -130,7 +124,7 @@
// this creates a context if one did not exist.
if (txManager == null)
{
- log.trace("no transaction manager configured, setting tx as null.");
+ if (trace) log.trace("no transaction manager configured, setting tx as null.");
return null;
}
else
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -10,10 +10,8 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jgroups.Address;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
/**
* The purpose of this interceptor is to supply a nicer way of handling the interception of desired methods:
@@ -36,32 +34,37 @@
public abstract class MethodDispacherInterceptor extends Interceptor
{
/**
- * List of the method the extending interceptor pverwrites. It is only those methods that will be called.
+ * Methods that have been overridden. This is encoded in the bits of an integer, with each ordinal position representing a method id.
+ * This was originally a Set but that proved way too inefficient with constant boxing/unboxing of ints and doing Set.contains()
+ * for each invocation for each interceptor. - Manik, Jan '08.
*/
- private Set<Integer> overriddenMethods = new HashSet<Integer>();
+ private long overriddenMethods = 0;
protected MethodDispacherInterceptor()
{
findOverriddenMethods();
}
+ private boolean noHandlersRegistered(int id)
+ {
+ return (overriddenMethods & ((long) 1 << id)) < 1;
+ }
+
/**
* Acts like a 'switch case' that delegates the call to the appropriate method.
*/
public Object invoke(InvocationContext ctx) throws Throwable
{
- if (log.isTraceEnabled())
- {
- log.trace("Invoked with method call " + ctx.getMethodCall());
- }
+ if (trace) log.trace("Invoked with method call " + ctx.getMethodCall());
+
if (skipMethodCall(ctx))
{
return nextInterceptor(ctx);
}
MethodCall m = ctx.getMethodCall();
- if (!overriddenMethods.contains(m.getMethodId()))
+ if (noHandlersRegistered(m.getMethodId()))
{
- log.trace("Not registered for any handlers, passing up the chain.");
+ if (trace) log.trace("Not registered for any handlers, passing up the chain.");
return nextInterceptor(ctx);
}
Object[] args = m.getArgs();
@@ -468,7 +471,7 @@
*/
private Object defaultHandlersBehavior()
{
- throw new IllegalStateException("this is either called from a derived class or nt overwritten and accidentally called. Either way, is not correct.");
+ throw new IllegalStateException("this is either called from a derived class or not overridden and accidentally called. Either way, is not correct.");
}
/**
@@ -510,7 +513,6 @@
checkIfOverridden(MethodDeclarations.blockChannelMethodLocal_id, "handleBlockChannelMethod", InvocationContext.class);
checkIfOverridden(MethodDeclarations.unblockChannelMethodLocal_id, "handleUnblockChannelMethod", InvocationContext.class);
checkIfOverridden(MethodDeclarations.lockMethodLocal_id, "handleLockMethod", InvocationContext.class, Fqn.class, NodeLock.LockType.class, boolean.class);
-
}
private void checkIfOverridden(int methodId, String methodName, Class... args)
@@ -522,7 +524,7 @@
try
{
currentClass.getDeclaredMethod(methodName, args);
- this.overriddenMethods.add(methodId);
+ overriddenMethods |= ((long) 1 << methodId);
}
catch (NoSuchMethodException e)
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/NotificationInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -14,7 +13,7 @@
{
public NotificationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -40,6 +40,11 @@
*/
private NodeFactory nodeFactory;
+ public OptimisticCreateIfNotExistsInterceptor()
+ {
+ initLogger();
+ }
+
@Inject
private void injectDependencies(NodeFactory nodeFactory)
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -29,15 +29,12 @@
{
protected TransactionManager txManager = null;
protected TransactionTable txTable = null;
- protected boolean trace;
@Inject
private void injectDependencies(TransactionManager txManager, TransactionTable txTable)
{
this.txManager = txManager;
this.txTable = txTable;
- trace = log != null && log.isTraceEnabled();
-
}
protected TransactionWorkspace getTransactionWorkspace(GlobalTransaction gtx) throws CacheException
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticLockingInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -41,6 +41,11 @@
lockAcquisitionTimeout = cache.getConfiguration().getLockAcquisitionTimeout();
}
+ public OptimisticLockingInterceptor()
+ {
+ initLogger();
+ }
+
@Override
protected Object handleOptimisticPrepareMethod(InvocationContext ctx, GlobalTransaction gtx, List modifications, Map data, Address address, boolean onePhaseCommit) throws Throwable
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -51,6 +51,11 @@
this.nodeFactory = nodeFactory;
}
+ public OptimisticNodeInterceptor()
+ {
+ initLogger();
+ }
+
@Override
public Object invoke(InvocationContext ctx) throws Throwable
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -49,7 +48,7 @@
public OptimisticReplicationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Override
@@ -189,7 +188,7 @@
+ " (" + num_mods + " modifications");
}
- replicateCall(toBroadcast, remoteCallSync, ctx.getOptionOverrides());
+ replicateCall(ctx, toBroadcast, remoteCallSync, ctx.getOptionOverrides());
}
else
{
@@ -218,7 +217,7 @@
if (log.isDebugEnabled())
log.debug("running remote commit for " + gtx + " and coord=" + cache.getLocalAddress());
- replicateCall(commit_method, remoteCallSync, ctx.getOptionOverrides());
+ replicateCall(ctx, commit_method, remoteCallSync, ctx.getOptionOverrides());
}
catch (Exception e)
{
@@ -242,7 +241,7 @@
if (log.isDebugEnabled())
log.debug("running remote rollback for " + gtx + " and coord=" + cache.getLocalAddress());
- replicateCall(rollback_method, remoteCallSync, ctx.getOptionOverrides());
+ replicateCall(ctx, rollback_method, remoteCallSync, ctx.getOptionOverrides());
}
catch (Exception e)
{
@@ -306,13 +305,13 @@
WorkspaceNode n = w.getNode(f);
if (n == null)
{
- if (log.isTraceEnabled()) log.trace("Fqn " + f + " not found in workspace; not using a data version.");
+ if (trace) log.trace("Fqn " + f + " not found in workspace; not using a data version.");
return null;
}
if (n.isVersioningImplicit())
{
DefaultDataVersion v = (DefaultDataVersion) n.getVersion();
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Fqn " + f + " has implicit versioning. Broadcasting an incremented version.");
// potential bug here - need to check if we *need* to increment at all, because of Configuration.isLockParentForChildInsertRemove()
@@ -320,7 +319,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("Fqn " + f + " has explicit versioning. Broadcasting the version as-is.");
+ if (trace) log.trace("Fqn " + f + " has explicit versioning. Broadcasting the version as-is.");
return n.getVersion();
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -47,6 +47,11 @@
{
private boolean useTombstones;
+ public OptimisticValidatorInterceptor()
+ {
+ initLogger();
+ }
+
@Override
public void setCache(CacheSPI cache)
{
@@ -189,7 +194,7 @@
boolean updateVersion = false;
if (workspaceNode.isChildrenModified())
{
- log.trace("Updating children since node has modified children");
+ if (trace) log.trace("Updating children since node has modified children");
// merge children.
List<Set<Fqn>> deltas = workspaceNode.getMergedChildren();
@@ -220,7 +225,7 @@
if (workspaceNode.isModified())
{
- log.trace("Merging data since node is dirty");
+ if (trace) log.trace("Merging data since node is dirty");
Map mergedData = workspaceNode.getMergedData();
underlyingNode.clearDataDirect();
underlyingNode.putAllDirect(mergedData);
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -27,7 +26,7 @@
public PassivationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@@ -60,7 +59,7 @@
}
catch (NodeNotLoadedException e)
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Node " + fqn + " not loaded in memory; passivation skipped");
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -53,19 +52,23 @@
{
private TransactionTable tx_table;
private CacheImpl cacheImpl;
+ private NodeSPI rootNode;
+
/**
* Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks held by that thread
*/
private Map<Thread, List<NodeLock>> lockTable;
+ // private ThreadLocal<List<NodeLock>> lockTable;
private long lock_acquisition_timeout;
public PessimisticLockInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@Inject
public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
+// public void injectDependencies(@ComponentName("LockTable")ThreadLocal<List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
{
this.lockTable = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
@@ -73,6 +76,13 @@
this.tx_table = txTable;
}
+ @Override
+ public Object invoke(InvocationContext ctx) throws Throwable
+ {
+ if (rootNode == null) rootNode = cache.getRoot();
+ return super.invoke(ctx);
+ }
+
protected Object handlePutDataMethod(InvocationContext ctx, GlobalTransaction tx, Fqn fqn, Map data, boolean createUndoOps) throws Throwable
{
return handlePutMethod(ctx, fqn);
@@ -93,10 +103,9 @@
{
if ((ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isSuppressLocking()) || configuration.getIsolationLevel() == IsolationLevel.NONE)
{
- log.trace("Suppressing locking");
- log.trace("Creating nodes if necessary");
+ if (trace) log.trace("Suppressing locking, creating nodes if necessary");
int treeNodeSize = fqn.size();
- NodeSPI n = cache.getRoot();
+ NodeSPI n = rootNode;
for (int i = 0; i < treeNodeSize; i++)
{
Object childName = fqn.get(i);
@@ -149,7 +158,7 @@
protected Object handleCommitMethod(InvocationContext ctx, GlobalTransaction globalTransaction) throws Throwable
{
commit(globalTransaction);
- log.trace("bypassed locking as method commit() doesn't require locking");
+ if (trace) log.trace("bypassed locking as method commit() doesn't require locking");
Object retVal = nextInterceptor(ctx);
tx_table.cleanup(globalTransaction);
return retVal;
@@ -158,7 +167,7 @@
protected Object handleRollbackMethod(InvocationContext ctx, GlobalTransaction globalTransaction) throws Throwable
{
TransactionEntry entry = tx_table.get(globalTransaction);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("called to rollback cache with GlobalTransaction=" + globalTransaction);
}
@@ -178,7 +187,7 @@
// 1. Revert the modifications by running the undo-op list in reverse. This *cannot* throw any exceptions !
entry.undoOperations(cache);
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("bypassed locking as method rollback() doesn't require locking");
}
@@ -191,7 +200,7 @@
{
long timeout = ctx.getContextLockAcquisitionTimeout(lock_acquisition_timeout);
// this call will ensure the node gets a WL and it's current parent gets RL.
- if (log.isTraceEnabled()) log.trace("Attempting to get WL on node to be moved [" + from + "]");
+ if (trace) log.trace("Attempting to get WL on node to be moved [" + from + "]");
if (from != null && !(configuration.getIsolationLevel() == IsolationLevel.NONE))
{
lock(ctx, from, NodeLock.LockType.WRITE, false, timeout, true, false);
@@ -204,7 +213,7 @@
if (to != null && !(configuration.getIsolationLevel() == IsolationLevel.NONE))
{
//now for an RL for the new parent.
- if (log.isTraceEnabled()) log.trace("Attempting to get RL on new parent [" + to + "]");
+ if (trace) log.trace("Attempting to get RL on new parent [" + to + "]");
lock(ctx, to, NodeLock.LockType.READ, false, timeout, false, false);
acquireLocksOnChildren(cache.peek(to, true), NodeLock.LockType.READ, ctx);
}
@@ -225,7 +234,7 @@
{
cache.getTransactionTable().get(ctx.getGlobalTransaction()).addRemovedNode(fqn);
}
- acquireLocksOnChildren(cache.getRoot().getChildDirect(fqn), NodeLock.LockType.WRITE, ctx);
+ acquireLocksOnChildren(rootNode.getChildDirect(fqn), NodeLock.LockType.WRITE, ctx);
Object retVal = nextInterceptor(ctx);
if (ctx.getGlobalTransaction() == null)
{
@@ -355,9 +364,9 @@
}
Object owner = (gtx != null) ? gtx : currentThread;
NodeSPI currentNode;
- if (log.isTraceEnabled()) log.trace("Attempting to lock node " + fqn + " for owner " + owner);
+ if (trace) log.trace("Attempting to lock node " + fqn + " for owner " + owner);
long expiryTime = System.currentTimeMillis() + timeout;
- currentNode = cache.getRoot();
+ currentNode = rootNode;
NodeSPI parent = null;
Object childName = null;
int currentIndex = -1;
@@ -369,11 +378,11 @@
{
currentNode = parent.addChildDirect(new Fqn(childName));
created = true;
- if (log.isTraceEnabled()) log.trace("Child node was null, so created child node " + childName);
+ if (trace) log.trace("Child node was null, so created child node " + childName);
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
log.trace("failed to find or create child " + childName + " of node " + currentNode);
return false;
}
@@ -394,7 +403,7 @@
NodeSPI repeek = cache.peek(currentNode.getFqn(), true, true);
if (currentNode != repeek)
{
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
// we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
// check if the parent exists!!
@@ -403,9 +412,9 @@
if (cache.peek(parent.getFqn(), true, true) == null)
{
// crap!
- if (log.isTraceEnabled())
+ if (trace)
log.trace("Parent has been deleted again. Go through the lock method all over again.");
- currentNode = cache.getRoot();
+ currentNode = rootNode;
parent = null;
}
else
@@ -472,7 +481,7 @@
int treeNodeSize = targetFqn.size();
// write lock forced!!
boolean isTargetNode = currentNodeIndex == (treeNodeSize - 1);
- if (ctx.getOptionOverrides().isForceWriteLock() && isTargetNode) return true;
+ if (isTargetNode && ctx.getOptionOverrides().isForceWriteLock()) return true;
//this can be injected, from the caller as a param named wlParent
if (currentNode.isLockForChildInsertRemove())
{
@@ -480,7 +489,8 @@
{
return true;// we're doing a remove and we've reached the PARENT node of the target to be removed.
}
- if (!isTargetNode && cache.peek(new Fqn(currentNode.getFqn(), targetFqn.get(currentNodeIndex + 1)), false) == null)
+ if (!isTargetNode && cache.peek(targetFqn.getAncestor(currentNodeIndex + 2), false) == null)
+ //if (!isTargetNode && cache.peek(new Fqn(currentNode.getFqn(), targetFqn.get(currentNodeIndex + 1)), false) == null)
{
return createIfNotExists;// we're at a node in the tree, not yet at the target node, and we need to create the next node. So we need a WL here.
}
@@ -490,11 +500,11 @@
private void acquireNodeLock(NodeSPI node, Object owner, GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException
{
- boolean acquired = node.getLock().acquire(owner, lockTimeout, lockType);
+ NodeLock lock = node.getLock();
+ boolean acquired = lock.acquire(owner, lockTimeout, lockType);
if (acquired)
{
// Record the lock for release on method return or tx commit/rollback
- NodeLock lock = node.getLock();
if (gtx != null)
{
cache.getTransactionTable().recordNodeLock(gtx, lock);
@@ -520,6 +530,7 @@
if (locks == null)
{
locks = Collections.synchronizedList(new LinkedList<NodeLock>());
+// lockTable.set(locks);
lockTable.put(currentThread, locks);
}
return locks;
@@ -544,7 +555,7 @@
*/
private void commit(GlobalTransaction gtx)
{
- if (log.isTraceEnabled()) log.trace("committing cache with gtx " + gtx);
+ if (trace) log.trace("committing cache with gtx " + gtx);
TransactionEntry entry = tx_table.get(gtx);
if (entry == null)
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ReplicationInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,6 +1,5 @@
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Configuration;
@@ -26,7 +25,7 @@
{
public ReplicationInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
protected boolean skipMethodCall(InvocationContext ctx)
@@ -34,7 +33,7 @@
Option optionOverride = ctx.getOptionOverrides();
if (optionOverride != null && optionOverride.isCacheModeLocal() && ctx.getTransaction() == null)
{
- log.trace("skip replication");
+ if (trace) log.trace("skip replication");
return true;
}
return false;
@@ -46,7 +45,7 @@
{
return nextInterceptor(ctx);
}
- replicateCall(ctx.getMethodCall(), configuration.isSyncCommitPhase(), ctx.getOptionOverrides());
+ replicateCall(ctx, ctx.getMethodCall(), configuration.isSyncCommitPhase(), ctx.getOptionOverrides());
return nextInterceptor(ctx);
}
@@ -69,7 +68,7 @@
}
if (!ctx.isLocalRollbackOnly())
{
- replicateCall(ctx.getMethodCall(), configuration.isSyncRollbackPhase(), ctx.getOptionOverrides());
+ replicateCall(ctx, ctx.getMethodCall(), configuration.isSyncRollbackPhase(), ctx.getOptionOverrides());
}
return nextInterceptor(ctx);
@@ -101,7 +100,7 @@
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
boolean isInitiatedHere = gtx != null && !gtx.isRemote();
- if (log.isTraceEnabled()) log.trace("isInitiatedHere? " + isInitiatedHere + "; gtx = " + gtx);
+ if (trace) log.trace("isInitiatedHere? " + isInitiatedHere + "; gtx = " + gtx);
return !isTransactionalAndLocal(ctx) || !containsModifications(ctx);
}
@@ -202,7 +201,7 @@
if (ctx.getTransaction() == null && ctx.isOriginLocal())
{
MethodCall m = ctx.getMethodCall();
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("invoking method " + m + ", members=" + cache.getMembers() + ", mode=" +
configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" +
@@ -211,13 +210,13 @@
if (!isSynchronous(ctx.getOptionOverrides()) || m.getMethodId() == MethodDeclarations.putForExternalReadMethodLocal_id)
{
// 2. Replicate change to all *other* members (exclude self !)
- replicateCall(m, false, ctx.getOptionOverrides());
+ replicateCall(ctx, m, false, ctx.getOptionOverrides());
}
else
{
// REVISIT Needs to exclude itself and apply the local change manually.
// This is needed such that transient field is modified properly in-VM.
- replicateCall(m, true, ctx.getOptionOverrides());
+ replicateCall(ctx, m, true, ctx.getOptionOverrides());
}
}
return returnValue;
@@ -240,12 +239,12 @@
protected void runPreparePhase(MethodCall prepareMethod, GlobalTransaction gtx, InvocationContext ctx) throws Throwable
{
boolean async = configuration.getCacheMode() == Configuration.CacheMode.REPL_ASYNC;
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("(" + cache.getLocalAddress() + "): running remote prepare for global tx " + gtx + " with async mode=" + async);
}
// this method will return immediately if we're the only member (because exclude_self=true)
- replicateCall(prepareMethod, !async, ctx.getOptionOverrides());
+ replicateCall(ctx, prepareMethod, !async, ctx.getOptionOverrides());
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -6,7 +6,6 @@
*/
package org.jboss.cache.interceptors;
-import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -58,7 +57,7 @@
public TxInterceptor()
{
- log = LogFactory.getLog(getClass());
+ initLogger();
}
@SuppressWarnings("unchecked")
@@ -82,7 +81,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("received my own message (discarding it)");
+ if (trace) log.trace("received my own message (discarding it)");
result = null;
}
}
@@ -109,7 +108,7 @@
boolean scrubTxsOnExit = false;
try
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("(" + cache.getLocalAddress() + ") call on method [" + ctx.getMethodCall() + "]");
}
@@ -120,7 +119,7 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("received my own message (discarding it)");
+ if (trace) log.trace("received my own message (discarding it)");
result = null;
}
}
@@ -287,7 +286,8 @@
boolean shouldRethtrow = optionOverride == null || !optionOverride.isFailSilently();
if (!shouldRethtrow)
{
- log.trace("There was a problem handling this request, but failSilently was set, so suppressing exception", e);
+ if (trace)
+ log.trace("There was a problem handling this request, but failSilently was set, so suppressing exception", e);
}
throw e;
}
@@ -372,7 +372,7 @@
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Resuming existing transaction " + ltx + ", global TX=" + gtx);
}
@@ -391,7 +391,7 @@
entry.setTransaction(ltx);
log.debug("creating new tx entry");
txTable.put(gtx, entry);
- if (log.isTraceEnabled()) log.trace("TxTable contents: " + txTable);
+ if (trace) log.trace("TxTable contents: " + txTable);
}
setTransactionalContext(ltx, gtx, ctx);
@@ -513,7 +513,7 @@
{
log.debug(" local transaction exists - registering global tx if not present for " + Thread.currentThread());
}
- if (log.isTraceEnabled())
+ if (trace)
{
GlobalTransaction tempGtx = txTable.get(tx);
log.trace("Associated gtx in txTable is " + tempGtx);
@@ -575,7 +575,8 @@
replayModifications(modifications, ctx, false);
if (m.isOnePhaseCommitPrepareMehod())
{
- log.trace("Using one-phase prepare. Not propagating the prepare call up the stack until called to do so by the sync handler.");
+ if (trace)
+ log.trace("Using one-phase prepare. Not propagating the prepare call up the stack until called to do so by the sync handler.");
}
else
{
@@ -604,7 +605,7 @@
finally
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Are we running a 1-phase commit? " + commit);
}
@@ -788,7 +789,7 @@
//resume the old transaction if we suspended it
if (resumeCurrentTxOnCompletion)
{
- if (log.isTraceEnabled()) log.trace("Resuming suspended transaction " + currentTx);
+ if (trace) log.trace("Resuming suspended transaction " + currentTx);
txManager.suspend();
if (currentTx != null)
{
@@ -887,7 +888,7 @@
commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx);
}
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(" running commit for " + gtx);
}
@@ -942,7 +943,7 @@
// JBCACHE-457
// MethodCall rollbackMethod = MethodCall(CacheImpl.rollbackMethod, new Object[]{gtx, hasMods ? true : false});
MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, gtx);
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace(" running rollback for " + gtx);
}
@@ -993,7 +994,7 @@
else
{
// this is a REPL_ASYNC call - do 1-phase commit. break!
- log.trace("This is a REPL_ASYNC call (1 phase commit) - do nothing for beforeCompletion()");
+ if (trace) log.trace("This is a REPL_ASYNC call (1 phase commit) - do nothing for beforeCompletion()");
return null;
}
@@ -1040,14 +1041,14 @@
if (gtx.isRemote())
{
// should be no need to register a handler since this a remotely initiated gtx
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("is a remotely initiated gtx so no need to register a tx for it");
}
}
else
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Registering sync handler for tx " + tx + ", gtx " + gtx);
}
@@ -1079,7 +1080,7 @@
{
OrderedSynchronizationHandler orderedHandler = OrderedSynchronizationHandler.getInstance(tx);
- if (log.isTraceEnabled()) log.trace("registering for TX completion: SynchronizationHandler(" + handler + ")");
+ if (trace) log.trace("registering for TX completion: SynchronizationHandler(" + handler + ")");
orderedHandler.registerAtHead(handler);// needs to be invoked first on TX commit
@@ -1117,7 +1118,7 @@
*/
private Transaction createLocalTx() throws Exception
{
- if (log.isTraceEnabled())
+ if (trace)
{
log.trace("Creating transaction for thread " + Thread.currentThread());
}
@@ -1141,7 +1142,7 @@
txTable.put(localTx, gtx);
// attach this to the context
ctx.setTransaction(localTx);
- if (log.isTraceEnabled()) log.trace("Created new tx for gtx " + gtx);
+ if (trace) log.trace("Created new tx for gtx " + gtx);
return localTx;
}
@@ -1169,7 +1170,7 @@
public void beforeCompletion()
{
- if (log.isTraceEnabled()) log.trace("Running beforeCompletion on gtx " + gtx);
+ if (trace) log.trace("Running beforeCompletion on gtx " + gtx);
entry = txTable.get(gtx);
if (entry == null)
{
@@ -1220,7 +1221,7 @@
}
- if (log.isTraceEnabled()) log.trace("calling aftercompletion for " + gtx);
+ if (trace) log.trace("calling aftercompletion for " + gtx);
// set any transaction wide options as current for this thread.
if (entry != null)
{
@@ -1334,7 +1335,7 @@
setTransactionalContext(tx, gtx, ctx);
if (modifications.size() == 0)
{
- if (log.isTraceEnabled()) log.trace("No modifications in this tx. Skipping beforeCompletion()");
+ if (trace) log.trace("No modifications in this tx. Skipping beforeCompletion()");
return;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -3,12 +3,10 @@
import org.jboss.cache.InvocationContext;
import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.lock.IdentityLock;
import org.jboss.cache.lock.NodeLock;
import javax.transaction.Transaction;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
/**
@@ -22,10 +20,16 @@
{
Map<Thread, List<NodeLock>> lockTable = null;
- boolean trace = log.isTraceEnabled();
+// ThreadLocal<List<NodeLock>> lockTable;
+ public UnlockInterceptor()
+ {
+ initLogger();
+ }
+
@Inject
private void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable)
+// private void injectDependencies(@ComponentName("LockTable")ThreadLocal<List<NodeLock>> lockTable)
{
this.lockTable = lockTable;
}
@@ -52,7 +56,7 @@
else
{ // no TX
Thread currentThread = Thread.currentThread();
- List locks = lockTable.get(currentThread);
+ List<NodeLock> locks = lockTable.get(currentThread);
if (trace) log.trace("Attempting to release locks on current thread. Lock table is " + lockTable);
if (locks != null && locks.size() > 0)
@@ -65,15 +69,13 @@
}
}
- private void releaseLocks(List locks, Thread currentThread)
+ private void releaseLocks(List<NodeLock> locks, Thread currentThread)
{
- IdentityLock lock;
- for (ListIterator it = locks.listIterator(locks.size()); it.hasPrevious();)
+ NodeLock[] locksArray = locks.toArray(new NodeLock[]{});
+ for (int i = locksArray.length - 1; i > -1; i--)
{
- lock = (IdentityLock) it.previous();
- if (trace)
- log.trace("releasing lock for " + lock.getFqn() + ": " + lock);
- lock.release(currentThread);
+ if (trace) log.trace("releasing lock for " + locksArray[i].getFqn() + ": " + locksArray[i]);
+ locksArray[i].release(currentThread);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,5 +1,7 @@
package org.jboss.cache.lock;
+import org.jboss.cache.Fqn;
+
import java.util.Collection;
import java.util.Set;
@@ -9,12 +11,13 @@
*/
public interface NodeLock
{
-
public enum LockType
{
NONE, READ, WRITE
}
+ Fqn getFqn();
+
/**
* Returns a copy of the reader lock owner in List.
* Size is zero is not available. Note that this list
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -38,11 +38,6 @@
{
private static Log log = LogFactory.getLog(MethodDeclarations.class);
- static final Set<Integer> crudMethodIds = new HashSet<Integer>();
- static final Set<Integer> transactionLifecycleMethodIds = new HashSet<Integer>();
- static final Set<Integer> buddyGroupOrganisationMethodIds = new HashSet<Integer>();
- static final Set<Integer> blockUnblockMethodIds = new HashSet<Integer>();
- static final Set<Integer> putMethodIds = new HashSet<Integer>();
static final Set<Integer> methodsThatNeedToReturnValuesToRemoteCallers = new HashSet<Integer>();
// maintain a list of method IDs that correspond to Methods in CacheImpl
@@ -356,42 +351,9 @@
{
methodIds.put(methods.get(id), id);
}
-
- putMethodIds.add(putDataMethodLocal_id);
- putMethodIds.add(putDataEraseMethodLocal_id);
- putMethodIds.add(putKeyValMethodLocal_id);
- putMethodIds.add(putDataEraseVersionedMethodLocal_id);
- putMethodIds.add(putDataVersionedMethodLocal_id);
- putMethodIds.add(putKeyValVersionedMethodLocal_id);
- putMethodIds.add(putForExternalReadMethodLocal_id);
- putMethodIds.add(putForExternalReadVersionedMethodLocal_id);
-
- crudMethodIds.addAll(putMethodIds);
- crudMethodIds.add(removeNodeMethodLocal_id);
- crudMethodIds.add(removeKeyMethodLocal_id);
- crudMethodIds.add(removeDataMethodLocal_id);
- crudMethodIds.add(dataGravitationCleanupMethod_id);
- crudMethodIds.add(moveMethodLocal_id);
- crudMethodIds.add(removeNodeVersionedMethodLocal_id);
- crudMethodIds.add(removeKeyVersionedMethodLocal_id);
- crudMethodIds.add(removeDataVersionedMethodLocal_id);
-
-
- transactionLifecycleMethodIds.add(commitMethod_id);
- transactionLifecycleMethodIds.add(rollbackMethod_id);
- transactionLifecycleMethodIds.add(prepareMethod_id);
- transactionLifecycleMethodIds.add(optimisticPrepareMethod_id);
-
- buddyGroupOrganisationMethodIds.add(remoteAnnounceBuddyPoolNameMethod_id);
- buddyGroupOrganisationMethodIds.add(remoteAssignToBuddyGroupMethod_id);
- buddyGroupOrganisationMethodIds.add(remoteRemoveFromBuddyGroupMethod_id);
-
- blockUnblockMethodIds.add(blockChannelMethodLocal_id);
- blockUnblockMethodIds.add(unblockChannelMethodLocal_id);
-
}
- protected static int lookupMethodId(Method method)
+ public static int lookupMethodId(Method method)
{
Integer methodIdInteger = methodIds.get(method);
int methodId = -1;
@@ -411,7 +373,7 @@
return methodId;
}
- protected static Method lookupMethod(int id)
+ public static Method lookupMethod(int id)
{
Method method = methods.get(id);
if (method == null)
@@ -430,22 +392,39 @@
*/
public static boolean isCrudMethod(int id)
{
- return crudMethodIds.contains(Integer.valueOf(id));
+ return isPutMethod(id) ||
+ id == removeNodeMethodLocal_id ||
+ id == removeKeyMethodLocal_id ||
+ id == removeDataMethodLocal_id ||
+ id == dataGravitationCleanupMethod_id ||
+ id == moveMethodLocal_id ||
+ id == removeNodeVersionedMethodLocal_id ||
+ id == removeKeyVersionedMethodLocal_id ||
+ id == removeDataVersionedMethodLocal_id;
}
public static boolean isTransactionLifecycleMethod(int id)
{
- return transactionLifecycleMethodIds.contains(id);
+ // transactional lifecycle methods consist of just commit, rollback, prepare and optimistic prepare.
+ return id == commitMethod_id || id == optimisticPrepareMethod_id || id == prepareMethod_id || id == rollbackMethod_id;
}
public static boolean isBuddyGroupOrganisationMethod(int id)
{
- return buddyGroupOrganisationMethodIds.contains(id);
+ return id == remoteAssignToBuddyGroupMethod_id || id == remoteRemoveFromBuddyGroupMethod_id || id == remoteAnnounceBuddyPoolNameMethod_id;
}
public static boolean isPutMethod(int id)
{
- return putMethodIds.contains(id);
+ return
+ id == putDataMethodLocal_id ||
+ id == putDataEraseMethodLocal_id ||
+ id == putKeyValMethodLocal_id ||
+ id == putDataEraseVersionedMethodLocal_id ||
+ id == putDataVersionedMethodLocal_id ||
+ id == putKeyValVersionedMethodLocal_id ||
+ id == putForExternalReadMethodLocal_id ||
+ id == putForExternalReadVersionedMethodLocal_id;
}
public static boolean isGetMethod(int methodId)
@@ -456,7 +435,7 @@
public static boolean isBlockUnblockMethod(int id)
{
- return blockUnblockMethodIds.contains(id);
+ return id == blockChannelMethodLocal_id || id == unblockChannelMethodLocal_id;
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/FqnTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -21,6 +21,7 @@
* @author <a href="mailto:bela@jboss.org">Bela Ban</a> May 9, 2003
* @version $Revision$
*/
+@Test(groups = "functional")
public class FqnTest
{
private Cache<Object, Object> cache;
@@ -41,7 +42,6 @@
}
}
- @Test(groups = {"functional"})
public void testNull()
{
Fqn fqn = new Fqn();
@@ -51,7 +51,6 @@
assert hcode != -1;
}
- @Test(groups = {"functional"})
public void testOne()
{
Fqn<Integer> fqn = new Fqn<Integer>(22);
@@ -61,7 +60,6 @@
assert hcode != -1;
}
- @Test(groups = {"functional"})
public void testEmptyFqn()
{
Fqn f1 = new Fqn();
@@ -69,7 +67,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testFqn()
{
Fqn<String> fqn = Fqn.fromString("/a/b/c");
@@ -83,7 +80,6 @@
assert fqn.hashCode() == fqn2.hashCode();
}
- @Test(groups = {"functional"})
public void testHereogeneousNames()
{
Fqn<Object> fqn = new Fqn<Object>("string", 38, true);
@@ -95,7 +91,6 @@
assert fqn.hashCode() == fqn2.hashCode();
}
- @Test(groups = {"functional"})
public void testHashcode()
{
Fqn fqn1, fqn2;
@@ -111,7 +106,6 @@
assert map.get(fqn1).equals(34);
}
- @Test(groups = {"functional"})
public void testHashcode2()
{
Fqn<Integer> fqn = new Fqn<Integer>(-1);
@@ -121,7 +115,6 @@
assert hcode == -1;
}
- @Test(groups = {"functional"})
public void testEquals()
{
Fqn<String> fqn1 = new Fqn<String>("person/test");
@@ -145,7 +138,6 @@
}
- @Test(groups = {"functional"})
public void testEquals2()
{
Fqn<String> f1;
@@ -161,7 +153,6 @@
assert !f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals2WithMarshalling() throws Exception
{
Fqn<String> f1, f2;
@@ -170,7 +161,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals3()
{
Fqn<Object> f1;
@@ -190,7 +180,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals3WithMarshalling() throws Exception
{
Fqn<Object> f1, f2;
@@ -212,7 +201,6 @@
assert f1.equals(f2);
}
- @Test(groups = {"functional"})
public void testEquals4()
{
Fqn<String> fqn = Fqn.fromString("X");
@@ -231,7 +219,6 @@
assert fqn1.hashCode() == fqn2.hashCode();
}
- @Test(groups = {"functional"})
public void testNullElements() throws CloneNotSupportedException
{
Fqn<Object> fqn0 = new Fqn<Object>((Object) null);
@@ -246,7 +233,6 @@
assert fqn1.equals(fqn1.clone());
}
- @Test(groups = {"functional"})
public void testIteration()
{
Fqn<String> fqn = Fqn.fromString("/a/b/c");
@@ -263,7 +249,6 @@
assert fqn.equals(tmp_fqn);
}
- @Test(groups = {"functional"})
public void testIsChildOf()
{
Fqn<String> child = Fqn.fromString("/a/b");
@@ -277,14 +262,12 @@
assert child.isChildOf(parent);
}
- @Test(groups = {"functional"})
public void testIsChildOf2()
{
Fqn<String> child = Fqn.fromString("/a/b/c/d");
assert "/b/c/d".equals(child.getSubFqn(1, child.size()).toString());
}
- @Test(groups = {"functional"})
public void testParentage()
{
Fqn<String> fqnRoot = new Fqn<String>();
@@ -308,7 +291,6 @@
}
- @Test(groups = {"functional"})
public void testRoot()
{
Fqn<String> fqn = new Fqn<String>();
@@ -318,7 +300,6 @@
assert !fqn.isRoot();
}
- @Test(groups = {"functional"})
public void testGetName()
{
Fqn<Integer> integerFqn = new Fqn<Integer>(1);
@@ -329,7 +310,6 @@
assert object.toString().equals(objectFqn.getLastElementAsString());
}
- @Test(groups = {"functional"})
public void testCloningString() throws CloneNotSupportedException
{
Fqn<String> f = Fqn.fromString("/a/b/c");
@@ -343,7 +323,6 @@
assert f.equals(f.clone());
}
- @Test(groups = {"functional"})
public void testRemovalNonString() throws Exception
{
Fqn<Object> f = new Fqn<Object>("test", 1);
@@ -372,7 +351,6 @@
// testing generics
- @Test(groups = {"functional"})
public void testGenerics()
{
Fqn<String> f = Fqn.fromString("/blah/blah");
@@ -387,7 +365,21 @@
assert f3.getParent().equals(f4);
}
- @Test(groups = {"functional"})
+ public void testSize()
+ {
+ Fqn f = new Fqn();
+ assert f.size() == 0;
+ assert f.isRoot();
+
+ f = Fqn.fromString("/");
+ assert f.size() == 0;
+ assert f.isRoot();
+
+ f = Fqn.fromString("/hello");
+ assert f.size() == 1;
+ assert !f.isRoot();
+ }
+
public void testGenerations()
{
Fqn<Integer> f = new Fqn<Integer>(1, 2, 3, 4, 5, 6, 7);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CrudMethodTest.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -8,11 +8,10 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
-
import org.testng.annotations.Test;
+
/**
* Checks CRUD methods
*
@@ -32,8 +31,6 @@
assertTrue(MethodDeclarations.isPutMethod(MethodDeclarations.putKeyValVersionedMethodLocal_id));
assertTrue(MethodDeclarations.isPutMethod(MethodDeclarations.putForExternalReadMethodLocal_id));
assertTrue(MethodDeclarations.isPutMethod(MethodDeclarations.putForExternalReadVersionedMethodLocal_id));
-
- assertEquals(8, MethodDeclarations.putMethodIds.size());
}
public void testTransactionLifecycleMethods()
@@ -42,8 +39,6 @@
assertTrue(MethodDeclarations.isTransactionLifecycleMethod(MethodDeclarations.rollbackMethod_id));
assertTrue(MethodDeclarations.isTransactionLifecycleMethod(MethodDeclarations.prepareMethod_id));
assertTrue(MethodDeclarations.isTransactionLifecycleMethod(MethodDeclarations.optimisticPrepareMethod_id));
-
- assertEquals(4, MethodDeclarations.transactionLifecycleMethodIds.size());
}
public void testCrudMethods()
@@ -65,8 +60,6 @@
assertTrue(MethodDeclarations.isCrudMethod(MethodDeclarations.putForExternalReadMethodLocal_id));
assertTrue(MethodDeclarations.isCrudMethod(MethodDeclarations.putForExternalReadVersionedMethodLocal_id));
- assertEquals(16, MethodDeclarations.crudMethodIds.size());
-
assertFalse(MethodDeclarations.isCrudMethod(MethodDeclarations.getKeyValueMethodLocal_id));
assertFalse(MethodDeclarations.isCrudMethod(MethodDeclarations.getNodeMethodLocal_id));
assertFalse(MethodDeclarations.isCrudMethod(MethodDeclarations.getKeysMethodLocal_id));
@@ -78,7 +71,5 @@
assertTrue(MethodDeclarations.isBuddyGroupOrganisationMethod(MethodDeclarations.remoteAnnounceBuddyPoolNameMethod_id));
assertTrue(MethodDeclarations.isBuddyGroupOrganisationMethod(MethodDeclarations.remoteAssignToBuddyGroupMethod_id));
assertTrue(MethodDeclarations.isBuddyGroupOrganisationMethod(MethodDeclarations.remoteRemoveFromBuddyGroupMethod_id));
-
- assertEquals(3, MethodDeclarations.buddyGroupOrganisationMethodIds.size());
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-01-03 13:29:35 UTC (rev 4967)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-01-03 19:17:09 UTC (rev 4968)
@@ -1,14 +1,16 @@
package org.jboss.cache.profiling;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
@@ -34,62 +36,34 @@
/*
Test configuration options
*/
- protected static final long DURATION = 2 * 60000;
+ protected static final long DURATION = 2 * 60 * 1000;
protected static final int NUM_THREADS = 10;
protected static final int MAX_RANDOM_SLEEP_MILLIS = 100;
protected static final int MAX_DEPTH = 8;
protected static final int MAX_OVERALL_NODES = 100;
+ protected static final int WARMUP_LOOPS = 10000;
-
private List<Fqn> fqns = new ArrayList<Fqn>(MAX_OVERALL_NODES);
private Random r = new Random();
- @BeforeTest
- public void initialiseFqns()
- {
- fqns.clear();
- for (int i = 0; i < MAX_OVERALL_NODES; i++)
- {
- Fqn fqn = createRandomFqn(r);
- while (fqns.contains(fqn)) fqn = createRandomFqn(r);
- if (i % 100 == 0) System.out.println("Generated " + i + " fqns");
- fqns.add(fqn);
- }
- System.gc();
- System.out.println("Finished initialising. Starting test.");
- }
+ private Log log = LogFactory.getLog(ProfileTest.class);
- private Fqn createRandomFqn(Random r)
- {
- String s = "/";
- int depth = r.nextInt(MAX_DEPTH);
- for (int i = 0; i < depth; i++)
- {
- s += r.nextInt(Integer.MAX_VALUE) + "/";
- }
-
- return Fqn.fromString(s);
- }
-
public void testReplSync() throws Exception
{
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplAsync() throws Exception
{
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplSyncOptimistic() throws Exception
{
cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplAsyncOptimistic() throws Exception
@@ -97,8 +71,7 @@
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- cache.start();
- doTest();
+ runCompleteTest();
}
public void testReplSyncBR() throws Exception
@@ -133,15 +106,92 @@
testReplAsyncOptimistic();
}
+ private void runCompleteTest() throws Exception
+ {
+ init();
+ startup();
+ warmup();
+ doTest();
+ }
+
+ /**
+ * Thr following test phases can be profiled individually using triggers in JProfiler.
+ */
+
+ protected void init()
+ {
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting init() phase");
+ fqns.clear();
+ for (int i = 0; i < MAX_OVERALL_NODES; i++)
+ {
+ Fqn fqn = createRandomFqn(r);
+ while (fqns.contains(fqn)) fqn = createRandomFqn(r);
+ if (i % 10 == 0)
+ {
+ log.warn("Generated " + i + " fqns");
+ }
+ fqns.add(fqn);
+ }
+ System.gc();
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Finished init() phase. " + printDuration(duration));
+ }
+
+ private Fqn createRandomFqn(Random r)
+ {
+ String s = "/";
+ int depth = r.nextInt(MAX_DEPTH);
+ for (int i = 0; i < depth; i++)
+ {
+ s += r.nextInt(Integer.MAX_VALUE) + "/";
+ }
+
+ return Fqn.fromString(s);
+ }
+
+
+ private void startup()
+ {
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting cache");
+ cache.start();
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Started cache. " + printDuration(duration));
+ }
+
+ private void warmup()
+ {
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting warmup");
+ // creates all the Fqns since this can be expensive and we don't really want to measure this (for now)
+ for (Fqn f : fqns)
+ {
+ // this will create the necessary nodes.
+ cache.put(f, Collections.emptyMap());
+ }
+
+ // loop through WARMUP_LOOPS gets and puts for JVM optimisation
+ for (int i = 0; i < WARMUP_LOOPS; i++)
+ {
+ Fqn f = fqns.get(r.nextInt(MAX_OVERALL_NODES));
+ cache.get(f, "");
+ cache.put(f, "k", "v");
+ cache.remove(f, "k");
+ }
+
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Finished warmup. " + printDuration(duration));
+ }
+
private void doTest() throws Exception
{
ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS);
long end = System.currentTimeMillis() + DURATION;
- int i = 0;
- long start = System.currentTimeMillis();
+ long startTime = System.currentTimeMillis();
+ log.warn("Starting test");
while (System.currentTimeMillis() < end)
{
- i++;
exec.execute(new Runnable()
{
public void run()
@@ -153,12 +203,12 @@
});
TestingUtil.sleepRandom(MAX_RANDOM_SLEEP_MILLIS);
}
-
+ log.warn("Finished generating runnables; awaiting executor completion");
// wait for executors to complete!
exec.shutdown();
exec.awaitTermination(10000, TimeUnit.MILLISECONDS);
- double durationSecs = (System.currentTimeMillis() - start) / 1000;
- System.out.println("Completed Test! Achieved " + ((double) i / durationSecs) + " TPS.");
+ long duration = System.currentTimeMillis() - startTime;
+ log.warn("Finished test. " + printDuration(duration));
}
private String getRandomString()
@@ -172,4 +222,17 @@
}
return sb.toString();
}
+
+ private String printDuration(long duration)
+ {
+ if (duration > 2000)
+ {
+ double dSecs = ((double) duration / (double) 1000);
+ return "Duration: " + dSecs + " seconds";
+ }
+ else
+ {
+ return "Duration: " + duration + " millis";
+ }
+ }
}
16 years, 11 months
JBoss Cache SVN: r4967 - core/trunk/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-01-03 08:29:35 -0500 (Thu, 03 Jan 2008)
New Revision: 4967
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
Log:
fixed broken unit test
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2008-01-03 13:20:31 UTC (rev 4966)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2008-01-03 13:29:35 UTC (rev 4967)
@@ -85,12 +85,9 @@
assertSame(listClass, cache2.get(fqn, key).getClass());
// now test if this is the same when obtained using a clustered get mcall
- MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateMethod,
- MethodCallFactory.create(MethodDeclarations.clusteredGetMethod,
- MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false),
- false
- )
- );
+ MethodCall call = MethodCallFactory.create(MethodDeclarations.clusteredGetMethod,
+ MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false),
+ false);
List responses = cache1.getRPCManager().callRemoteMethods(null, call, true, true, 15000);
List response1 = (List) responses.get(0);// response from the first (and only) node
@@ -117,11 +114,8 @@
assertSame(listClass, cache2.get(fqn, key).getClass());
// now test if this is the same when obtained using a data gravitate call
- MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateMethod,
- MethodCallFactory.create(MethodDeclarations.dataGravitationMethod,
- fqn, false
- )
- );
+ MethodCall call = MethodCallFactory.create(MethodDeclarations.dataGravitationMethod,
+ fqn, false);
List responses = cache1.getRPCManager().callRemoteMethods(null, call, true, true, 15000);
GravitateResult data = (GravitateResult) responses.get(0);// response from the first (and only) node
16 years, 11 months