JBoss Cache SVN: r5955 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-04 13:10:42 -0400 (Wed, 04 Jun 2008)
New Revision: 5955
Modified:
core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
Log:
When a cache starts, childrenLoaded should be set to true on the root node
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-06-04 17:09:59 UTC (rev 5954)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainerImpl.java 2008-06-04 17:10:42 UTC (rev 5955)
@@ -84,6 +84,7 @@
if (trace) log.trace("Setting root node to an instance of " + tempRootType);
setRoot(tempRoot);
}
+ root.setChildrenLoaded(true);
}
@Stop(priority = 100)
16 years, 7 months
JBoss Cache SVN: r5954 - in core/trunk/src/main/java/org/jboss/cache: commands/remote and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-04 13:09:59 -0400 (Wed, 04 Jun 2008)
New Revision: 5954
Modified:
core/trunk/src/main/java/org/jboss/cache/DataContainer.java
core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java
Log:
Fixed typo and unnecessary toString noise
Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java 2008-06-04 17:07:48 UTC (rev 5953)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java 2008-06-04 17:09:59 UTC (rev 5954)
@@ -1,8 +1,8 @@
package org.jboss.cache;
+import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.marshall.NodeData;
import java.util.List;
import java.util.Set;
@@ -11,7 +11,7 @@
* This class defines the functionality needed for node manipulation.
*
* @author Mircea.Markus(a)jboss.com
- * @see org.jboss.cache.DataConatainerImpl
+ * @see DataContainerImpl
* @since 2.2
*/
public interface DataContainer
Modified: core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java 2008-06-04 17:07:48 UTC (rev 5953)
+++ core/trunk/src/main/java/org/jboss/cache/commands/remote/ClusteredGetCommand.java 2008-06-04 17:09:59 UTC (rev 5954)
@@ -172,8 +172,6 @@
return "ClusteredGetCommand{" +
"dataCommand=" + dataCommand +
", searchBackupSubtrees=" + searchBackupSubtrees +
- ", cacheData=" + dataContainer +
- ", interceptorChain=" + interceptorChain +
'}';
}
}
16 years, 7 months
JBoss Cache SVN: r5953 - in core/trunk/src/main/java/org/jboss/cache: loader and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-04 13:07:48 -0400 (Wed, 04 Jun 2008)
New Revision: 5953
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java
Log:
JBCACHE-1360: ClusteredCacheLoader.getChildrenNames() returns a null if it cannot connect to the cluster
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-06-04 17:05:59 UTC (rev 5952)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2008-06-04 17:07:48 UTC (rev 5953)
@@ -328,7 +328,17 @@
if (trace) log.trace("Children already loaded!");
return;
}
- Set childrenNames = loader.getChildrenNames(fqn);
+ Set childrenNames;
+ try
+ {
+ childrenNames = loader.getChildrenNames(fqn);
+ }
+ catch (Exception e)
+ {
+ if (log.isInfoEnabled()) log.info("Cache loader was unable to load state", e);
+ // return!
+ return;
+ }
if (trace)
{
Modified: core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java 2008-06-04 17:05:59 UTC (rev 5952)
+++ core/trunk/src/main/java/org/jboss/cache/loader/ClusteredCacheLoader.java 2008-06-04 17:07:48 UTC (rev 5953)
@@ -14,6 +14,7 @@
import org.jboss.cache.Modification;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.ReplicationException;
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.read.ExistsCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
@@ -122,7 +123,7 @@
{
if (log.isInfoEnabled())
log.info("No replies to call " + dataCommand + ". Perhaps we're alone in the cluster?");
- return null;
+ throw new ReplicationException("No replies to call " + dataCommand + ". Perhaps we're alone in the cluster?");
}
else
{
16 years, 7 months
JBoss Cache SVN: r5952 - benchmarks/benchmark-fwk/trunk.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-06-04 13:05:59 -0400 (Wed, 04 Jun 2008)
New Revision: 5952
Modified:
benchmarks/benchmark-fwk/trunk/bindAddress.sh
Log:
added some additional report processing stuff
Modified: benchmarks/benchmark-fwk/trunk/bindAddress.sh
===================================================================
--- benchmarks/benchmark-fwk/trunk/bindAddress.sh 2008-06-04 16:19:41 UTC (rev 5951)
+++ benchmarks/benchmark-fwk/trunk/bindAddress.sh 2008-06-04 17:05:59 UTC (rev 5952)
@@ -1,5 +1,5 @@
#!/bin/sh
### Set your bind address for the tests to use. Could be an IP, host name or a reference to an environment variable.
-BIND_ADDRESS=127.0.0.1
+BIND_ADDRESS=${MYTESTIP_2}
16 years, 7 months
JBoss Cache SVN: r5951 - in searchable/trunk/src: test/java and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-04 12:19:41 -0400 (Wed, 04 Jun 2008)
New Revision: 5951
Added:
searchable/trunk/src/test/java/TransformerTest.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Fixed up Transfomer methods and wrote Test for it. 3 Tests pass.
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04 15:47:45 UTC (rev 5950)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04 16:19:41 UTC (rev 5951)
@@ -13,7 +13,7 @@
{
public static String getKey(String docId)
{
- //Comes in the format "Fqn=[a/b/c]Key=[key]"
+ //docID comes in the format "Fqn=[/a/b/c]Key=[key]"
// This will be the index of the first time the sub-String "key=[" occurs within the whole String.
int startIndex = docId.indexOf("Key=[");
@@ -23,7 +23,7 @@
int endIndex = docId.indexOf("]", startIndex);
//Make the startIndex index point at the first char in the key sequence.
- startIndex += 1;
+ startIndex += 5;
//The resultant key that will be returned.
String key = docId.substring(startIndex, endIndex);
@@ -33,9 +33,12 @@
public static Fqn getFqn(String docId)
{
+ //docId comes in the format "Fqn=[/a/b/c]Key=[key]"
+
+
// This will be the index of the first time the sub-String "Fqn=[" occurs within the whole String.
//Adding 1 so that the index being pointed at will be the first character in the Fqn sequence.
- int startIndex = docId.indexOf("Fqn=[") + 1;
+ int startIndex = docId.indexOf("[") + 1;
//The endIndex of the Fqn sequence so that we know when to cut out the sub-String.
int endIndex = docId.indexOf("]");
Added: searchable/trunk/src/test/java/TransformerTest.java
===================================================================
--- searchable/trunk/src/test/java/TransformerTest.java (rev 0)
+++ searchable/trunk/src/test/java/TransformerTest.java 2008-06-04 16:19:41 UTC (rev 5951)
@@ -0,0 +1,53 @@
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.Transformer;
+import org.testng.annotations.Test;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 4, 2008
+ * Time: 3:52:58 PM
+ * To change this template use File | Settings | File Templates.
+ */
+
+@Test
+public class TransformerTest
+{
+ public void testGenerateId()
+ {
+
+ Fqn fqn = Fqn.fromString("/a/b/c");
+ String key = "key";
+
+ String generatedId = Transformer.generateId(fqn, key);
+
+ assert generatedId.contentEquals("Fqn=[/a/b/c]Key=[key]");
+
+ assert ! generatedId.contentEquals("/ab/c/d");
+ }
+
+ public void testGetFqn()
+ {
+ Fqn fqn = Transformer.getFqn("Fqn=[/cat/dog/person]Key=[key]");
+
+ Fqn expectedFqn = Fqn.fromString("/cat/dog/person");
+
+ assert fqn.equals(expectedFqn);
+
+ expectedFqn = Fqn.fromString("/dog/cat/person");
+
+ assert !fqn.equals(expectedFqn);
+
+ }
+
+ public void testGetKey()
+ {
+ String key = Transformer.getKey("Fqn=[/a/b/c]Key=[thisIsMyKey]");
+
+ assert key.contentEquals("thisIsMyKey");
+
+ assert ! key.contentEquals("thisIsNotMyKey");
+
+ }
+
+}
16 years, 7 months
JBoss Cache SVN: r5950 - core/trunk/src/test/java/org/jboss/cache/buddyreplication.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-04 11:47:45 -0400 (Wed, 04 Jun 2008)
New Revision: 5950
Modified:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java
Log:
Replaced lousy Thread.sleeps with proper interthread comms
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java 2008-06-04 14:32:05 UTC (rev 5949)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyAssignmentStateTransferTest.java 2008-06-04 15:47:45 UTC (rev 5950)
@@ -6,13 +6,18 @@
*/
package org.jboss.cache.buddyreplication;
+import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
-import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.notifications.annotation.BuddyGroupChanged;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.event.Event;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
import java.util.ArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
/**
* Tests how groups are formed and disbanded
@@ -30,6 +35,48 @@
return timeout;
}
+ @CacheListener
+ public static class BuddyJoinedListener
+ {
+ CountDownLatch latch;
+
+ public BuddyJoinedListener(CountDownLatch latch)
+ {
+ this.latch = latch;
+ }
+
+ @BuddyGroupChanged
+ public void buddyJoined(Event e)
+ {
+ latch.countDown();
+ }
+ }
+
+ private void createCacheWithLatch(CountDownLatch latch) throws Exception
+ {
+ CacheSPI<Object, Object> cache2 = createCache(1, "TEST", false, false);
+ cache2.create();
+ cache2.addCacheListener(new BuddyJoinedListener(latch));
+ cache2.start();
+ caches.add(cache2);
+ }
+
+ private void replaceLatch(Cache<?, ?> cache, CountDownLatch newLatch)
+ {
+ BuddyJoinedListener bjl = null;
+ for (Object listener : cache.getCacheListeners())
+ {
+ if (listener instanceof BuddyJoinedListener)
+ {
+ bjl = (BuddyJoinedListener) listener;
+ break;
+ }
+ }
+
+ if (bjl != null) cache.removeCacheListener(bjl);
+ cache.addCacheListener(new BuddyJoinedListener(newLatch));
+ }
+
public void testNonRegionBasedStateTransfer() throws Exception
{
caches = new ArrayList<CacheSPI<Object, Object>>();
@@ -38,27 +85,30 @@
Fqn<String> main = Fqn.fromString("/a/b/c");
caches.get(0).put(main, "name", "Joe");
- caches.add(createCache(1, "TEST", false, true));
+ CountDownLatch latch = new CountDownLatch(1);
+ createCacheWithLatch(latch);
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), VIEW_BLOCK_TIMEOUT);
- TestingUtil.sleepThread(getSleepTimeout());
+ assert latch.await(getSleepTimeout(), TimeUnit.MILLISECONDS) : "Buddy groups not formed after " + getSleepTimeout() + " millis!";
Fqn<String> test = BuddyFqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), main);
assertEquals("State not transferred", "Joe", caches.get(1).get(test, "name"));
- caches.add(createCache(1, "TEST", false, true));
+ latch = new CountDownLatch(1);
+ createCacheWithLatch(latch);
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), VIEW_BLOCK_TIMEOUT);
- TestingUtil.sleepThread(getSleepTimeout());
+ assert latch.await(getSleepTimeout(), TimeUnit.MILLISECONDS) : "Buddy groups not formed after " + getSleepTimeout() + " millis!";
assertNull("State not transferred", caches.get(2).get(test, "name"));
+ latch = new CountDownLatch(1);
+ replaceLatch(caches.get(2), latch);
+ replaceLatch(caches.get(0), latch);
// Make 2 the buddy of 0
caches.get(1).stop();
caches.set(1, null);
- TestingUtil.sleepThread(getSleepTimeout());
+ assert latch.await(getSleepTimeout(), TimeUnit.MILLISECONDS) : "Buddy groups not formed after " + getSleepTimeout() + " millis!";
assertEquals("State transferred", "Joe", caches.get(2).get(test, "name"));
}
@@ -67,6 +117,8 @@
{
caches = new ArrayList<CacheSPI<Object, Object>>();
+ CountDownLatch latch = new CountDownLatch(4);
+
caches.add(createCache(1, "TEST", false, false));
caches.add(createCache(1, "TEST", false, false));
caches.add(createCache(1, "TEST", false, false));
@@ -74,40 +126,31 @@
// caches[0] is not the backup node for caches[2] (although
// caches[2] *is* the backup node for caches[0]
caches.add(createCache(1, "TEST", false, false));
- caches.get(0).getConfiguration().setInactiveOnStartup(true);
- caches.get(1).getConfiguration().setInactiveOnStartup(true);
- caches.get(2).getConfiguration().setInactiveOnStartup(true);
- caches.get(3).getConfiguration().setInactiveOnStartup(true);
- caches.get(0).getConfiguration().setUseRegionBasedMarshalling(true);
- caches.get(1).getConfiguration().setUseRegionBasedMarshalling(true);
- caches.get(2).getConfiguration().setUseRegionBasedMarshalling(true);
- caches.get(3).getConfiguration().setUseRegionBasedMarshalling(true);
- caches.get(0).start();
- caches.get(1).start();
- caches.get(2).start();
- caches.get(3).start();
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), VIEW_BLOCK_TIMEOUT);
- TestingUtil.sleepThread(getSleepTimeout());
+ for (Cache c : caches)
+ {
+ c.getConfiguration().setInactiveOnStartup(true);
+ c.getConfiguration().setUseRegionBasedMarshalling(true);
+ c.create();
+ c.addCacheListener(new BuddyJoinedListener(latch));
+ }
+ for (Cache c : caches) c.start();
+
+ assert latch.await(getSleepTimeout(), TimeUnit.MILLISECONDS) : "Buddy groups not formed after " + getSleepTimeout() + " millis!";
+
Fqn fqnA = Fqn.fromString("/a");
Fqn fqnD = Fqn.fromString("/d");
// FIXME We have to use a hack to get JBC to recognize that our regions are for marshalling
ClassLoader cl = Fqn.class.getClassLoader();
- caches.get(0).getRegion(fqnA, true).registerContextClassLoader(cl);
- caches.get(1).getRegion(fqnA, true).registerContextClassLoader(cl);
- caches.get(2).getRegion(fqnA, true).registerContextClassLoader(cl);
- caches.get(3).getRegion(fqnA, true).registerContextClassLoader(cl);
- caches.get(0).getRegion(fqnD, true).registerContextClassLoader(cl);
- caches.get(1).getRegion(fqnD, true).registerContextClassLoader(cl);
- caches.get(2).getRegion(fqnD, true).registerContextClassLoader(cl);
- caches.get(3).getRegion(fqnD, true).registerContextClassLoader(cl);
+ for (Cache c : caches)
+ {
+ c.getRegion(fqnA, true).registerContextClassLoader(cl);
+ c.getRegion(fqnD, true).registerContextClassLoader(cl);
+ }
- caches.get(0).getRegion(fqnA, true).activate();
- caches.get(1).getRegion(fqnA, true).activate();
- caches.get(2).getRegion(fqnA, true).activate();
- caches.get(3).getRegion(fqnA, true).activate();
+ for (Cache c : caches) c.getRegion(fqnA, true).activate();
caches.get(0).getRegion(fqnD, true).activate();
caches.get(1).getRegion(fqnD, true).activate();
@@ -127,9 +170,12 @@
assertNull("No backup of /d", caches.get(2).get(testD, "name"));
// Make 2 the buddy of 0 -- this should cause a push from 0 to 2
+ latch = new CountDownLatch(1);
+ replaceLatch(caches.get(2), latch);
+ replaceLatch(caches.get(0), latch);
caches.get(1).stop();
- TestingUtil.sleepThread(getSleepTimeout());
+ assert latch.await(getSleepTimeout(), TimeUnit.MILLISECONDS) : "Buddy groups not formed after " + getSleepTimeout() + " millis!";
assertEquals("/a state transferred", "Joe", caches.get(2).get(testA, "name"));
assertNull("/d state not transferred", caches.get(2).get(testD, "name"));
@@ -145,22 +191,26 @@
public void testPersistentStateTransfer() throws Exception
{
caches = new ArrayList<CacheSPI<Object, Object>>();
+ CountDownLatch latch = new CountDownLatch(2);
caches.add(createCacheWithCacheLoader(false, false, false, true, false));
caches.get(0).getConfiguration().setFetchInMemoryState(false);
+ caches.get(0).create();
+ caches.get(0).addCacheListener(new BuddyJoinedListener(latch));
caches.get(0).start();
-
Fqn<String> main = Fqn.fromString("/a/b/c");
caches.get(0).put(main, "name", "Joe");
caches.add(createCacheWithCacheLoader(false, false, false, true, false));
caches.get(1).getConfiguration().setFetchInMemoryState(false);
+ caches.get(1).create();
+ caches.get(1).addCacheListener(new BuddyJoinedListener(latch));
+
caches.get(1).start();
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), VIEW_BLOCK_TIMEOUT);
- TestingUtil.sleepThread(getSleepTimeout());
+ assert latch.await(getSleepTimeout(), TimeUnit.MILLISECONDS) : "Buddy groups not formed after " + getSleepTimeout() + " millis!";
Fqn test = BuddyFqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(), main);
16 years, 7 months
JBoss Cache SVN: r5949 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-04 10:32:05 -0400 (Wed, 04 Jun 2008)
New Revision: 5949
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Finished 3 static methods.
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04 10:44:28 UTC (rev 5948)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04 14:32:05 UTC (rev 5949)
@@ -11,25 +11,52 @@
*/
public class Transformer
{
- public static Fqn getFqn(String docId)
+ public static String getKey(String docId)
{
- //TODO: Do the dirty work to convert a given document Id into an Fqn.
- return null;
+ //Comes in the format "Fqn=[a/b/c]Key=[key]"
+
+ // This will be the index of the first time the sub-String "key=[" occurs within the whole String.
+ int startIndex = docId.indexOf("Key=[");
+
+ //The index of the endIndex of the key sequence so we know when to cut out. The startIndex integer is also passed in so that
+ // there will not be an error later of endIndex < startIndex because this char occurs earlier when the Fqn is stated.
+ int endIndex = docId.indexOf("]", startIndex);
+
+ //Make the startIndex index point at the first char in the key sequence.
+ startIndex += 1;
+
+ //The resultant key that will be returned.
+ String key = docId.substring(startIndex, endIndex);
+
+ return key;
}
- public static String getKey(String docId)
+ public static Fqn getFqn(String docId)
{
- //TODO: Get the document Id to give back a string.
- return null;
+ // This will be the index of the first time the sub-String "Fqn=[" occurs within the whole String.
+ //Adding 1 so that the index being pointed at will be the first character in the Fqn sequence.
+ int startIndex = docId.indexOf("Fqn=[") + 1;
+
+ //The endIndex of the Fqn sequence so that we know when to cut out the sub-String.
+ int endIndex = docId.indexOf("]");
+
+ String fqnString = docId.substring(startIndex, endIndex);
+
+ Fqn fqn = Fqn.fromString(fqnString);
+ return fqn;
}
public static String generateId(Fqn fqn, String key)
{
- //TODO: Generate the Id from the given Fqn and key pairing to get a unique String.
+ StringBuilder sb = new StringBuilder();
+ sb.append("Fqn=[");
+ sb.append(fqn);
+ sb.append("]Key=[");
+ sb.append(key);
+ sb.append("]");
- String generatedId = "Fqn = " + fqn + "key = " + key;
+ return sb.toString();
- return generatedId;
}
//TODO: Look at HS documentation to see what can be done about non-String keys.
16 years, 7 months
JBoss Cache SVN: r5948 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-04 06:44:28 -0400 (Wed, 04 Jun 2008)
New Revision: 5948
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Wrote up generatedId method
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-03 19:19:03 UTC (rev 5947)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04 10:44:28 UTC (rev 5948)
@@ -26,9 +26,12 @@
public static String generateId(Fqn fqn, String key)
{
//TODO: Generate the Id from the given Fqn and key pairing to get a unique String.
- //TODO: Look at HS documentation to see what can be done about non-String keys.
- return null;
+
+ String generatedId = "Fqn = " + fqn + "key = " + key;
+
+ return generatedId;
}
+ //TODO: Look at HS documentation to see what can be done about non-String keys.
}
16 years, 7 months
JBoss Cache SVN: r5947 - in pojo/trunk: src/main/java/org/jboss/cache/pojo/collection and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-03 15:19:03 -0400 (Tue, 03 Jun 2008)
New Revision: 5947
Added:
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayInterceptable.java
Modified:
pojo/trunk/pom.xml
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayHandler.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/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml
pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/test/ArrayObject.java
Log:
Only use array interception handlers on types that can be intercepted
Allow array interception to be disabled
Add a multi-dim test
Update to use snapshot versions of projects (requires local building atm until a release)
Modified: pojo/trunk/pom.xml
===================================================================
--- pojo/trunk/pom.xml 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/pom.xml 2008-06-03 19:19:03 UTC (rev 5947)
@@ -6,7 +6,7 @@
<properties>
<jbosscache-pojo-version>2.2.0-SNAPSHOT</jbosscache-pojo-version>
<jbosscache-core-version>2.1.0-SNAPSHOT</jbosscache-core-version>
- <jboss.aop.version>2.0.0.CR3</jboss.aop.version>
+ <jboss.aop.version>2.0.0-SNAPSHOT</jboss.aop.version>
</properties>
<parent>
<groupId>org.jboss.cache</groupId>
@@ -125,7 +125,7 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jbossaop-plugin</artifactId>
- <version>2.0.0.beta1</version>
+ <version>1.0.0-SNAPSHOT</version>
<!-- HACK: AOP project and plugin has broken deps -->
<dependencies>
<dependency>
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -22,6 +22,7 @@
package org.jboss.cache.pojo.collection;
import org.jboss.cache.Fqn;
+import org.jboss.cache.pojo.impl.ArrayInterceptable;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.util.AopUtil;
import org.jboss.cache.pojo.util.Null;
@@ -34,31 +35,35 @@
*/
public class CachedObjectArray extends CachedArray
{
+ // Used to indicate that the source of the element is an interceptable array
+ // so that multi-dimensional arrays can be handled properly
+ private static ArrayInterceptable arraySource = new ArrayInterceptable() {};
+
protected CachedObjectArray(Fqn<?> fqn, Class<?> type, PojoCacheImpl cache)
{
super(fqn, type, cache);
}
-
+
public void set(int index, Object element)
{
Fqn<?> fqn = AopUtil.constructFqn(this.fqn, IntegerCache.toString(index));
- cache.attach(fqn, Null.toNullObject(element));
+ cache.attach(fqn, Null.toNullObject(element), null, arraySource);
}
-
+
public Object get(int index)
{
Fqn<?> fqn = AopUtil.constructFqn(this.fqn, IntegerCache.toString(index));
-
- return Null.toNullValue(cache.find(fqn));
+
+ return Null.toNullValue(cache.getObject(fqn, null, arraySource));
}
-
+
public void destroy()
{
// Detach all children to ensure reference cleanup
for (int i = 0; i < length(); i++)
- cache.detach(AopUtil.constructFqn(this.fqn, IntegerCache.toString(i)));
-
+ cache.detach(AopUtil.constructFqn(this.fqn, IntegerCache.toString(i)), null, arraySource);
+
super.destroy();
}
}
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/AdvisedPojoHandler.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -65,7 +65,7 @@
cache_ = pCache_.getCache();
util_ = util;
}
-
+
@Override
protected Fqn<?> getFqn(Object obj)
{
@@ -74,14 +74,14 @@
InstanceAdvisor advisor = ((Advised) obj)._getInstanceAdvisor();
if (advisor == null)
throw new PojoCacheException("_putObject(): InstanceAdvisor is null for: " + obj);
-
+
// Step Check for cross references
BaseInterceptor interceptor = AopUtil.findCacheInterceptor(advisor);
if (interceptor != null)
return interceptor.getFqn();
}
-
- return null;
+
+ return null;
}
@Override
@@ -89,21 +89,21 @@
{
CachedType type = pCache_.getCachedType(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());
-
+ result = pCache_.getObject(fqn, field.getName(), obj);
+
field.set(obj, result);
}
}
@@ -187,12 +187,12 @@
Field field = (Field) o;
Object value = subPojoMap.get(field);
if (value == null) continue; // really no need to map the POJO.
- pCache_.attach(fqn, value, field.getName());
+ pCache_.attach(fqn, value, field.getName(), obj);
// If it is Collection classes, we replace it with dynamic proxy.
// But we will have to ignore it if value is null
if (value instanceof Map || value instanceof List || value instanceof Set)
{
- Object newValue = pCache_.getObject(fqn, field.getName());
+ Object newValue = pCache_.getObject(fqn, field.getName(), obj);
util_.inMemorySubstitution(obj, field, newValue);
}
}
@@ -216,7 +216,7 @@
if (! CachedType.isSimpleAttribute(field))
{
- value = pCache_.detach(fqn, field.getName());
+ value = pCache_.detach(fqn, field.getName(), result);
// Check for Collection. If it is, we need to reset the original reference.
if ((value instanceof Map || value instanceof List || value instanceof Set))
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayHandler.java 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayHandler.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -33,19 +33,19 @@
public class ArrayHandler extends AbstractHandler
{
private final PojoCacheImpl cache;
-
+
ArrayHandler(PojoCacheImpl cache)
{
this.cache = cache;
}
-
+
protected Fqn<?> getFqn(Object array)
{
CachedArray cached = CachedArrayRegistry.lookup(array);
return cached != null ? cached.getFqn() : null;
}
-
-
+
+
protected void put(Fqn<?> fqn, Fqn<?> referencingFqn, Object obj)
{
// Always initialize the ref count so that we can mark this as an AopNode.
@@ -53,36 +53,35 @@
pojoInstance.set(obj);
pojoInstance.setPojoClass(obj.getClass());
cache.getCache().put(fqn, PojoInstance.KEY, pojoInstance);
-
+
CachedArray cached = CachedArray.create(fqn, cache, obj);
CachedArrayRegistry.register(obj, cached);
}
-
+
@Override
protected Object get(Fqn<?> fqn, Class<?> clazz, PojoInstance pojo)
{
CachedArray cached = CachedArray.load(fqn, cache, clazz);
Object array = cached.toArray();
CachedArrayRegistry.register(array, cached);
-
+
return array;
}
-
+
@Override
protected Object remove(Fqn<?> fqn, Fqn<?> referencingFqn, Object obj)
{
CachedArray cached = CachedArrayRegistry.unregister(obj);
if (cached != null)
cached.destroy();
-
+
return obj;
}
@Override
protected boolean handles(Class<?> clazz)
{
- return false;
- //return clazz.isArray();
+ return clazz.isArray();
}
}
Added: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayInterceptable.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayInterceptable.java (rev 0)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ArrayInterceptable.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -0,0 +1,33 @@
+/*
+* 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.impl;
+
+/**
+ * Internal interface that indicates that a type's fields
+ * can be included for array interception.
+ *
+ * @author Jason T. Greene
+ */
+public interface ArrayInterceptable
+{
+
+}
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-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -77,7 +77,7 @@
return bulkRemove_.get();
}
- public Object getObject(Fqn fqn, String field) throws CacheException
+ public Object getObject(Fqn fqn, String field, Object source) throws CacheException
{
// TODO Must we really to couple with BR? JBCACHE-669
Object pojo = internal_.getPojo(fqn, field);
@@ -101,7 +101,7 @@
if (region != null && region.getClassLoader() != null)
Thread.currentThread().setContextClassLoader(region.getClassLoader());
- return getObjectInternal(fqn, field);
+ return getObjectInternal(fqn, field, source);
}
finally
{
@@ -112,11 +112,12 @@
/**
* Note that caller of this method will take care of synchronization within the <code>fqn</code> sub-tree.
*/
- public Object putObject(Fqn fqn, Object obj, String field) throws CacheException
+ public Object putObject(Fqn fqn, Object obj, String field, Object source) throws CacheException
{
// Skip some un-necessary update if obj is the same class as the old one
Object oldValue = internal_.getPojo(fqn, field);
- if (oldValue == obj && skipDuplicateAttach(obj))
+ boolean allowArray = source instanceof ArrayInterceptable;
+ if (oldValue == obj && skipDuplicateAttach(obj, allowArray))
{
if (log.isDebugEnabled())
{
@@ -127,14 +128,14 @@
// remove old value before overwriting it. This is necessary to detach any interceptor.
// TODO Or can we simply walk thru that somewhere? Well, there is also implication of Collection though
- pojoCache.detach(fqn, field);
+ pojoCache.detach(fqn, field, source);
if (obj == null)
return oldValue;// we are done
- AbstractHandler handler = getHandler(obj.getClass());
+ AbstractHandler handler = getHandler(obj.getClass(), allowArray);
Fqn<?> internalFqn = handler.getFqn(obj);
-
+
if (internalFqn != null)
{
graphHandler_.put(internalFqn, fqn, obj);
@@ -142,44 +143,44 @@
else
{
internalFqn = createInternalFqn(fqn, obj);
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled())
log.debug("attach(): id: " + fqn + " will store the pojo in the internal area: " + internalFqn);
-
+
handler.put(internalFqn, fqn, obj);
// Used by notification sub-system
cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS, "ATTACHED");
}
-
+
setPojoReference(fqn, obj, field, internalFqn);
return oldValue;
}
-
- private boolean skipDuplicateAttach(Object obj)
+
+ private boolean skipDuplicateAttach(Object obj, boolean allowArray)
{
- return obj == null || getHandler(obj.getClass()) != serializableHandler_;
+ return obj == null || getHandler(obj.getClass(), allowArray) != serializableHandler_;
}
-
- private AbstractHandler getHandler(Class<?> clazz)
+
+ private AbstractHandler getHandler(Class<?> clazz, boolean allowArray)
{
if (advisedHandler_.handles(clazz))
return advisedHandler_;
-
+
if (collectionHandler_.handles(clazz))
return collectionHandler_;
-
- if (arrayHandler.handles(clazz))
+
+ if (allowArray && arrayHandler.handles(clazz))
return arrayHandler;
-
+
if (serializableHandler_.handles(clazz))
return serializableHandler_;
-
- throw new CacheException("Can not manage object. It must be either instrumented, a collection, an array, or Serializable: "
+
+ throw new CacheException("Can not manage object. It must be either instrumented, a collection, an array, or Serializable: "
+ clazz.getName());
}
-
+
private Fqn createInternalFqn(Fqn fqn, Object obj) throws CacheException
{
// Create an internal Fqn name
@@ -226,7 +227,7 @@
* @return detached object
* @throws CacheException
*/
- public Object removeObject(Fqn fqn, String field) throws CacheException
+ public Object removeObject(Fqn fqn, String field, Object source) throws CacheException
{
// the class attribute is implicitly stored as an immutable read-only attribute
PojoReference pojoReference = internal_.getPojoReference(fqn, field);
@@ -259,8 +260,8 @@
else
{
cache.put(internalFqn, InternalConstant.POJOCACHE_STATUS, "DETACHING");
-
- result = getHandler(result.getClass()).remove(internalFqn, fqn, result);
+ boolean allowArray = source instanceof ArrayInterceptable;
+ result = getHandler(result.getClass(), allowArray).remove(internalFqn, fqn, result);
}
internal_.cleanUp(fqn, field);
@@ -272,7 +273,7 @@
// Traverse from fqn to do getObject, if it return a pojo we then stop.
Map map = new HashMap();
- Object pojo = getObject(fqn, null);
+ Object pojo = getObject(fqn, null, null);
if (pojo != null)
{
map.put(fqn, pojo);// we are done!
@@ -287,7 +288,7 @@
return map;
}
- private Object getObjectInternal(Fqn<?> fqn, String field) throws CacheException
+ private Object getObjectInternal(Fqn<?> fqn, String field, Object source) throws CacheException
{
Fqn<?> internalFqn = fqn;
PojoReference pojoReference = internal_.getPojoReference(fqn, field);
@@ -315,7 +316,8 @@
//throw new PojoCacheException("PojoCacheDelegate.getObjectInternal(): null PojoInstance for fqn: " + internalFqn);
Class<?> clazz = pojoInstance.getPojoClass();
- obj = getHandler(clazz).get(internalFqn, clazz, pojoInstance);
+ boolean allowArray = source instanceof ArrayInterceptable;
+ obj = getHandler(clazz, allowArray).get(internalFqn, clazz, pojoInstance);
InternalHelper.setPojo(pojoInstance, obj);
return obj;
@@ -336,7 +338,7 @@
Fqn newFqn = n.getFqn();
if (InternalHelper.isInternalNode(newFqn)) continue;// skip
- Object pojo = getObject(newFqn, null);
+ Object pojo = getObject(newFqn, null, null);
if (pojo != null)
{
map.put(newFqn, pojo);
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-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheImpl.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -99,7 +99,7 @@
{
try
{
- Object obj = putObject(id, pojo, null);
+ Object obj = putObject(id, pojo, null, null);
return obj;
}
catch (CacheException e)
@@ -109,11 +109,11 @@
}
@Attach
- public Object attach(Fqn<?> id, Object pojo, String field) throws PojoCacheException
+ public Object attach(Fqn<?> id, Object pojo, String field, Object source) throws PojoCacheException
{
try
{
- Object obj = putObject(id, pojo, field);
+ Object obj = putObject(id, pojo, field, source);
return obj;
}
catch (CacheException e)
@@ -125,9 +125,9 @@
/**
* This public API is called from internal package only.
*/
- public Object putObject(Fqn<?> id, Object pojo, String field) throws CacheException
+ public Object putObject(Fqn<?> id, Object pojo, String field, Object source) throws CacheException
{
- return delegate_.putObject(id, pojo, field);
+ return delegate_.putObject(id, pojo, field, source);
}
public Object detach(String id) throws PojoCacheException
@@ -136,14 +136,14 @@
}
@Detach
- public Object detach(Fqn<?> id, String field) throws PojoCacheException
+ public Object detach(Fqn<?> id, String field, Object source) throws PojoCacheException
{
try
{
- Object pojo = getObject(id, field);// TODO need optimization here since it will be redundant here
+ Object pojo = getObject(id, field, source);// TODO need optimization here since it will be redundant here
if (pojo == null) return pojo;
- Object obj = removeObject(id, field);
+ Object obj = removeObject(id, field, source);
return obj;
}
catch (CacheException e)
@@ -154,13 +154,13 @@
public Object detach(Fqn<?> id) throws PojoCacheException
{
- return detach(id, null);
+ return detach(id, null, null);
}
- public Object removeObject(Fqn<?> id, String field) throws CacheException
+ public Object removeObject(Fqn<?> id, String field, Object source) throws CacheException
{
delegate_.setBulkRemove(false);
- return delegate_.removeObject(id, field);
+ return delegate_.removeObject(id, field, source);
}
public String getPojoID(Object pojo)
@@ -193,12 +193,12 @@
public Object getObject(Fqn<?> id) throws CacheException
{
- return getObject(id, null);
+ return getObject(id, null, null);
}
- public Object getObject(Fqn<?> id, String field) throws CacheException
+ public Object getObject(Fqn<?> id, String field, Object source) throws CacheException
{
- return delegate_.getObject(id, field);
+ return delegate_.getObject(id, field, source);
}
@@ -313,7 +313,7 @@
cache.removeCacheListener(listenerAdaptor);
}
}
-
+
public PojoCacheThreadContext getThreadContext()
{
return threadContext;
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/interceptors/dynamic/CacheFieldInterceptor.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -53,7 +53,7 @@
util_ = new PojoUtil();
}
- public CacheFieldInterceptor()
+ private CacheFieldInterceptor()
{
}
@@ -96,7 +96,7 @@
// Kind of ad hoc now. MethodInvocation should not invoke this.
if (invocation instanceof MethodInvocation)
return invocation.invokeNext();
-
+
if (invocation instanceof FieldWriteInvocation)
{
Object target = invocation.getTargetObject();
@@ -123,7 +123,7 @@
}
else
{
- pCache_.attach(fqn_, value, field.getName());
+ pCache_.attach(fqn_, value, field.getName(), target);
}
}
@@ -148,8 +148,8 @@
}
else
{
- result = pCache_.getObject(fqn_, field.getName());
-
+ result = pCache_.getObject(fqn_, field.getName(), target);
+
// Work around AOP issue with field reads
if (result != null && result.getClass().isArray())
registerArrayWithAOP(target, field.getName(), result);
@@ -172,13 +172,13 @@
return invocation.invokeNext();
}
- private void registerArrayWithAOP(Object owner, String fieldName, Object array)
+ private void registerArrayWithAOP(Object owner, String fieldName, Object array)
{
CachedArray cached = CachedArrayRegistry.lookup(array);
if (cached != null)
- ArrayRegistry.getInstance().addFieldReference(owner, fieldName, array);
+ ArrayRegistry.getInstance().addFieldReference(owner, fieldName, array);
}
-
+
/**
* Check if the pojo is detached already.
*/
Modified: pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml
===================================================================
--- pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/main/resources/META-INF/pojocache-aop.xml 2008-06-03 19:19:03 UTC (rev 5947)
@@ -145,13 +145,16 @@
<prepare expr="field(* $instanceof{(a)org.jboss.cache.pojo.annotation.Replicable}->*)" />
<!-- Work around that ensures annotated classes which do not access fields are instrumented -->
- <introduction expr="class($instanceof{(a)org.jboss.cache.pojo.annotation.Replicable})"/>
- <!-- Array support
+
+ <!-- Array support -->
+ <!-- Comment entire section to disable -->
<arrayreplacement expr="class($instanceof{(a)org.jboss.cache.pojo.annotation.Replicable})"/>
- <interceptor name="array" class="org.jboss.cache.pojo.interceptors.dynamic.ArrayInterceptor"/>
- <arraybind type="READ_WRITE">
- <interceptor-ref name="array"/>
+ <interceptor name="pojocache-array" class="org.jboss.cache.pojo.interceptors.dynamic.ArrayInterceptor"/>
+ <introduction expr="class($instanceof{(a)org.jboss.cache.pojo.annotation.Replicable})">
+ <interfaces>org.jboss.cache.pojo.impl.ArrayInterceptable</interfaces>
+ </introduction>
+ <arraybind name="pojocache-array" type="READ_WRITE">
+ <interceptor-ref name="pojocache-array"/>
</arraybind>
- -->
</aop>
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -37,7 +37,7 @@
* @author Ben Wang
*/
@Test(groups = {"functional"})
-public class ArrayTest
+public class ArrayTest
{
Log log = LogFactory.getLog(ArrayTest.class);
PojoCache cache1, cache2;
@@ -49,7 +49,7 @@
cache1 = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache1.getCache().addCacheListener(new MyCacheListener(false));
cache1.start();
-
+
cache2 = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache2.getCache().addCacheListener(new MyCacheListener(true));
cache2.start();
@@ -83,32 +83,66 @@
ao.setPerson(3, ben);
ao.setPerson(4, joe);
ao.setPerson(5, ben);
-
+
AssertJUnit.assertSame(ao.getPerson(1), ben);
AssertJUnit.assertSame(ao.getPerson(2), joe);
AssertJUnit.assertSame(ao.getPerson(3), ben);
AssertJUnit.assertSame(ao.getPerson(4), joe);
AssertJUnit.assertSame(ao.getPerson(5), ben);
-
+
ArrayObject obj = (ArrayObject) cache2.find("/ao");
Person person = obj.getPerson(4);
obj.setPerson(5, person);
AssertJUnit.assertSame(ao.getPerson(5), ao.getPerson(4));
-
+
ao.setNum(5, 4);
AssertJUnit.assertEquals(4, obj.getNum(5));
}
+ public void testMulti() throws Exception
+ {
+ log.info("testMulti() ....");
+ ArrayObject ao = new ArrayObject();
+ Person joe = new Person();
+ joe.setName("Joe");
+ joe.setAge(19);
+
+ Person ben = new Person();
+ ben.setName("Ben");
+ ben.setAge(19);
+
+ ao.setPerson(0, joe);
+
+ cache1.attach("/ao", ao);
+
+ ao.setMultiPerson(1, 2, 1, ben);
+ ao.setMultiPerson(2, 3, 2, joe);
+ ao.setMultiPerson(1, 2, 3, ben);
+ ao.setMultiPerson(2, 1, 4, joe);
+ ao.setMultiPerson(1, 1, 5, ben);
+
+ AssertJUnit.assertSame(ao.getMultiPerson(1, 2, 1), ben);
+ AssertJUnit.assertSame(ao.getMultiPerson(2, 3, 2), joe);
+ AssertJUnit.assertSame(ao.getMultiPerson(1, 2, 3), ben);
+ AssertJUnit.assertSame(ao.getMultiPerson(2, 1, 4), joe);
+ AssertJUnit.assertSame(ao.getMultiPerson(1, 1, 5), ben);
+
+ ArrayObject obj = (ArrayObject) cache2.find("/ao");
+ Person person = obj.getMultiPerson(2, 1, 4);
+ obj.setMultiPerson(1, 1, 5, person);
+ AssertJUnit.assertSame(ao.getMultiPerson(1, 1, 5), ao.getMultiPerson(2, 1, 4));
+ }
+
@CacheListener
public class MyCacheListener
{
private boolean visits;
-
+
public MyCacheListener(boolean visits)
{
this.visits = visits;
}
-
+
@NodeActivated
@NodePassivated
@NodeCreated
@@ -118,11 +152,11 @@
{
if (visits != ne instanceof NodeVisitedEvent)
return;
-
+
if (!ne.isPre())
System.out.println((!visits ? "[one] " : "[two] ") + ne.getType() + " " + ne.getFqn());
}
-
+
@NodeModified
public void print(NodeModifiedEvent ne)
{
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/test/ArrayObject.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/test/ArrayObject.java 2008-06-03 16:22:30 UTC (rev 5946)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/test/ArrayObject.java 2008-06-03 19:19:03 UTC (rev 5947)
@@ -41,11 +41,13 @@
}
}
private Person[] team;
+ private Person[][][] multiTeam;
private int[] nums;
public ArrayObject()
{
team = new Person[10];
+ multiTeam = new Person[5][5][6];
nums = new int[] {1,2,3,4,5,6,7,8,9};
}
@@ -58,16 +60,16 @@
{
team = t;
}
-
+
public void setNum(int index, int value)
{
int nums[] = this.nums;
nums[index] = value;
-
+
// This will be optimized away if array interception is enabled
this.nums = nums;
}
-
+
public int getNum(int index)
{
return nums[index];
@@ -75,18 +77,25 @@
public Person getPerson(int index)
{
- Object o = team[index];
- return (Person)o;
+ return team[index];
}
public void setPerson(int index, Person p)
{
Person[] array = team;
array[index] = p;
-
+
// This will be optimized away if array interception is enabled
team = array;
}
+
+ public Person getMultiPerson(int one, int two, int three) {
+ return multiTeam[one][two][three];
+ }
+
+ public void setMultiPerson(int one, int two, int three, Person person) {
+ multiTeam[one][two][three] = person;
+ }
}
16 years, 7 months