[jboss-cvs] JBossAS SVN: r107224 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 29 23:57:08 EDT 2010


Author: pferraro
Date: 2010-07-29 23:57:08 -0400 (Thu, 29 Jul 2010)
New Revision: 107224

Modified:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java
Log:
Use AtomicMapFactory facade.

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java	2010-07-30 03:55:47 UTC (rev 107223)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java	2010-07-30 03:57:08 UTC (rev 107224)
@@ -21,7 +21,10 @@
  */
 package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
 
+import org.jboss.ha.ispn.CacheContainerRegistry;
 import org.jboss.ha.ispn.DefaultCacheContainerRegistry;
+import org.jboss.ha.ispn.atomic.AtomicMapFactory;
+import org.jboss.ha.ispn.atomic.DefaultAtomicMapFactory;
 import org.jboss.ha.ispn.invoker.CacheInvoker;
 import org.jboss.ha.ispn.invoker.RetryingCacheInvoker;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
@@ -35,9 +38,11 @@
  */
 public class DistributedCacheManagerFactoryImpl implements DistributedCacheManagerFactory
 {
+   private CacheContainerRegistry registry = DefaultCacheContainerRegistry.getInstance();
    private SessionAttributeStorageFactory storageFactory = new SessionAttributeStorageFactoryImpl();
    private SessionAttributeMarshallerFactory marshallerFactory = new SessionAttributeMarshallerFactoryImpl();
    private CacheInvoker invoker = new RetryingCacheInvoker(10, 100);
+   private AtomicMapFactory atomicMapFactory = new DefaultAtomicMapFactory();
    
    @Override
    public <T extends OutgoingDistributableSessionData> DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager)
@@ -45,9 +50,14 @@
       SessionAttributeMarshaller marshaller = this.marshallerFactory.createMarshaller(manager);
       SessionAttributeStorage<T> storage = this.storageFactory.createStorage(manager.getReplicationConfig().getReplicationGranularity(), marshaller);
       
-      return new DistributedCacheManagerImpl<T>(manager, DefaultCacheContainerRegistry.getInstance(), storage, this.invoker);
+      return new DistributedCacheManagerImpl<T>(manager, this.registry, storage, this.invoker, this.atomicMapFactory);
    }
    
+   public void setCacheContainerRegistry(CacheContainerRegistry registry)
+   {
+      this.registry = registry;
+   }
+   
    public void setSessionAttributeStorageFactory(SessionAttributeStorageFactory storageFactory)
    {
       this.storageFactory = storageFactory;
@@ -62,4 +72,9 @@
    {
       this.invoker = invoker;
    }
+   
+   public void setAtomicMapFactory(AtomicMapFactory atomicMapFactory)
+   {
+      this.atomicMapFactory = atomicMapFactory;
+   }
 }

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java	2010-07-30 03:55:47 UTC (rev 107223)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java	2010-07-30 03:57:08 UTC (rev 107224)
@@ -27,7 +27,6 @@
 import javax.transaction.TransactionManager;
 
 import org.infinispan.Cache;
-import org.infinispan.atomic.AtomicHashMap;
 import org.infinispan.atomic.AtomicMap;
 import org.infinispan.config.CacheLoaderManagerConfig;
 import org.infinispan.config.Configuration;
@@ -45,6 +44,7 @@
 import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
 import org.infinispan.transaction.tm.BatchModeTransactionManager;
 import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.ha.ispn.atomic.AtomicMapFactory;
 import org.jboss.ha.ispn.invoker.CacheInvoker;
 import org.jboss.logging.Logger;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
@@ -86,17 +86,19 @@
    private final SessionAttributeStorage<T> attributeStorage;
    private final CacheInvoker invoker;
    private final CacheContainerRegistry registry;
+   final AtomicMapFactory atomicMapFactory;
    
    private Cache<String, AtomicMap<Object, Object>> cache;
    private BatchingManager batchingManager;
    private boolean passivationEnabled = false;
    
