[infinispan-commits] Infinispan SVN: r863 - in trunk: core/src/main/java/org/infinispan/atomic and 3 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Sep 25 12:26:13 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-09-25 12:26:13 -0400 (Fri, 25 Sep 2009)
New Revision: 863

Added:
   trunk/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java
Removed:
   trunk/core/src/main/java/org/infinispan/atomic/AtomicMapCache.java
Modified:
   trunk/core/src/main/java/org/infinispan/CacheDelegate.java
   trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java
   trunk/core/src/test/java/org/infinispan/atomic/APITest.java
   trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java
   trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTestAssertions.java
   trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java
   trunk/tree/src/main/java/org/infinispan/tree/FqnComparator.java
   trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java
   trunk/tree/src/main/java/org/infinispan/tree/TreeCacheImpl.java
   trunk/tree/src/main/java/org/infinispan/tree/TreeStructureSupport.java
   trunk/tree/src/test/java/org/infinispan/api/tree/TreeCacheAPITest.java
Log:
Better generics for AtomicMap, and a better mechanism of construction and registration

Modified: trunk/core/src/main/java/org/infinispan/CacheDelegate.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/CacheDelegate.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/main/java/org/infinispan/CacheDelegate.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -21,9 +21,6 @@
  */
 package org.infinispan;
 
-import org.infinispan.atomic.AtomicHashMap;
-import org.infinispan.atomic.AtomicMap;
-import org.infinispan.atomic.AtomicMapCache;
 import org.infinispan.batch.BatchContainer;
 import org.infinispan.commands.CommandsFactory;
 import org.infinispan.commands.control.LockControlCommand;
@@ -82,7 +79,7 @@
  * @since 4.0
  */
 @NonVolatile
