JBoss Cache SVN: r5158 - benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-16 19:17:07 -0500 (Wed, 16 Jan 2008)
New Revision: 5158
Modified:
benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/CacheTest.java
Log:
added javadoc
Modified: benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/CacheTest.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/CacheTest.java 2008-01-17 00:11:22 UTC (rev 5157)
+++ benchmarks/benchmark-fwk/trunk/src/org/cachebench/tests/CacheTest.java 2008-01-17 00:17:07 UTC (rev 5158)
@@ -6,12 +6,18 @@
/**
+ * Each newly creted test should extend this class.
+ *
* @author Manik Surtani (manik(a)surtani.org)
* (C) Manik Surtani, 2004
*/
public interface CacheTest
{
+ /**
+ * Called before {@link #doTest(String, org.cachebench.CacheWrapper, String, int, int)}.
+ * Implemetations may cache this and further use on doTest method.
+ */
public void setConfiguration(Configuration configuration);
/**
16 years, 12 months
JBoss Cache SVN: r5157 - benchmarks/benchmark-fwk/trunk.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-01-16 19:11:22 -0500 (Wed, 16 Jan 2008)
New Revision: 5157
Modified:
benchmarks/benchmark-fwk/trunk/runNode.sh
Log:
Modified: benchmarks/benchmark-fwk/trunk/runNode.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/runNode.sh 2008-01-16 23:51:09 UTC (rev 5156)
+++ benchmarks/benchmark-fwk/trunk/runNode.sh 2008-01-17 00:11:22 UTC (rev 5157)
@@ -9,11 +9,12 @@
if [ -z $1 ]
then
echo "Usage:"
- echo " ./runNode.sh currentNodeIndex testConfig otherSysProps customConfigFile"
- echo "currentNodeIndex : the index of this node in the list of nodes in the cluster(0..n)"
- echo "testConfig : must be one of the directories names under 'cache-products'"
- echo "cluster size"
- echo "Ex: ./runNode.sh 0 jbosscache-2.0.0 3"
+ echo
+ echo " ./runNode.sh <currentNodeIndex> <testConfig> <clusterSize>"
+ echo "param <currentNodeIndex> : the index of this node in the list of nodes in the cluster(0..<clusterSize>-1)"
+ echo "param <testConfig> : must be one of the directories names under './cache-products'"
+ echo "param <clusterSize> : total number of nodes that will run tests. "
+ echo "Ex: './runNode.sh 0 jbosscache-2.0.0 3' will start the 1st node running an instance of jbc2.0.0 on a cluster made out of 3 nodes."
exit 1
fi
16 years, 12 months
JBoss Cache SVN: r5156 - in pojo/branches/2.1/src: test/java/org/jboss/cache/pojo/notification and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 18:51:09 -0500 (Wed, 16 Jan 2008)
New Revision: 5156
Added:
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
Log:
Merge 4868 - Fix for PCACHE-56
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java 2008-01-16 22:52:32 UTC (rev 5155)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java 2008-01-16 23:51:09 UTC (rev 5156)
@@ -122,7 +122,8 @@
if (! (o instanceof Entry))
return false;
- return ((Entry)o).equals(listener);
+ // Must be the same instance
+ return ((Entry)o).listener == this.listener;
}
private static Map<Class<?>, List<Method>> buildNotifiers(Class clazz)
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 22:52:32 UTC (rev 5155)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 23:51:09 UTC (rev 5156)
@@ -298,7 +298,10 @@
{
try
{
+ boolean wasEmpty = listenerAdaptor.isEmpty();
listenerAdaptor.addListener(listener, pattern);
+ if (wasEmpty)
+ cache.addCacheListener(listenerAdaptor);
}
catch (IllegalArgumentException e)
{
@@ -306,7 +309,6 @@
e.fillInStackTrace();
throw e;
}
- cache.addCacheListener(listenerAdaptor);
}
}
Copied: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java (from rev 4868, pojo/trunk/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java)
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java (rev 0)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/notification/ListenerCountTest.java 2008-01-16 23:51:09 UTC (rev 5156)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.cache.pojo.notification;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.impl.CacheListenerAdaptor;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+// $Id: ObjectTest.java 4698 2007-10-26 18:30:20Z jason.greene(a)jboss.com $
+
+/**
+ * Tests that CacheListenerAdaptor is attached properly.
+ *
+ * @author Jason T. Greene
+ */
+@Test(groups = {"functional"})
+public class ListenerCountTest
+{
+ protected PojoCache cache;
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ String configFile = "META-INF/local-service.xml";
+ boolean toStart = false;
+ cache = PojoCacheFactory.createCache(configFile, toStart);
+ cache.start();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ }
+
+ public void testAddRemoveListener() throws Exception
+ {
+ assertEquals(0, getAdaptorCount());
+
+ Object listener1 = new Listener();
+ cache.addListener(listener1);
+ assertEquals(1, getAdaptorCount());
+
+ Object listener2 = new Listener();
+ cache.addListener(listener2);
+ assertEquals(1, getAdaptorCount());
+
+ cache.removeListener(listener1);
+ assertEquals(1, getAdaptorCount());
+
+ cache.removeListener(listener2);
+ assertEquals(0, getAdaptorCount());
+ }
+
+ private int getAdaptorCount()
+ {
+ int count = 0;
+ for (Object listener : cache.getCache().getCacheListeners())
+ if (listener instanceof CacheListenerAdaptor)
+ count++;
+
+ return count;
+ }
+}
\ No newline at end of file
16 years, 12 months
JBoss Cache SVN: r5155 - pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:52:32 -0500 (Wed, 16 Jan 2008)
New Revision: 5155
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
Log:
Merge 5126
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-01-16 22:51:48 UTC (rev 5154)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-01-16 22:52:32 UTC (rev 5155)
@@ -936,17 +936,20 @@
*/
private void sendStateChangeNotification(int oldState, int newState, String msg, Throwable t)
{
- long now = System.currentTimeMillis();
-
- AttributeChangeNotification stateChangeNotification = new AttributeChangeNotification(
- this,
- plainCacheWrapper.getNextNotificationSequenceNumber(), now, msg,
- "State", "java.lang.Integer",
- new Integer(oldState), new Integer(newState)
- );
- stateChangeNotification.setUserData(t);
-
- plainCacheWrapper.sendNotification(stateChangeNotification);
+ if (plainCacheWrapper != null)
+ {
+ long now = System.currentTimeMillis();
+
+ AttributeChangeNotification stateChangeNotification = new AttributeChangeNotification(
+ this,
+ plainCacheWrapper.getNextNotificationSequenceNumber(), now, msg,
+ "State", "java.lang.Integer",
+ new Integer(oldState), new Integer(newState)
+ );
+ stateChangeNotification.setUserData(t);
+
+ plainCacheWrapper.sendNotification(stateChangeNotification);
+ }
}
/**
16 years, 12 months
JBoss Cache SVN: r5154 - in pojo/branches/2.1: src/main/release and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:51:48 -0500 (Wed, 16 Jan 2008)
New Revision: 5154
Added:
pojo/branches/2.1/src/main/release/bin/
pojo/branches/2.1/src/main/release/bin/pojo-run
Removed:
pojo/branches/2.1/src/main/release/bin/pojo-run
Modified:
pojo/branches/2.1/assembly/all.xml
pojo/branches/2.1/assembly/bin.xml
Log:
Merge 4859 and 4860
Modified: pojo/branches/2.1/assembly/all.xml
===================================================================
--- pojo/branches/2.1/assembly/all.xml 2008-01-16 22:46:23 UTC (rev 5153)
+++ pojo/branches/2.1/assembly/all.xml 2008-01-16 22:51:48 UTC (rev 5154)
@@ -46,12 +46,14 @@
<fileSet>
<directory>src/main/release</directory>
<outputDirectory/>
- <includes>
- <include>**/*.txt</include>
- <include>**/*.xml</include>
- </includes>
</fileSet>
+ <fileSet>
+ <directory>src/main/release/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0755</fileMode>
+ </fileSet>
+
<!-- docs -->
<fileSet>
<directory>target/site/apidocs</directory>
Modified: pojo/branches/2.1/assembly/bin.xml
===================================================================
--- pojo/branches/2.1/assembly/bin.xml 2008-01-16 22:46:23 UTC (rev 5153)
+++ pojo/branches/2.1/assembly/bin.xml 2008-01-16 22:51:48 UTC (rev 5154)
@@ -27,12 +27,14 @@
<fileSet>
<directory>src/main/release</directory>
<outputDirectory/>
- <includes>
- <include>**/*.txt</include>
- <include>**/*.xml</include>
- </includes>
</fileSet>
+ <fileSet>
+ <directory>src/main/release/bin</directory>
+ <outputDirectory>bin</outputDirectory>
+ <fileMode>0755</fileMode>
+ </fileSet>
+
</fileSets>
<dependencySets>
<dependencySet>
Copied: pojo/branches/2.1/src/main/release/bin (from rev 4860, pojo/trunk/src/main/release/bin)
Deleted: pojo/branches/2.1/src/main/release/bin/pojo-run
===================================================================
--- pojo/trunk/src/main/release/bin/pojo-run 2007-12-14 04:58:12 UTC (rev 4860)
+++ pojo/branches/2.1/src/main/release/bin/pojo-run 2008-01-16 22:51:48 UTC (rev 5154)
@@ -1,75 +0,0 @@
-#!/bin/sh
-DIRNAME=`dirname $0`
-POJO_HOME=`cd $DIRNAME/..; pwd`
-
-if [ $# -lt 1 ]; then
- echo Utility which executes the JVM with properties needed by POJO Cache for load-time instrumentation.
- echo
- echo Usage:
- echo "pojo-run [-classpath <classpath>] <main-class> [arguments...] "
- echo " classpath: Classpath of your sourcefiles and all required libraries"
- echo " main-class: Normal Java main class"
- echo
- echo Example:
- echo " pojo-run -classpath myclasses org.foo.Main"
- exit 1
-fi
-
-cygwin=false;
-case "`uname`" in
- CYGWIN*)
- cygwin=true
- ;;
-esac
-
-AOP_FILE="pojocache-aop.xml"
-AOP_PATH="$POJO_HOME/$AOP_FILE"
-
-if [ ! -f "$AOP_PATH" ]; then
- AOP_PATH="$POJO_HOME/etc/META-INF/$AOP_FILE"
-
- if [ ! -f "$AOP_PATH" ]; then
- echo "Could not locate pojocache-aop.xml in $POJO_HOME or $POJO_HOME/etc/META-INF"
- exit 1
- fi
-fi
-
-POJO_CLASSPATH=.:$POJO_HOME/jbosscache-pojo.jar
-
-for i in $POJO_HOME/lib/*.jar
-do
- POJO_CLASSPATH="$POJO_CLASSPATH:${i}"
-done
-
-while [ $# -ge 1 ]; do
- case $1 in
- "-classpath") POJO_CLASSPATH="$POJO_CLASSPATH:$2"; shift;;
- *) args="$args \"$1\""; echo $1;;
- esac
- shift
-done
-
-
-#Check for cygwin and convert path if necessary
-if $cygwin; then
- POJO_CLASSPATH=`cygpath --path --windows $POJO_CLASSPATH`
-fi
-
-# Setup the JVM
-if [ "x$JAVA" = "x" ]; then
- if [ "x$JAVA_HOME" != "x" ]; then
- JAVA="$JAVA_HOME/bin/java"
- else
- JAVA="java"
- fi
-fi
-
-#JPDA options. Uncomment and modify as appropriate to enable remote debugging .
-#JAVA_OPTS="-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n $JAVA_OPTS"
-
-# Execute the JVM
-eval "$JAVA" $JAVA_OPTS \
- -javaagent:"$POJO_HOME/lib/jboss-aop.jar" \
- -Djboss.aop.path="$AOP_PATH" \
- -classpath "$POJO_CLASSPATH" \
- "$args"
Copied: pojo/branches/2.1/src/main/release/bin/pojo-run (from rev 4860, pojo/trunk/src/main/release/bin/pojo-run)
===================================================================
--- pojo/branches/2.1/src/main/release/bin/pojo-run (rev 0)
+++ pojo/branches/2.1/src/main/release/bin/pojo-run 2008-01-16 22:51:48 UTC (rev 5154)
@@ -0,0 +1,75 @@
+#!/bin/sh
+DIRNAME=`dirname $0`
+POJO_HOME=`cd $DIRNAME/..; pwd`
+
+if [ $# -lt 1 ]; then
+ echo Utility which executes the JVM with properties needed by POJO Cache for load-time instrumentation.
+ echo
+ echo Usage:
+ echo "pojo-run [-classpath <classpath>] <main-class> [arguments...] "
+ echo " classpath: Classpath of your sourcefiles and all required libraries"
+ echo " main-class: Normal Java main class"
+ echo
+ echo Example:
+ echo " pojo-run -classpath myclasses org.foo.Main"
+ exit 1
+fi
+
+cygwin=false;
+case "`uname`" in
+ CYGWIN*)
+ cygwin=true
+ ;;
+esac
+
+AOP_FILE="pojocache-aop.xml"
+AOP_PATH="$POJO_HOME/$AOP_FILE"
+
+if [ ! -f "$AOP_PATH" ]; then
+ AOP_PATH="$POJO_HOME/etc/META-INF/$AOP_FILE"
+
+ if [ ! -f "$AOP_PATH" ]; then
+ echo "Could not locate pojocache-aop.xml in $POJO_HOME or $POJO_HOME/etc/META-INF"
+ exit 1
+ fi
+fi
+
+POJO_CLASSPATH=.:$POJO_HOME/jbosscache-pojo.jar
+
+for i in $POJO_HOME/lib/*.jar
+do
+ POJO_CLASSPATH="$POJO_CLASSPATH:${i}"
+done
+
+while [ $# -ge 1 ]; do
+ case $1 in
+ "-classpath") POJO_CLASSPATH="$POJO_CLASSPATH:$2"; shift;;
+ *) args="$args \"$1\""; echo $1;;
+ esac
+ shift
+done
+
+
+#Check for cygwin and convert path if necessary
+if $cygwin; then
+ POJO_CLASSPATH=`cygpath --path --windows $POJO_CLASSPATH`
+fi
+
+# Setup the JVM
+if [ "x$JAVA" = "x" ]; then
+ if [ "x$JAVA_HOME" != "x" ]; then
+ JAVA="$JAVA_HOME/bin/java"
+ else
+ JAVA="java"
+ fi
+fi
+
+#JPDA options. Uncomment and modify as appropriate to enable remote debugging .
+#JAVA_OPTS="-classic -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n $JAVA_OPTS"
+
+# Execute the JVM
+eval "$JAVA" $JAVA_OPTS \
+ -javaagent:"$POJO_HOME/lib/jboss-aop.jar" \
+ -Djboss.aop.path="$AOP_PATH" \
+ -classpath "$POJO_CLASSPATH" \
+ "$args"
16 years, 12 months
JBoss Cache SVN: r5153 - in pojo/branches/2.1/src: main/java/org/jboss/cache/pojo/interceptors/dynamic and 3 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:46:23 -0500 (Wed, 16 Jan 2008)
New Revision: 5153
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/CachedType.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
pojo/branches/2.1/src/main/resources/META-INF/pojocache-aop.xml
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalTest.java
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedTest.java
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/test/Person.java
Log:
Merge 4857 and 4858
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-01-16 22:46:23 UTC (rev 5153)
@@ -26,6 +26,7 @@
import org.jboss.cache.pojo.memory.FieldPersistentReference;
import org.jboss.cache.pojo.util.AopUtil;
import org.jboss.cache.pojo.util.Instantiator;
+import org.jboss.cache.pojo.util.ObjectUtil;
/**
* Handling the advised pojo operations. No consideration of object graph here.
@@ -49,14 +50,33 @@
util_ = util;
}
- public Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance pojoInstance)
- throws CacheException
+ public Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance pojoInstance) throws CacheException
{
CachedType type = pCache_.getCachedType(clazz);
- Object obj =Instantiator.newInstance(clazz);
+ Object obj = Instantiator.newInstance(clazz);
+
+ // Eager initialize final fields, since these may not be intercepted
+
+ try
+ {
+ for (FieldPersistentReference ref : type.getFinalFields())
+ {
+ Field field = ref.getField();
+ Object result;
+
+ if (CachedType.isSimpleAttribute(field))
+ result = cache_.get(fqn, field.getName());
+ else
+ result = pCache_.getObject(fqn, field.getName());
+
+ field.set(obj, result);
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn("Could not initialize final fields on object: " + ObjectUtil.identityString(obj));
+ }
- // TODO Need to populate the object from the cache as well.
- // Insert interceptor at runtime
InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
CacheFieldInterceptor interceptor = new CacheFieldInterceptor(pCache_, fqn, type);
interceptor.setAopInstance(pojoInstance);
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/CachedType.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/CachedType.java 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/CachedType.java 2008-01-16 22:46:23 UTC (rev 5153)
@@ -31,8 +31,8 @@
public class CachedType
{
// Types that are considered "primitive".
- private static final Set immediates =
- new HashSet(Arrays.asList(new Object[]{
+ private static final Set<Object> immediates =
+ new HashSet<Object>(Arrays.asList(new Object[]{
String.class,
Boolean.class,
Double.class,
@@ -57,8 +57,9 @@
private boolean immediate;
// Java fields . Will use special FieldPersistentReference to prevent classloader leakage.
- private List fields = new ArrayList();
- private Map fieldMap = new HashMap();// Name -> CachedAttribute
+ private List<FieldPersistentReference> fields = new ArrayList<FieldPersistentReference>();
+ private List<FieldPersistentReference> finalFields = new ArrayList<FieldPersistentReference>();
+ private Map<String, FieldPersistentReference> fieldMap = new HashMap<String, FieldPersistentReference>();// Name -> CachedAttribute
public CachedType()
{
@@ -92,14 +93,19 @@
return immutable;
}
- public List getFields()
+ public List<FieldPersistentReference> getFields()
{
return fields;
}
+
+ public List<FieldPersistentReference> getFinalFields()
+ {
+ return finalFields;
+ }
public Field getField(String name)
{
- FieldPersistentReference ref = (FieldPersistentReference) fieldMap.get(name);
+ FieldPersistentReference ref = fieldMap.get(name);
if (ref == null) return null;
return (Field) ref.get();
}
@@ -209,7 +215,7 @@
for (int i = 0; i < classFields.length; i++)
{
Field f = classFields[i];
- if (isNonReplicatable(f)) continue;
+ if (isNonReplicable(f)) continue;
PrivilegedCode.setAccessible(f);
@@ -217,17 +223,20 @@
fields.add(persistentRef);
fieldMap.put(f.getName(), persistentRef);
+
+ if (Modifier.isFinal(f.getModifiers()))
+ finalFields.add(persistentRef);
}
}
- public static boolean isNonReplicatable(Field field)
+ public static boolean isNonReplicable(Field field)
{
int mods = field.getModifiers();
/**
* The following modifiers are ignored in the cache, i.e., they will not be stored in the cache.
* Whenever, user trying to access these fields, it will be accessed from the in-memory version.
*/
- return Modifier.isStatic(mods) || Modifier.isTransient(mods) || Modifier.isFinal(mods) ||
+ return Modifier.isStatic(mods) || Modifier.isTransient(mods) ||
field.isAnnotationPresent(org.jboss.cache.pojo.annotation.Transient.class);
}
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-01-16 22:46:23 UTC (rev 5153)
@@ -112,7 +112,7 @@
// Only if this field is replicatable. static, transient and final are not.
CachedType fieldType = pCache_.getCachedType(field.getType());
Object value = ((FieldWriteInvocation) fieldInvocation).getValue();
- if (!CachedType.isNonReplicatable(field))
+ if (!CachedType.isNonReplicable(field))
{
if (CachedType.isSimpleAttribute(field))
{
@@ -136,7 +136,7 @@
// Only if this field is replicatable
CachedType fieldType = pCache_.getCachedType(field.getType());
- if (!CachedType.isNonReplicatable(field))
+ if (!CachedType.isNonReplicable(field))
{
Object result;
if (CachedType.isSimpleAttribute(field))
Modified: pojo/branches/2.1/src/main/resources/META-INF/pojocache-aop.xml
===================================================================
--- pojo/branches/2.1/src/main/resources/META-INF/pojocache-aop.xml 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/main/resources/META-INF/pojocache-aop.xml 2008-01-16 22:46:23 UTC (rev 5153)
@@ -137,10 +137,13 @@
instrumented as well.
-->
- <!-- If a POJO has PojoCachable annotation, it will be asepectized. -->
+ <!-- If a POJO has Replicable annotation, it will be asepectized. -->
<!--
Supports inheritance and polymorphism. It can either be a concrete class
or an interface. All sub-classes or interface implementors will be instrumeneted.
-->
<prepare expr="field(* $instanceof{(a)org.jboss.cache.pojo.annotation.Replicable}->*)" />
-</aop>
+
+ <!-- Work around that ensures annotated classes which do not access fields are instrumented -->
+ <introduction expr="class($instanceof{(a)org.jboss.cache.pojo.annotation.Replicable})"/>
+</aop>
\ No newline at end of file
Modified: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalTest.java 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/LocalTest.java 2008-01-16 22:46:23 UTC (rev 5153)
@@ -58,7 +58,12 @@
private Person createPerson(String id, String name, int age)
{
- Person p = new Person();
+ return createPerson(id, name, age, null);
+ }
+
+ private Person createPerson(String id, String name, int age, Map<String, String> finalMap)
+ {
+ Person p = new Person(finalMap);
p.setName(name);
p.setAge(age);
Address add = new Address();
@@ -154,6 +159,7 @@
}
}
+
public void testMap() throws Exception
{
log.info("testMap() ....");
@@ -178,7 +184,29 @@
assertEquals("Hobbies size", 2, hobbies.size());
log.debug("Hobbies is " + hobbies.toString());
}
+ public void testFinalMap() throws Exception
+ {
+ log.info("testMap() ....");
+ Person ben = createPerson("/person/test1", "Ben Wang", 40, new HashMap<String, String>());
+ assertEquals((Object) "Ben Wang", ben.getName());
+ Map<String, String> map = ben.getFinalMap();
+ if (!(map instanceof ClassProxy))
+ {
+ fail("Final map is not an instance of ClassProxy");
+ }
+
+ map.put("test1", "testa");
+ map.put("test2", "testb");
+ assertEquals("Hobbies size", 2, map.size());
+ ben = (Person) cache_.detach("/person/test1");
+ map = ben.getFinalMap();
+ if (!(map instanceof HashMap))
+ {
+ fail("Final map is not an instance of HashMap");
+ }
+ }
+
public void testMapDetachAttach() throws Exception
{
log.info("testMapDetachATtach() ....");
Modified: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedTest.java 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/ReplicatedTest.java 2008-01-16 22:46:23 UTC (rev 5153)
@@ -4,7 +4,9 @@
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,7 +51,12 @@
private Person createPerson(String id, String name, int age)
{
- Person p = new Person();
+ return createPerson(id, name, age, null);
+ }
+
+ private Person createPerson(String id, String name, int age, Map<String, String> map)
+ {
+ Person p = new Person(map);
p.setName(name);
p.setAge(age);
cache.attach(id, p);
@@ -112,6 +119,17 @@
((Person) cache1.find("/person/test1")).getCurrentStatus());
cache.detach("/person/test1");
}
+
+ public void testFinal() throws Exception
+ {
+ Person jason = createPerson("/person/test1", "Jason Greene", 28, new HashMap<String, String>());
+ jason.getFinalMap().put("test1", "testa");
+ jason.getFinalMap().put("test2", "testb");
+
+ Person jason2 = (Person) cache1.find("/person/test1");
+ assertEquals("testa", jason2.getFinalMap().get("test1"));
+ assertEquals("testb", jason2.getFinalMap().get("test2"));
+ }
public void testModification() throws Exception
{
Modified: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/test/Person.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/test/Person.java 2008-01-16 22:36:22 UTC (rev 5152)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/test/Person.java 2008-01-16 22:46:23 UTC (rev 5153)
@@ -7,6 +7,8 @@
package org.jboss.cache.pojo.test;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -40,11 +42,17 @@
private List<String> medication = null;
private static final int AGE1 = 50;
private static final int AGE2 = 60;
+ private final Map<String, String> finalMap;
public Person()
{
-
+ this(null);
}
+
+ public Person(Map<String, String> map)
+ {
+ finalMap = map;
+ }
public String getName()
{
@@ -162,6 +170,11 @@
{
this.languages = languages;
}
+
+ public Map<String, String> getFinalMap()
+ {
+ return this.finalMap;
+ }
public String toString()
{
16 years, 12 months
JBoss Cache SVN: r5152 - pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:36:22 -0500 (Wed, 16 Jan 2008)
New Revision: 5152
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
Log:
Merge 5127
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-01-16 22:17:11 UTC (rev 5151)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapper.java 2008-01-16 22:36:22 UTC (rev 5152)
@@ -251,13 +251,15 @@
{
cacheStatus = CacheStatus.DESTROYING;
- pojoCache.destroy();
+ if (pojoCache != null)
+ pojoCache.destroy();
// The cache is destroyed, so we shouldn't leave it registered
// in JMX even if we didn't register it in create()
unregisterPlainCache();
- plainCacheWrapper.destroy();
+ if (plainCacheWrapper != null)
+ plainCacheWrapper.destroy();
}
finally
{
16 years, 12 months
JBoss Cache SVN: r5151 - in pojo/trunk/src: main/java/org/jboss/cache/pojo and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:17:11 -0500 (Wed, 16 Jan 2008)
New Revision: 5151
Added:
pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java
Modified:
pojo/trunk/src/main/docbook/userguide/en/modules/instrumentation.xml
pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
Log:
Merge 5150 and 5149
Modified: pojo/trunk/src/main/docbook/userguide/en/modules/instrumentation.xml
===================================================================
--- pojo/trunk/src/main/docbook/userguide/en/modules/instrumentation.xml 2008-01-16 22:15:37 UTC (rev 5150)
+++ pojo/trunk/src/main/docbook/userguide/en/modules/instrumentation.xml 2008-01-16 22:17:11 UTC (rev 5151)
@@ -7,7 +7,7 @@
approach since it preserves object identity and provides field granular
replication. POJO Cache currently uses the JBoss AOP project to provide
instrumentation, so the same processes described in the AOP documentation
- can be used with POJO Cache.</para>
+ are used with POJO Cache.</para>
<para>The primary input to JBoss AOP is the AOP binding file, which is
responsible for specifying which classes should be instrumented. POJO Cache
@@ -57,86 +57,74 @@
<jvmarg value="-Djboss.aop.path=etc/META-INF/pojocache-aop.xml"/>
<classpath refid="test.classpath"/>
</java> </programlisting>
+
+ <para>Once the JVM is executed in this manner, any class with the
+ <literal>@Replicable</literal> annotation will be instrumented when it is
+ loaded.</para>
</sect1>
- <para>For the first step, since we are using the dynamic Aop feature, a POJO
- is only required to be declared "prepare". Basically, there are two ways to
- do this: either via explicit xml or annotation.</para>
+ <sect1>
+ <title>Compile-time instrumentation</title>
- <para>As for the second step, either we can ask JBoss Aop to do load-time
- (through a special class loader, so-called load-time mode) or compile-time
- instrumentation (use of an aopc pre-compiler, so-called precompiled mode).
- Reader can read the JBoss Aop introduction chapter for more details.</para>
+ <para>While load-time is the preffered approach, it is also possible to
+ instrument classes at compile-time. To do this, the aopc tool is used,
+ with the following requirements:</para>
- <sect1><title>XML descriptor</title> <para> To declare a POJO via XML
- configuration file, you will need a
- <literal>META-INF/jboss-aop.xml</literal> (or in the PojoCache case, it is
- the equivalent <literal>pojocache-service.xml</literal> file located under
- the class path or listed in the <literal>jboss.aop.path</literal> system
- property. JBoss AOP framework will read this file during startup to make
- necessary byte code manipulation for advice and introduction. Or you can
- pre-compile it using a pre-compiler called <literal>aopc</literal> such that
- you won't need the XML file during load time. JBoss Aop provides a so-called
- <literal>pointcut</literal> language where it consists of a regular
- expression set to specify the interception points (or
- <literal>jointpoint</literal> in aop parlance). The jointpoint can be
- constructor, method call, or field. You will need to declare any of your
- POJO to be "prepared" so that AOP framework knows to start intercepting
- either method, field, or constructor invocations using the dynamic Aop.
- </para> <para> For PojoCache, we only allow all the fields (both read and
- write) to be intercepted. That is, we don't care for the method level
- interception since it is the state that we are interested in. So you should
- only need to change your POJO class name. For details of the pointcut
- language, please refer to JBoss Aop. </para> <para> The standalone
- <literal>JBoss Cache</literal> distribution package provides an example
- declaration for the tutorial classes, namely, <literal>Person</literal> and
- <literal>Address</literal> . Detailed class declaration for
- <literal>Person</literal> and <literal>Address</literal> are provided in the
- Appendix section. But here is the snippet for
- <literal>pojocache-aop.xml</literal> : </para> <programlisting>
- <aop> <prepare expr="field(*
- $instanceof{(a)org.jboss.cache.pojo.annotation.Replicable}->*)"
- /> </aop>
- </programlisting> and then notice the annotation @Replicable used in the
- <literal>Person</literal> and <literal>Address</literal> POJOs. Also note
- that @Replicable is now inheritant. For example, sub-class of
- <literal>Person</literal> such as <literal>Student</literal> will also be
- aspectized by JBoss Aop as well. If you want to stop this inheritance
- behavior, you can simply remove the <literal>$instanceof</literal>
- declaration in the prepare statement, e.g., <programlisting>
- <aop> <prepare expr="field(*
- @org.jboss.cache.pojo.annotation.Replicable->*)" />
- </aop>
- </programlisting> <para> Detailed semantics of
- <literal>pojocache-aop.xml</literal> (or equivalently
- <literal>pojocache-aop.xml</literal> ) can again be found in JBoss Aop. But
- above statements basically declare all field read and write operations in
- classes <code>Address</code> and <code>Person</code> will be "prepared" (or
- "aspectized"). Note that: </para> <itemizedlist>
- <listitem>The wildcard at the end of the expression signifies all fields
- in the POJO</listitem>
+ <orderedlist>
+ <listitem>
+ <para>The <literal>aoppath</literal> option must point to the location
+ of pojocache-aop.xml</para>
+ </listitem>
- <listitem>You can potentially replace specific class name with wildcard
- that includes all the POJOs inside the same package space</listitem>
+ <listitem>
+ <para>The <literal>src</literal> option must point to the location of
+ your class files that are to be instrumented. This is typically the
+ output folder of a <literal>javac</literal> run.</para>
+ </listitem>
+ </orderedlist>
- <listitem>The <code>instanceof</code> operator declares any sub-type or
- sub-class of the specific POJO will also be "aspectized". For example,
- if a <code>Student</code> class is a subclass of <code>Person</code> ,
- JBossAop will automatically instrument it as well!</listitem>
+ <para>The following is an example ant task which performs compile-time
+ instrumentation:</para>
- <listitem>We intercept the field of all access levels (i.e.,
- <literal>private</literal> , <literal>protected</literal> ,
- <literal>public</literal> , etc.) The main reason being that we consider
- all fields as stateful data. However, we can relax this requirement in
- the future if there is a use case for it.</listitem>
+ <para><programlisting><taskdef name="aopc" classname="org.jboss.aop.ant.AopC" classpathref="aop.classpath"/>
+<target name="aopc" depends="compile" description="Precompile aop class">
+ <aopc compilerclasspathref="aop.classpath" verbose="true">
+ <src path="${build}"/>
+ <include name="org/jboss/cache/aop/test/**/*.class"/>
+ <aoppath path="${output}/resources/pojocache-aop.xml"/>
+ <classpath path="${build}"/>
+ <classpath refid="lib.classpath"/>
+ </aopc>
+</target> </programlisting>In this example, once the aopc target
+ is executeed the clasess in the build directory are modified. They can
+ then be packaged in a jar and loaded using the normal Java
+ mechanisms.</para>
+ </sect1>
- <listitem>We don't intercept field modifiers of <literal>final</literal>
- and <literal>transient</literal> though. That is, field with these
- modifiers are not stored in cache and is not replicated either. If you
- don't want your field to be managed by the cache, you can declare them
- with these modifiers, e.g., transient.</listitem>
- </itemizedlist></sect1>
+ <sect1>
+ <title>Understanding the provided AOP descriptor</title>
+ <para>The advanced user might decide to alter the provided AOP descritor.
+ In order to do this, it is important to understand the reaons behind what
+ is provided, and what is required by POJO Cache. Previous sections have
+ mentioned that any class with the <literal>@Replicable</literal>
+ annotation will be instrumented. This happens, because the provided AOP
+ descriptor, <literal>pojocache-aop.xml</literal>, has a perpare statement
+ which matches any class (or subclass) using the annotation. This is shown
+ in the following snippet:</para>
+
+ <programlisting><prepare expr="field(* $instanceof{(a)org.jboss.cache.pojo.annotation.Replicable}->*)"/> </programlisting>
+
+ <para>More specifically, any code which accesses a field on a class which
+ has been annotated with <literal>@Replicable</literal>, will be
+ instrumented: The "field" pointcut in the expression matches both read and
+ write operations. The wildcard "*" indicates that all java protection
+ modes are intercepted (private, package, protected, public). The
+ <literal>$instanceof</literal> expression refers to any annotation that
+ subclasses <literal>@Replicable</literal>. Finally, the ending wildcard
+ allows the matched field to have any name.</para>
+ </sect1>
+
<sect1>
<title>Annotation</title>
@@ -145,27 +133,51 @@
declaration since there will be no need for external metadata xml
descriptor.</para>
- <sect2><title>POJO annotation for instrumentation</title> <para> To
- support annotation (in order to simplify user's development effort), the
- JBoss Cache distribution ships with a <literal>pojocache-aop.xml</literal>
- under the <literal>resources</literal> directory. For reference, here is
- annotation definition from <literal>pojocache-aop.xml</literal> again :
- <programlisting>
+ <sect2>
+
+
+ <title>POJO annotation for instrumentation</title>
+
+
+
+ <para>To support annotation (in order to simplify user's development
+ effort), the JBoss Cache distribution ships with a
+ <literal>pojocache-aop.xml</literal> under the
+ <literal>resources</literal> directory. For reference, here is
+ annotation definition from <literal>pojocache-aop.xml</literal> again :
+ <programlisting>
<aop> <prepare expr="field(*
@org.jboss.cache.pojo.annotation.Replicable->*)"
/> </aop>
</programlisting> Basically, it simply states that any annotation
- with both marker interfaces will be "aspectized" accordingly. </para>
- <para> Here is a code snippet that illustrate the declaration: </para>
- <programlisting>
+ with both marker interfaces will be "aspectized" accordingly.</para>
+
+
+
+ <para>Here is a code snippet that illustrate the declaration:</para>
+
+
+
+ <programlisting>
@org.jboss.cache.pojo.annotation.Replicable public class
Person {...}
- </programlisting> The above declaration will instrument the class
- <literal>Person</literal> and all of its sub-classes. That is, if
- <literal>Student</literal> sub-class from <literal>Personal</literal> ,
- then it will get instrumented automatically without further annotation
- declaration.</sect2>
+ </programlisting>
+ The above declaration will instrument the class
+
+ <literal>Person</literal>
+
+ and all of its sub-classes. That is, if
+
+ <literal>Student</literal>
+
+ sub-class from
+
+ <literal>Personal</literal>
+
+ , then it will get instrumented automatically without further annotation declaration.
+ </sect2>
+
<sect2>
<title>JDK5.0 field level annotations</title>
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java 2008-01-16 22:15:37 UTC (rev 5150)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCache.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -241,6 +241,14 @@
* @param listener the listener to remove
*/
void removeListener(Object listener);
+
+ /**
+ * Get's the thread context for all POJO Cache operations.
+ *
+ * @return the current thread's context
+ * @since 2.1
+ */
+ PojoCacheThreadContext getThreadContext();
/**
* Obtain the underlying generic cache system. Use this for non-POJO cache operation, e.g.
Copied: pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java (from rev 5149, pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java)
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java (rev 0)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.cache.pojo;
+
+
+/**
+ * Represents the thread specific context for POJO Cache operations against a particular cache instance. This is
+ * primarily used to change thread specific options. Once set, they remain for the entire lifetime of the thread.
+ *
+ * Instances of this class can only be obtained by {@link PojoCache#getThreadContext}
+ *
+ * @author Jason T. Greene
+ * @since 2.1
+ */
+public interface PojoCacheThreadContext
+{
+ /**
+ * Returns whether or not this thread should trigger gravitation when a cache-miss occurs. The default is false.
+ *
+ * @return true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public boolean isGravitationEnabled();
+
+ /**
+ * Enables or disables gravitation on cache-miss
+ *
+ * @param gravitate true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public void setGravitationEnabled(boolean gravitate);
+}
\ No newline at end of file
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-01-16 22:15:37 UTC (rev 5150)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -13,6 +13,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.util.ObjectUtil;
@@ -26,11 +27,13 @@
{
private static Log log = LogFactory.getLog(InternalHelper.class.getName());
- private Cache cache;
+ private Cache<Object, Object> cache;
+ private PojoCache pcache;
- InternalHelper(Cache cache)
+ InternalHelper(PojoCache pcache)
{
- this.cache = cache;
+ this.cache = pcache.getCache();
+ this.pcache = pcache;
}
PojoInstance getPojoInstance(Fqn fqn) throws CacheException
@@ -86,7 +89,8 @@
private Object get(Fqn fqn, Object key, boolean gravitate) throws CacheException
{
- if (gravitate)
+ // Only gravitate when we have to and only when the user has enabled it
+ if (gravitate && pcache.getThreadContext().isGravitationEnabled())
{
cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
Object obj = cache.get(fqn, key);
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-01-16 22:15:37 UTC (rev 5150)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -58,7 +58,7 @@
{
pojoCache = cache;
this.cache = pojoCache.getCache();
- internal_ = new InternalHelper(this.cache);
+ internal_ = new InternalHelper(cache);
graphHandler_ = new ObjectGraphHandler(pojoCache, internal_);
collectionHandler_ = new CollectionClassHandler(pojoCache, internal_);
serializableHandler_ = new SerializableObjectHandler(pojoCache, internal_);
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 22:15:37 UTC (rev 5150)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -24,6 +24,7 @@
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.PojoCacheThreadContext;
import org.jboss.cache.pojo.annotation.Attach;
import org.jboss.cache.pojo.annotation.Detach;
import org.jboss.cache.pojo.annotation.Find;
@@ -44,6 +45,7 @@
private Map cachedTypes_ = new WeakHashMap();
private boolean hasCreate_ = false;
private CacheListenerAdaptor listenerAdaptor = new CacheListenerAdaptor(this);
+ private PojoCacheThreadContext threadContext = new PojoCacheThreadContextImpl();
public PojoCacheImpl(String configStr, boolean toStart)
{
@@ -319,6 +321,11 @@
cache.removeCacheListener(listenerAdaptor);
}
}
+
+ public PojoCacheThreadContext getThreadContext()
+ {
+ return threadContext;
+ }
public Cache<Object,Object> getCache()
{
Copied: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java (from rev 5149, pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java)
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java (rev 0)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -0,0 +1,46 @@
+package org.jboss.cache.pojo.impl;
+
+import org.jboss.cache.pojo.PojoCacheThreadContext;
+
+public class PojoCacheThreadContextImpl implements PojoCacheThreadContext
+{
+ private static final int GRAVITATE = 0;
+ private static final Boolean GRAVITATE_DEFAULT = false;
+
+ // Every cache instance gets it's own configuration
+ // An array is used to conserve memory usage since reclamation is slow with TLs, and prevent CL leaks
+ // In the future, if we get multiple booleans, use bitwise operations on an integer
+ // as the first entry
+ private final ThreadLocal<Object[]> state = new ThreadLocal<Object[]>()
+ {
+ @Override
+ protected Object[] initialValue()
+ {
+ return new Object[] {GRAVITATE_DEFAULT};
+ }
+ };
+
+ PojoCacheThreadContextImpl()
+ {
+ }
+
+ /**
+ * Returns whether or not this thread should trigger gravitation when a cache-miss occurs. The default is false.
+ *
+ * @return true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public boolean isGravitationEnabled()
+ {
+ return (Boolean) state.get()[GRAVITATE];
+ }
+
+ /**
+ * Enables or disables gravitation on cache-miss
+ *
+ * @param gravitate true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public void setGravitationEnabled(boolean gravitate)
+ {
+ state.get()[GRAVITATE] = gravitate;
+ }
+}
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-01-16 22:15:37 UTC (rev 5150)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -65,6 +65,10 @@
addBuddyReplication(cfg2);
cache1 = PojoCacheFactory.createCache(cfg2, toStart);
cache1.start();
+
+ // Enable gravitation
+ cache.getThreadContext().setGravitationEnabled(true);
+ cache1.getThreadContext().setGravitationEnabled(true);
}
@AfterMethod(alwaysRun = true)
Copied: pojo/trunk/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java (from rev 5149, pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java)
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java (rev 0)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java 2008-01-16 22:17:11 UTC (rev 5151)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * A BuddyReplicatedTest.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 4717 $
+ */
+@Test(groups = {"functional"})
+public class PojoCacheThreadContextTest
+{
+ Log log = LogFactory.getLog(ReplicatedTest.class);
+ volatile PojoCache cache, cache1;
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ boolean toStart = false;
+ Configuration cfg1 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL);
+ cache = PojoCacheFactory.createCache(cfg1, toStart);
+ cache.start();
+ Configuration cfg2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL);
+ cache1 = PojoCacheFactory.createCache(cfg2, toStart);
+ cache1.start();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ cache1.stop();
+ }
+
+ public void testDefault()
+ {
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), false);
+ }
+
+ private class TestThread extends Thread
+ {
+ public volatile Throwable t;
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ cache1.getThreadContext().setGravitationEnabled(true);
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+
+ cache.getThreadContext().setGravitationEnabled(true);
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), true);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+ }
+ catch (Throwable t)
+ {
+ this.t = t;
+ }
+ }
+ };
+
+ public void testThreadIsolation() throws Throwable
+ {
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), false);
+
+
+ TestThread t1 = new TestThread();
+ t1.start();
+ t1.join();
+ if (t1.t != null)
+ throw t1.t;
+
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), false);
+
+ cache1.getThreadContext().setGravitationEnabled(true);
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+ t1 = new TestThread();
+ t1.start();
+ t1.join();
+ if (t1.t != null)
+ throw t1.t;
+
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+ }
+}
16 years, 12 months
JBoss Cache SVN: r5150 - pojo/branches/2.1/src/main/java/org/jboss/cache/pojo.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:15:37 -0500 (Wed, 16 Jan 2008)
New Revision: 5150
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java
Log:
Add @since
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java 2008-01-16 22:13:38 UTC (rev 5149)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java 2008-01-16 22:15:37 UTC (rev 5150)
@@ -246,6 +246,7 @@
* Get's the thread context for all POJO Cache operations.
*
* @return the current thread's context
+ * @since 2.1
*/
PojoCacheThreadContext getThreadContext();
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java 2008-01-16 22:13:38 UTC (rev 5149)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java 2008-01-16 22:15:37 UTC (rev 5150)
@@ -30,6 +30,7 @@
* Instances of this class can only be obtained by {@link PojoCache#getThreadContext}
*
* @author Jason T. Greene
+ * @since 2.1
*/
public interface PojoCacheThreadContext
{
16 years, 12 months
JBoss Cache SVN: r5149 - in pojo/branches/2.1/src: main/java/org/jboss/cache/pojo/impl and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-01-16 17:13:38 -0500 (Wed, 16 Jan 2008)
New Revision: 5149
Added:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java
Modified:
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
Log:
Implement PCACHE-59
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java 2008-01-16 20:52:01 UTC (rev 5148)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCache.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -241,6 +241,13 @@
* @param listener the listener to remove
*/
void removeListener(Object listener);
+
+ /**
+ * Get's the thread context for all POJO Cache operations.
+ *
+ * @return the current thread's context
+ */
+ PojoCacheThreadContext getThreadContext();
/**
* Obtain the underlying generic cache system. Use this for non-POJO cache operation, e.g.
Added: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java (rev 0)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/PojoCacheThreadContext.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.cache.pojo;
+
+
+/**
+ * Represents the thread specific context for POJO Cache operations against a particular cache instance. This is
+ * primarily used to change thread specific options. Once set, they remain for the entire lifetime of the thread.
+ *
+ * Instances of this class can only be obtained by {@link PojoCache#getThreadContext}
+ *
+ * @author Jason T. Greene
+ */
+public interface PojoCacheThreadContext
+{
+ /**
+ * Returns whether or not this thread should trigger gravitation when a cache-miss occurs. The default is false.
+ *
+ * @return true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public boolean isGravitationEnabled();
+
+ /**
+ * Enables or disables gravitation on cache-miss
+ *
+ * @param gravitate true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public void setGravitationEnabled(boolean gravitate);
+}
\ No newline at end of file
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-01-16 20:52:01 UTC (rev 5148)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/InternalHelper.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -13,6 +13,7 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
import org.jboss.cache.pojo.util.ObjectUtil;
@@ -26,11 +27,13 @@
{
private static Log log = LogFactory.getLog(InternalHelper.class.getName());
- private Cache cache;
+ private Cache<Object, Object> cache;
+ private PojoCache pcache;
- InternalHelper(Cache cache)
+ InternalHelper(PojoCache pcache)
{
- this.cache = cache;
+ this.cache = pcache.getCache();
+ this.pcache = pcache;
}
PojoInstance getPojoInstance(Fqn fqn) throws CacheException
@@ -86,7 +89,8 @@
private Object get(Fqn fqn, Object key, boolean gravitate) throws CacheException
{
- if (gravitate)
+ // Only gravitate when we have to and only when the user has enabled it
+ if (gravitate && pcache.getThreadContext().isGravitationEnabled())
{
cache.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
Object obj = cache.get(fqn, key);
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-01-16 20:52:01 UTC (rev 5148)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -58,7 +58,7 @@
{
pojoCache = cache;
this.cache = pojoCache.getCache();
- internal_ = new InternalHelper(this.cache);
+ internal_ = new InternalHelper(cache);
graphHandler_ = new ObjectGraphHandler(pojoCache, internal_);
collectionHandler_ = new CollectionClassHandler(pojoCache, internal_);
serializableHandler_ = new SerializableObjectHandler(pojoCache, internal_);
Modified: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 20:52:01 UTC (rev 5148)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -24,6 +24,7 @@
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheException;
+import org.jboss.cache.pojo.PojoCacheThreadContext;
import org.jboss.cache.pojo.annotation.Attach;
import org.jboss.cache.pojo.annotation.Detach;
import org.jboss.cache.pojo.annotation.Find;
@@ -44,6 +45,7 @@
private Map cachedTypes_ = new WeakHashMap();
private boolean hasCreate_ = false;
private CacheListenerAdaptor listenerAdaptor = new CacheListenerAdaptor(this);
+ private PojoCacheThreadContext threadContext = new PojoCacheThreadContextImpl();
public PojoCacheImpl(String configStr, boolean toStart)
{
@@ -317,6 +319,11 @@
cache.removeCacheListener(listenerAdaptor);
}
}
+
+ public PojoCacheThreadContext getThreadContext()
+ {
+ return threadContext;
+ }
public Cache<Object,Object> getCache()
{
Added: pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java
===================================================================
--- pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java (rev 0)
+++ pojo/branches/2.1/src/main/java/org/jboss/cache/pojo/impl/PojoCacheThreadContextImpl.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -0,0 +1,46 @@
+package org.jboss.cache.pojo.impl;
+
+import org.jboss.cache.pojo.PojoCacheThreadContext;
+
+public class PojoCacheThreadContextImpl implements PojoCacheThreadContext
+{
+ private static final int GRAVITATE = 0;
+ private static final Boolean GRAVITATE_DEFAULT = false;
+
+ // Every cache instance gets it's own configuration
+ // An array is used to conserve memory usage since reclamation is slow with TLs, and prevent CL leaks
+ // In the future, if we get multiple booleans, use bitwise operations on an integer
+ // as the first entry
+ private final ThreadLocal<Object[]> state = new ThreadLocal<Object[]>()
+ {
+ @Override
+ protected Object[] initialValue()
+ {
+ return new Object[] {GRAVITATE_DEFAULT};
+ }
+ };
+
+ PojoCacheThreadContextImpl()
+ {
+ }
+
+ /**
+ * Returns whether or not this thread should trigger gravitation when a cache-miss occurs. The default is false.
+ *
+ * @return true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public boolean isGravitationEnabled()
+ {
+ return (Boolean) state.get()[GRAVITATE];
+ }
+
+ /**
+ * Enables or disables gravitation on cache-miss
+ *
+ * @param gravitate true if gravitation should be triggered on cache-miss, false if gravitation should not be triggered
+ */
+ public void setGravitationEnabled(boolean gravitate)
+ {
+ state.get()[GRAVITATE] = gravitate;
+ }
+}
Modified: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-01-16 20:52:01 UTC (rev 5148)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/BuddyReplicationTest.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -65,6 +65,10 @@
addBuddyReplication(cfg2);
cache1 = PojoCacheFactory.createCache(cfg2, toStart);
cache1.start();
+
+ // Enable gravitation
+ cache.getThreadContext().setGravitationEnabled(true);
+ cache1.getThreadContext().setGravitationEnabled(true);
}
@AfterMethod(alwaysRun = true)
Added: pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java
===================================================================
--- pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java (rev 0)
+++ pojo/branches/2.1/src/test/java/org/jboss/cache/pojo/PojoCacheThreadContextTest.java 2008-01-16 22:13:38 UTC (rev 5149)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.pojo;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocatorConfig;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.pojo.test.Person;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * A BuddyReplicatedTest.
+ *
+ * @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
+ * @version $Revision: 4717 $
+ */
+@Test(groups = {"functional"})
+public class PojoCacheThreadContextTest
+{
+ Log log = LogFactory.getLog(ReplicatedTest.class);
+ volatile PojoCache cache, cache1;
+
+ @BeforeMethod(alwaysRun = true)
+ protected void setUp() throws Exception
+ {
+ log.info("setUp() ....");
+ boolean toStart = false;
+ Configuration cfg1 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL);
+ cache = PojoCacheFactory.createCache(cfg1, toStart);
+ cache.start();
+ Configuration cfg2 = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL);
+ cache1 = PojoCacheFactory.createCache(cfg2, toStart);
+ cache1.start();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ protected void tearDown() throws Exception
+ {
+ cache.stop();
+ cache1.stop();
+ }
+
+ public void testDefault()
+ {
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), false);
+ }
+
+ private class TestThread extends Thread
+ {
+ public volatile Throwable t;
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ cache1.getThreadContext().setGravitationEnabled(true);
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+
+ cache.getThreadContext().setGravitationEnabled(true);
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), true);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+ }
+ catch (Throwable t)
+ {
+ this.t = t;
+ }
+ }
+ };
+
+ public void testThreadIsolation() throws Throwable
+ {
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), false);
+
+
+ TestThread t1 = new TestThread();
+ t1.start();
+ t1.join();
+ if (t1.t != null)
+ throw t1.t;
+
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), false);
+
+ cache1.getThreadContext().setGravitationEnabled(true);
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+ t1 = new TestThread();
+ t1.start();
+ t1.join();
+ if (t1.t != null)
+ throw t1.t;
+
+ assertEquals(cache.getThreadContext().isGravitationEnabled(), false);
+ assertEquals(cache1.getThreadContext().isGravitationEnabled(), true);
+ }
+}
16 years, 12 months