-   public DistributedCacheManagerImpl(LocalDistributableSessionManager manager, CacheContainerRegistry registry, SessionAttributeStorage<T> attributeStorage, CacheInvoker invoker)
+   public DistributedCacheManagerImpl(LocalDistributableSessionManager manager, CacheContainerRegistry registry, SessionAttributeStorage<T> attributeStorage, CacheInvoker invoker, AtomicMapFactory atomicMapFactory)
    {
       this.manager = manager;
       this.registry = registry;
       this.attributeStorage = attributeStorage;
       this.invoker = invoker;
+      this.atomicMapFactory = atomicMapFactory;
    }
 
    /**
@@ -203,24 +205,22 @@
          log.trace("putSession(): putting session " + mask(sessionId));
       }     
       
-      final AtomicMap<Object, Object> data = new AtomicHashMap<Object, Object>();
-      
-      AtomicMapEntry.VERSION.put(data, Integer.valueOf(sessionData.getVersion()));
-      AtomicMapEntry.METADATA.put(data, sessionData.getMetadata());
-      AtomicMapEntry.TIMESTAMP.put(data, sessionData.getTimestamp());
-      
-      this.attributeStorage.store(data, sessionData);
-      
       Operation<AtomicMap<Object, Object>> operation = new Operation<AtomicMap<Object, Object>>()
       {
          @Override
          public AtomicMap<Object, Object> invoke(Cache<String, AtomicMap<Object, Object>> cache)
          {
-            return cache.put(sessionId, data);
+            return DistributedCacheManagerImpl.this.atomicMapFactory.getAtomicMap(cache, sessionId, true);
          }
       };
       
-      this.invoker.invoke(this.cache, operation);
+      AtomicMap<Object, Object> data = this.invoker.invoke(this.cache, operation);
+      
+      AtomicMapEntry.VERSION.put(data, Integer.valueOf(sessionData.getVersion()));
+      AtomicMapEntry.METADATA.put(data, sessionData.getMetadata());
+      AtomicMapEntry.TIMESTAMP.put(data, sessionData.getTimestamp());
+      
+      this.attributeStorage.store(data, sessionData);
    }
    
    /**
@@ -250,7 +250,7 @@
          @Override
          public AtomicMap<Object, Object> invoke(Cache<String, AtomicMap<Object, Object>> cache)
          {
-            return cache.get(sessionId);
+            return DistributedCacheManagerImpl.this.atomicMapFactory.getAtomicMap(cache, sessionId, false);
          }
       };
       

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java	2010-07-30 03:55:47 UTC (rev 107223)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java	2010-07-30 03:57:08 UTC (rev 107224)
@@ -40,6 +40,7 @@
 import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
 import org.infinispan.transaction.tm.BatchModeTransactionManager;
 import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.ha.ispn.atomic.AtomicMapFactory;
 import org.jboss.ha.ispn.invoker.CacheInvoker;
 import org.jboss.metadata.web.jboss.ReplicationConfig;
 import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
@@ -65,6 +66,7 @@
    @SuppressWarnings("unchecked")
    private final AdvancedCache<String, AtomicMap<Object, Object>> cache = EasyMock.createStrictMock(AdvancedCache.class);
    private final CacheInvoker invoker = EasyMock.createStrictMock(CacheInvoker.class);
+   private final AtomicMapFactory atomicMapFactory = EasyMock.createStrictMock(AtomicMapFactory.class);
    
    @Test
    public void start()
@@ -96,7 +98,7 @@
    
    private DistributedCacheManagerImpl<OutgoingDistributableSessionData> start(String containerName, String templateCacheName, String hostName, String contextName, String cacheName, ReplicationConfig config, ComponentStatus cacheStatus, boolean startCache, Configuration configuration)
    {
-      DistributedCacheManagerImpl<OutgoingDistributableSessionData> manager = new DistributedCacheManagerImpl<OutgoingDistributableSessionData>(this.manager, this.registry, this.storage, this.invoker);
+      DistributedCacheManagerImpl<OutgoingDistributableSessionData> manager = new DistributedCacheManagerImpl<OutgoingDistributableSessionData>(this.manager, this.registry, this.storage, this.invoker, this.atomicMapFactory);
       
       @SuppressWarnings("unchecked")
       Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
@@ -179,7 +181,8 @@
       OutgoingDistributableSessionData data = EasyMock.createNiceMock(OutgoingDistributableSessionData.class);
       
       DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
-      Capture<AtomicMap<Object, Object>> capturedMap = new Capture<AtomicMap<Object, Object>>();
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createNiceMock(AtomicMap.class);
       Capture<DistributedCacheManagerImpl.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<DistributedCacheManagerImpl.Operation<AtomicMap<Object, Object>>>();
       
       String sessionId = "abc";
@@ -187,46 +190,39 @@
       long timestamp = System.currentTimeMillis();
       DistributableSessionMetadata metadata = new DistributableSessionMetadata();
       
+      EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(map);
+
       EasyMock.expect(data.getRealId()).andReturn(sessionId);
       EasyMock.expect(data.getVersion()).andReturn(version);
+      EasyMock.expect(map.put(Byte.valueOf((byte) AtomicMapEntry.VERSION.ordinal()), version)).andReturn(null);
       EasyMock.expect(data.getTimestamp()).andReturn(timestamp);
+      EasyMock.expect(map.put(Byte.valueOf((byte) AtomicMapEntry.TIMESTAMP.ordinal()), timestamp)).andReturn(null);
       EasyMock.expect(data.getMetadata()).andReturn(metadata);
+      EasyMock.expect(map.put(Byte.valueOf((byte) AtomicMapEntry.METADATA.ordinal()), metadata)).andReturn(null);
       
-      this.storage.store(EasyMock.capture(capturedMap), EasyMock.same(data));
+      this.storage.store(EasyMock.same(map), EasyMock.same(data));
       
-      EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, data, map);
       
-      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, data);
-      
       manager.storeSessionData(data);
       
-      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, data, map);
+      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, data, map);
       
-      AtomicMap<Object, Object> map = capturedMap.getValue();
       
-      Assert.assertEquals(3, map.size());
-      Assert.assertEquals(version, map.get(Byte.valueOf((byte) AtomicMapEntry.VERSION.ordinal())));
-      Assert.assertEquals(timestamp, map.get(Byte.valueOf((byte) AtomicMapEntry.TIMESTAMP.ordinal())));
-      Assert.assertSame(metadata, map.get(Byte.valueOf((byte) AtomicMapEntry.METADATA.ordinal())));
-      
-      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, data);
-      
-      
       DistributedCacheManagerImpl.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
-      @SuppressWarnings("unchecked")
-      AtomicMap<Object, Object> oldMap = EasyMock.createMock(AtomicMap.class);
       
-      EasyMock.expect(this.cache.put(EasyMock.same(sessionId), EasyMock.same(map))).andReturn(oldMap);
+      EasyMock.expect(this.atomicMapFactory.getAtomicMap(EasyMock.same(cache), EasyMock.same(sessionId), EasyMock.eq(true))).andReturn(map);
+            
+      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, data);
       
-      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, data);
-      
       AtomicMap<Object, Object> result = operation.invoke(this.cache);
       
-      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, data);
       
-      Assert.assertSame(oldMap, result);
+      Assert.assertSame(map, result);
       
-      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, data);
    }
    
    @Test
@@ -263,11 +259,11 @@
          EasyMock.expect(this.storage.load(map)).andReturn(attributes);
       }
       
-      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, map);
+      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, map);
       
       IncomingDistributableSessionData result = manager.getSessionData(sessionId, null, includeAttributes);
       
-      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, map);
+      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, map);
       
       Assert.assertNotNull(result);
       Assert.assertEquals(version.intValue(), result.getVersion());
@@ -296,24 +292,24 @@
          Assert.assertNotNull(exception);
       }
       
-      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, map);
+      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, map);
       
       
       DistributedCacheManagerImpl.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
       @SuppressWarnings("unchecked")
       AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
       
-      EasyMock.expect(this.cache.get(EasyMock.same(sessionId))).andReturn(expectedMap);
+      EasyMock.expect(this.atomicMapFactory.getAtomicMap(EasyMock.same(cache), EasyMock.same(sessionId), EasyMock.eq(false))).andReturn(expectedMap);
       
-      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, expectedMap);
+      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, expectedMap);
       
       AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
       
-      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, expectedMap);
+      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, expectedMap);
       
       Assert.assertSame(expectedMap, resultMap);
       
-      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, expectedMap);
+      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory, expectedMap);
    }
    
    @Test
@@ -332,32 +328,32 @@
       
       EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
       
-      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory);
       
       IncomingDistributableSessionData result = manager.getSessionData("abc", null, includeAttributes);
       
-      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory);
       
       Assert.assertNull(result);
       
-      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory);
       
       
       DistributedCacheManagerImpl.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
       @SuppressWarnings("unchecked")
       AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
       
-      EasyMock.expect(this.cache.get("abc")).andReturn(expectedMap);
+      EasyMock.expect(this.atomicMapFactory.getAtomicMap(this.cache, "abc", false)).andReturn(expectedMap);
       
-      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+      EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory);
       
       AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
       
-      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+      EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory);
       
       Assert.assertSame(expectedMap, resultMap);
       
-      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+      EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, this.atomicMapFactory);
    }
    
    @Test



More information about the jboss-cvs-commits mailing list