-public class CacheDelegate<K, V> implements AdvancedCache<K, V>, AtomicMapCache<K, V> {
+public class CacheDelegate<K, V> implements AdvancedCache<K, V> {
    protected InvocationContextContainer icc;
    protected CommandsFactory commandsFactory;
    protected InterceptorChain invoker;
@@ -517,13 +514,6 @@
       return "Cache '" + name + "'@" + (config.getCacheMode().isClustered() ? getCacheManager().getAddress() : System.identityHashCode(this));
    }
 
-   @SuppressWarnings("unchecked")
-   public <AMK, AMV> AtomicMap<AMK, AMV> getAtomicMap(K key) throws ClassCastException {
-      Object value = get(key);
-      if (value == null) value = AtomicHashMap.newInstance(this, key);
-      return ((AtomicHashMap) value).getProxy(this, key, batchContainer, icc);
-   }
-
    public BatchContainer getBatchContainer() {
       return batchContainer;
    }

Modified: trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -51,7 +51,7 @@
 public class AtomicHashMap<K, V> implements AtomicMap<K, V>, DeltaAware, Cloneable {
    FastCopyHashMap<K, V> delegate;
    private AtomicHashMapDelta delta = null;
-   private volatile AtomicHashMapProxy proxy;
+   private volatile AtomicHashMapProxy<K, V> proxy;
    volatile boolean copied = false;
 
    /**
@@ -137,14 +137,14 @@
       delegate.clear();
    }
 
-   public AtomicMap getProxy(Cache cache, Object mapKey,
+   public AtomicMap<K, V> getProxy(Cache cache, Object mapKey,
                              BatchContainer batchContainer, InvocationContextContainer icc) {
       // construct the proxy lazily
       if (proxy == null)  // DCL is OK here since proxy is volatile (and we live in a post-JDK 5 world)
       {
          synchronized (this) {
             if (proxy == null)
-               proxy = new AtomicHashMapProxy(cache, mapKey, batchContainer, icc);
+               proxy = new AtomicHashMapProxy<K, V>(cache, mapKey, batchContainer, icc);
          }
       }
       return proxy;

Deleted: trunk/core/src/main/java/org/infinispan/atomic/AtomicMapCache.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicMapCache.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicMapCache.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * 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.infinispan.atomic;
-
-import org.infinispan.Cache;
-
-/**
- * This interface adds the getAtomicMap() method which allows users to get a hold of a map type where operations on its
- * elements are all atomic.  Refer to the {@link AtomicMap} javadocs for more details.
- *
- * @author Manik Surtani (<a href="mailto:manik AT jboss DOT org">manik AT jboss DOT org</a>)
- * @see AtomicMap
- * @since 4.0
- */
-public interface AtomicMapCache<K> extends Cache<K, AtomicMap<?, ?>> {
-   /**
-    * Returns an atomic map.  The classes passed in are used to parameterize the Map returned.
-    *
-    * @param key          key under which to obtain and store this map in the cache
-    * @return a new or existing atomic map.  Never null.
-    * @throws ClassCastException if there already is a value stored under the given key and the type of value cannot be
-    *                            used as an AtomicMap.
-    */
-   <AMK, AMV> AtomicMap<AMK, AMV> getAtomicMap(K key) throws ClassCastException;
-}

Added: trunk/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java	                        (rev 0)
+++ trunk/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -0,0 +1,28 @@
+package org.infinispan.atomic;
+
+import org.infinispan.Cache;
+
+/**
+ * A helper that locates atomic maps within a given cache.  This should be the <b>only</b> way AtomicMaps are created/retrieved.
+ *
+ * @author Manik Surtani
+ * @since 4.0
+ */
+public class AtomicMapLookup {
+
+   /**
+    * Retrieves an atomic map from a given cache, stored under a given key.  If an AtomicMap did not exist, one is created
+    * and registered in an atomic fashion.
+    * @param cache underlying cache
+    * @param <K> key param of the AtomicMap
+    * @param <V> value param of the AtomicMap
+    * @return an AtomicMap
+    */
+   @SuppressWarnings("unchecked")
+   public static <MK, K, V> AtomicMap<K, V> getAtomicMap(Cache<?, ?> cache, MK key) {
+      Object value = cache.get(key);
+      if (value == null) value = AtomicHashMap.newInstance(cache, key);
+      AtomicHashMap<K, V> castValue = (AtomicHashMap<K, V>) value;
+      return castValue.getProxy(cache, key, cache.getAdvancedCache().getBatchContainer(), cache.getAdvancedCache().getInvocationContextContainer());
+   }
+}


Property changes on: trunk/core/src/main/java/org/infinispan/atomic/AtomicMapLookup.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: trunk/core/src/test/java/org/infinispan/atomic/APITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/APITest.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/test/java/org/infinispan/atomic/APITest.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -21,6 +21,7 @@
  */
 package org.infinispan.atomic;
 
+import org.infinispan.Cache;
 import static org.infinispan.atomic.AtomicHashMapTestAssertions.assertIsEmpty;
 import static org.infinispan.atomic.AtomicHashMapTestAssertions.assertIsEmptyMap;
 import org.infinispan.config.Configuration;
@@ -38,20 +39,20 @@
 @Test(groups = "functional", testName = "atomic.APITest")
 public class APITest {
 
-   AtomicMapCache cache;
+   Cache<String, Object> cache;
    TransactionManager tm;
 
    @BeforeTest
    private void setUp() {
       Configuration c = new Configuration();
       c.setInvocationBatchingEnabled(true);
-      cache = (AtomicMapCache) TestCacheManagerFactory.createCacheManager(c, true).getCache();
+      cache = TestCacheManagerFactory.createCacheManager(c, true).getCache();
       tm = TestingUtil.getTransactionManager(cache);
    }
 
    @AfterTest
    private void tearDown() {
-      cache.getCacheManager().stop();
+      TestingUtil.killCaches(cache);
    }
 
    @AfterMethod
@@ -68,7 +69,7 @@
    }
 
    public void testAtomicMap() {
-      AtomicMap map = cache.getAtomicMap("map");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map");
 
       assertIsEmpty(map);
       assertIsEmptyMap(cache, "map");
@@ -86,7 +87,7 @@
 
 
    public void testReadSafetyEmptyCache() throws Exception {
-      AtomicMap map = cache.getAtomicMap("map");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map");
 
       assertIsEmpty(map);
       assertIsEmptyMap(cache, "map");
@@ -115,7 +116,7 @@
    }
 
    public void testReadSafetyNotEmptyCache() throws Exception {
-      AtomicMap map = cache.getAtomicMap("map");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map");
 
       tm.begin();
       map.put("blah", "blah");
@@ -140,7 +141,7 @@
    }
 
    public void testReadSafetyRollback() throws Exception {
-      AtomicMap map = cache.getAtomicMap("map");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map");
 
       tm.begin();
       map.put("blah", "blah");

Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapConcurrencyTest.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -23,7 +23,7 @@
 public class AtomicHashMapConcurrencyTest {
 
    public static final String KEY = "key";
-   AtomicMapCache<String, String> cache;
+   Cache<String, Object> cache;
    TransactionManager tm;
 
    enum Operation {
@@ -40,8 +40,7 @@
       // these 2 need to be set to use the AtomicMapCache
       c.setInvocationBatchingEnabled(true);
       CacheManager cm = TestCacheManagerFactory.createCacheManager(c, true);
-      Cache basicCache = cm.getCache();
-      cache = (AtomicMapCache<String, String>) basicCache;
+      cache = cm.getCache();
       tm = TestingUtil.getTransactionManager(cache);
    }
 
@@ -55,7 +54,7 @@
 
    public void testConcurrentCreate() throws Exception {
       tm.begin();
-      cache.getAtomicMap(KEY);
+      AtomicMapLookup.getAtomicMap(cache, KEY);
       OtherThread ot = new OtherThread();
       ot.start();
       Object response = ot.response.take();
@@ -63,7 +62,7 @@
    }
 
    public void testConcurrentModifications() throws Exception {
-      AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY);
+      AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
       tm.begin();
       atomicMap.put(1, "");
       OtherThread ot = new OtherThread();
@@ -74,7 +73,7 @@
    }
 
    public void testReadAfterTxStarted() throws Exception {
-      AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY);
+      AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
       atomicMap.put(1, "existing");
       tm.begin();
       atomicMap.put(1, "newVal");
@@ -96,7 +95,7 @@
          super("OtherThread");
       }
 
-      BlockingQueue response = new ArrayBlockingQueue(1);
+      BlockingQueue<Object> response = new ArrayBlockingQueue<Object>(1);
 
       BlockingQueue<Operation> toExecute = new ArrayBlockingQueue<Operation>(1);
 
@@ -104,7 +103,7 @@
       public void run() {
          try {
             tm.begin();
-            AtomicMap<Integer, String> atomicMap = cache.getAtomicMap(KEY);
+            AtomicMap<Integer, String> atomicMap = AtomicMapLookup.getAtomicMap(cache, KEY);
             boolean notCommited = true;
             while (notCommited) {
                Operation op = toExecute.take();

Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTestAssertions.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTestAssertions.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicHashMapTestAssertions.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -1,5 +1,7 @@
 package org.infinispan.atomic;
 
+import org.infinispan.Cache;
+
 import java.util.Map;
 
 public class AtomicHashMapTestAssertions {
@@ -10,7 +12,7 @@
       assert !map.containsKey("blah");
    }
 
-   public static void assertIsEmptyMap(AtomicMapCache cache, Object key) {
-      assertIsEmpty(cache.getAtomicMap(key));
+   public static void assertIsEmptyMap(Cache<?, ?> cache, Object key) {
+      assertIsEmpty(AtomicMapLookup.getAtomicMap(cache, key));
    }
 }

Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -20,7 +20,7 @@
 @Test(groups = "functional", testName = "atomic.AtomicMapFunctionalTest")
 public class AtomicMapFunctionalTest {
    private static final Log log = LogFactory.getLog(AtomicMapFunctionalTest.class);
-   AtomicMapCache<String, String> cache;
+   Cache<String, Object> cache;
    TransactionManager tm;
 
    @BeforeMethod
@@ -30,8 +30,7 @@
       // these 2 need to be set to use the AtomicMapCache
       c.setInvocationBatchingEnabled(true);
       CacheManager cm = TestCacheManagerFactory.createCacheManager(c, true);
-      Cache basicCache = cm.getCache();
-      cache = (AtomicMapCache<String, String>) basicCache;
+      cache = cm.getCache();
       tm = TestingUtil.getTransactionManager(cache);
    }
 
@@ -41,34 +40,34 @@
    }
 
    public void testChangesOnAtomicMap() {
-      AtomicMap<String, String> map = cache.getAtomicMap("key");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key");
       assert map.isEmpty();
       map.put("a", "b");
       assert map.get("a").equals("b");
 
       // now re-retrieve the map and make sure we see the diffs
-      assert cache.getAtomicMap("key").get("a").equals("b");
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b");
    }
 
    public void testTxChangesOnAtomicMap() throws Exception {
-      AtomicMap<String, String> map = cache.getAtomicMap("key");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key");
       tm.begin();
       assert map.isEmpty();
       map.put("a", "b");
       assert map.get("a").equals("b");
       Transaction t = tm.suspend();
 
-      assert cache.getAtomicMap("key").get("a") == null;
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a") == null;
 
       tm.resume(t);
       tm.commit();
 
       // now re-retrieve the map and make sure we see the diffs
-      assert cache.getAtomicMap("key").get("a").equals("b");
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b");
    }
 
    public void testChangesOnAtomicMapNoLocks() {
-      AtomicMap<String, String> map = cache.getAtomicMap("key");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key");
       assert map.isEmpty();
       InvocationContextContainer icc = TestingUtil.extractComponent(cache, InvocationContextContainer.class);
       InvocationContext ic = icc.createInvocationContext();
@@ -80,11 +79,11 @@
       assert map.get("a").equals("b");
 
       // now re-retrieve the map and make sure we see the diffs
-      assert cache.getAtomicMap("key").get("a").equals("b");
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b");
    }
 
    public void testTxChangesOnAtomicMapNoLocks() throws Exception {
-      AtomicMap<String, String> map = cache.getAtomicMap("key");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key");
       tm.begin();
       assert map.isEmpty();
       TestingUtil.extractComponent(cache, InvocationContextContainer.class).createInvocationContext().setFlags(SKIP_LOCKING);
@@ -92,17 +91,17 @@
       assert map.get("a").equals("b");
       Transaction t = tm.suspend();
 
-      assert cache.getAtomicMap("key").get("a") == null;
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a") == null;
 
       tm.resume(t);
       tm.commit();
 
       // now re-retrieve the map and make sure we see the diffs
-      assert cache.getAtomicMap("key").get("a").equals("b");
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b");
    }
 
    public void testChangesOnAtomicMapNoLocksExistingData() {
-      AtomicMap<String, String> map = cache.getAtomicMap("key");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "key");
       assert map.isEmpty();
       map.put("x", "y");
       assert map.get("x").equals("y");
@@ -114,7 +113,7 @@
       assert map.get("x").equals("y");
 
       // now re-retrieve the map and make sure we see the diffs
-      assert cache.getAtomicMap("key").get("x").equals("y");
-      assert cache.getAtomicMap("key").get("a").equals("b");
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("x").equals("y");
+      assert AtomicMapLookup.getAtomicMap(cache, "key").get("a").equals("b");
    }
 }

Modified: trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -13,19 +13,19 @@
 
 @Test(groups = "functional", testName = "atomic.ClusteredAPITest")
 public class ClusteredAPITest extends MultipleCacheManagersTest {
-   AtomicMapCache cache1, cache2;
+   Cache<String, Object> cache1, cache2;
 
    protected void createCacheManagers() throws Throwable {
       Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC, true);
       c.setInvocationBatchingEnabled(true);
 
-      List<Cache<Object, Object>> caches = createClusteredCaches(2, "atomic", c);
-      cache1 = (AtomicMapCache) caches.get(0);
-      cache2 = (AtomicMapCache) caches.get(1);
+      List<Cache<String, Object>> caches = createClusteredCaches(2, "atomic", c);
+      cache1 = caches.get(0);
+      cache2 = caches.get(1);
    }
 
    public void testReplicationCommit() throws Exception {
-      AtomicMap map = cache1.getAtomicMap("map");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map");
 
       TestingUtil.getTransactionManager(cache1).begin();
       map.put("existing", "existing");
@@ -36,14 +36,14 @@
       assert map.get("blah").equals("blah");
       assert map.containsKey("blah");
 
-      assert cache2.getAtomicMap("map").size() == 2;
-      assert cache2.getAtomicMap("map").get("blah").equals("blah");
-      assert cache2.getAtomicMap("map").containsKey("blah");
+      assert AtomicMapLookup.getAtomicMap(cache2, "map").size() == 2;
+      assert AtomicMapLookup.getAtomicMap(cache2, "map").get("blah").equals("blah");
+      assert AtomicMapLookup.getAtomicMap(cache2, "map").containsKey("blah");
    }
 
    public void testReplicationRollback() throws Exception {
       assertIsEmptyMap(cache2, "map");
-      AtomicMap map = cache1.getAtomicMap("map");
+      AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map");
 
       TestingUtil.getTransactionManager(cache1).begin();
       map.put("existing", "existing");

Modified: trunk/tree/src/main/java/org/infinispan/tree/FqnComparator.java
===================================================================
--- trunk/tree/src/main/java/org/infinispan/tree/FqnComparator.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/tree/src/main/java/org/infinispan/tree/FqnComparator.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -93,6 +93,7 @@
     * Compares two Fqn elements. If e1 and e2 are the same class and e1 implements Comparable, returns e1.compareTo(e2).
     * Otherwise, returns e1.toString().compareTo(e2.toString()).
     */
+   @SuppressWarnings("unchecked")
    private int compareElements(Object e1, Object e2) {
       if (e1.getClass() == e2.getClass() && e1 instanceof Comparable) {
          return ((Comparable<Object>) e1).compareTo(e2);

Modified: trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java
===================================================================
--- trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/tree/src/main/java/org/infinispan/tree/NodeImpl.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -46,7 +46,7 @@
    Fqn fqn;
    NodeKey dataKey, structureKey;
 
-   public NodeImpl(Fqn fqn, Cache cache, BatchContainer batchContainer, InvocationContextContainer icc) {
+   public NodeImpl(Fqn fqn, Cache<?, ?> cache, BatchContainer batchContainer, InvocationContextContainer icc) {
       super(cache, batchContainer, icc);
       this.fqn = fqn;
       dataKey = new NodeKey(fqn, NodeKey.Type.DATA);
@@ -253,7 +253,7 @@
    public V replace(K key, V value) {
       startAtomic();
       try {
-         AtomicMap<K, V> map = cache.getAtomicMap(dataKey);
+         AtomicMap<K, V> map = getAtomicMap(dataKey);
          if (map.containsKey(key))
             return map.put(key, value);
          else
@@ -410,12 +410,12 @@
 
    @SuppressWarnings("unchecked")
    AtomicMap<K, V> getDataInternal() {
-      return cache.getAtomicMap(dataKey);
+      return getAtomicMap(dataKey);
    }
 
    @SuppressWarnings("unchecked")
    AtomicMap<Object, Fqn> getStructure() {
-      return cache.getAtomicMap(structureKey);
+      return getAtomicMap(structureKey);
    }
 
    public boolean equals(Object o) {

Modified: trunk/tree/src/main/java/org/infinispan/tree/TreeCacheImpl.java
===================================================================
--- trunk/tree/src/main/java/org/infinispan/tree/TreeCacheImpl.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/tree/src/main/java/org/infinispan/tree/TreeCacheImpl.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -95,7 +95,7 @@
    public V remove(Fqn fqn, K key) {
       startAtomic();
       try {
-         AtomicMap<K, V> map = cache.getAtomicMap(new NodeKey(fqn, NodeKey.Type.DATA));
+         AtomicMap<K, V> map = getAtomicMap(new NodeKey(fqn, NodeKey.Type.DATA));
          return map == null ? null : map.remove(key);
       }
       finally {
@@ -174,7 +174,7 @@
    }
 
    public V get(Fqn fqn, K key) {
-      Map<K, V> m = cache.getAtomicMap(new NodeKey(fqn, NodeKey.Type.DATA));
+      Map<K, V> m = getAtomicMap(new NodeKey(fqn, NodeKey.Type.DATA));
       if (m == null) return null;
       return m.get(key);
    }
@@ -332,7 +332,7 @@
       startAtomic();
       try {
          createNodeInCache(fqn);
-         Map<K, V> m = cache.getAtomicMap(new NodeKey(fqn, NodeKey.Type.DATA));
+         Map<K, V> m = getAtomicMap(new NodeKey(fqn, NodeKey.Type.DATA));
          return m.put(key, value);
       }
       finally {

Modified: trunk/tree/src/main/java/org/infinispan/tree/TreeStructureSupport.java
===================================================================
--- trunk/tree/src/main/java/org/infinispan/tree/TreeStructureSupport.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/tree/src/main/java/org/infinispan/tree/TreeStructureSupport.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -23,7 +23,7 @@
 
 import org.infinispan.Cache;
 import org.infinispan.atomic.AtomicMap;
-import org.infinispan.atomic.AtomicMapCache;
+import org.infinispan.atomic.AtomicMapLookup;
 import org.infinispan.batch.AutoBatchSupport;
 import org.infinispan.batch.BatchContainer;
 import org.infinispan.context.Flag;
@@ -35,11 +35,12 @@
 public class TreeStructureSupport extends AutoBatchSupport {
    private static Log log = LogFactory.getLog(TreeStructureSupport.class);
 
-   AtomicMapCache<NodeKey> cache;
-   InvocationContextContainer icc;
+   protected final Cache<NodeKey, AtomicMap<?, ?>> cache;
+   protected final InvocationContextContainer icc;
 
+   @SuppressWarnings("unchecked")
    public TreeStructureSupport(Cache<?, ?> cache, BatchContainer batchContainer, InvocationContextContainer icc) {
-      this.cache = (AtomicMapCache<NodeKey>) cache;
+      this.cache = (Cache<NodeKey, AtomicMap<?, ?>>) cache;
       this.batchContainer = batchContainer;
       this.icc = icc;
    }
@@ -72,8 +73,8 @@
             icc.getInvocationContext().setFlags(Flag.SKIP_LOCKING);
             parentStructure.put(fqn.getLastElement(), fqn);
          }
-         cache.getAtomicMap(structureKey);
-         cache.getAtomicMap(dataKey);
+         getAtomicMap(structureKey);
+         getAtomicMap(dataKey);
          if (log.isTraceEnabled()) log.trace("Created node " + fqn);
          return true;
       }
@@ -83,7 +84,7 @@
    }
 
    AtomicMap<Object, Fqn> getStructure(Fqn fqn) {
-      return cache.getAtomicMap(new NodeKey(fqn, NodeKey.Type.STRUCTURE));
+      return getAtomicMap(new NodeKey(fqn, NodeKey.Type.STRUCTURE));
    }
 
    public static boolean isLocked(LockManager lockManager, Fqn fqn) {
@@ -119,4 +120,8 @@
          addChildren(child, depth + 1, sb, details);
       }
    }
+
+   protected final <K, V> AtomicMap<K, V> getAtomicMap(NodeKey key) {
+      return AtomicMapLookup.getAtomicMap(cache, key);
+   }
 }

Modified: trunk/tree/src/test/java/org/infinispan/api/tree/TreeCacheAPITest.java
===================================================================
--- trunk/tree/src/test/java/org/infinispan/api/tree/TreeCacheAPITest.java	2009-09-25 15:33:44 UTC (rev 862)
+++ trunk/tree/src/test/java/org/infinispan/api/tree/TreeCacheAPITest.java	2009-09-25 16:26:13 UTC (rev 863)
@@ -2,7 +2,7 @@
 
 import org.infinispan.Cache;
 import org.infinispan.atomic.AtomicMap;
-import org.infinispan.atomic.AtomicMapCache;
+import org.infinispan.atomic.AtomicMapLookup;
 import org.infinispan.config.Configuration;
 import org.infinispan.manager.CacheManager;
 import org.infinispan.test.TestingUtil;
@@ -112,7 +112,7 @@
 
    private void assertStructure(TreeCache tc, String fqnStr) {
       // make sure structure nodes are properly built and maintained
-      AtomicMapCache c = (AtomicMapCache) tc.getCache();
+      Cache c = tc.getCache();
       Fqn fqn = Fqn.fromString(fqnStr);
       // loop thru the Fqn, starting at its root, and make sure all of its children exist in proper NodeKeys
       for (int i = 0; i < fqn.size(); i++) {
@@ -121,7 +121,7 @@
          // make sure a data key exists in the cache
          assert c.containsKey(new NodeKey(parent, NodeKey.Type.DATA)) : "Node [" + parent + "] does not have a Data atomic map!";
          assert c.containsKey(new NodeKey(parent, NodeKey.Type.STRUCTURE)) : "Node [" + parent + "] does not have a Structure atomic map!";
-         AtomicMap am = c.getAtomicMap(new NodeKey(parent, NodeKey.Type.STRUCTURE));
+         AtomicMap<Object, Fqn> am = AtomicMapLookup.getAtomicMap(c, new NodeKey(parent, NodeKey.Type.STRUCTURE));
          boolean hasChild = am.containsKey(childName);
          assert hasChild : "Node [" + parent + "] does not have a child [" + childName + "] in its Structure atomic map!";
       }



More information about the infinispan-commits mailing list