[jboss-cvs] JBossAS SVN: r107415 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 4 21:51:33 EDT 2010
Author: pferraro
Date: 2010-08-04 21:51:32 -0400 (Wed, 04 Aug 2010)
New Revision: 107415
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
Log:
[JBAS-7842] Infinispan replication configuration via jboss-web.xml
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-08-05 01:36:23 UTC (rev 107414)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-08-05 01:51:32 UTC (rev 107415)
@@ -30,6 +30,7 @@
import org.infinispan.atomic.AtomicMap;
import org.infinispan.config.CacheLoaderManagerConfig;
import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
import org.infinispan.context.Flag;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.lifecycle.ComponentStatus;
@@ -47,6 +48,8 @@
import org.jboss.ha.ispn.atomic.AtomicMapFactory;
import org.jboss.ha.ispn.invoker.CacheInvoker;
import org.jboss.logging.Logger;
+import org.jboss.metadata.web.jboss.ReplicationConfig;
+import org.jboss.metadata.web.jboss.ReplicationMode;
import org.jboss.web.tomcat.service.session.distributedcache.impl.BatchingManagerImpl;
import org.jboss.web.tomcat.service.session.distributedcache.impl.IncomingDistributableSessionDataImpl;
import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
@@ -109,7 +112,8 @@
@Override
public void start()
{
- String templateCacheName = this.manager.getReplicationConfig().getCacheName();
+ ReplicationConfig replConfig = this.manager.getReplicationConfig();
+ String templateCacheName = replConfig.getCacheName();
String containerName = null;
@@ -133,10 +137,61 @@
String path = context.isEmpty() || context.equals("/") ? "ROOT" : context.startsWith("/") ? context.substring(1) : context;
String cacheName = host + "/" + path;
+
+ Cache<?, ?> templateCache = container.getCache();
+ Configuration configuration = templateCache.getConfiguration().clone();
- EmbeddedCacheManager manager = (EmbeddedCacheManager) container.getCache().getCacheManager();
- manager.defineConfiguration(cacheName, templateCacheName, new Configuration());
+ Integer backups = replConfig.getBackups();
+ ReplicationMode replMode = replConfig.getReplicationMode();
+ CacheMode mode = configuration.getCacheMode();
+
+ if (backups != null)
+ {
+ int value = backups.intValue();
+
+ configuration.setNumOwners(value);
+
+ if (value == 0)
+ {
+ mode = CacheMode.LOCAL;
+ }
+ else
+ {
+ boolean synchronous = mode.isSynchronous();
+ if (value > 0)
+ {
+ mode = synchronous ? CacheMode.DIST_SYNC : CacheMode.DIST_ASYNC;
+ }
+ else // Negative backups means total replication
+ {
+ mode = synchronous ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC;
+ }
+ }
+ }
+
+ if (replMode != null)
+ {
+ switch (replMode)
+ {
+ case SYNCHRONOUS:
+ {
+ mode = mode.toSync();
+ break;
+ }
+ case ASYNCHRONOUS:
+ {
+ mode = mode.toAsync();
+ break;
+ }
+ }
+ }
+
+ configuration.setCacheMode(mode);
+
+ EmbeddedCacheManager manager = (EmbeddedCacheManager) templateCache.getCacheManager();
+ manager.defineConfiguration(cacheName, configuration);
+
this.cache = manager.getCache(cacheName);
if (this.cache.getStatus() != ComponentStatus.RUNNING)
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java 2010-08-05 01:36:23 UTC (rev 107414)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java 2010-08-05 01:51:32 UTC (rev 107415)
@@ -30,6 +30,7 @@
import org.infinispan.Cache;
import org.infinispan.atomic.AtomicMap;
import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
import org.infinispan.context.Flag;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.lifecycle.ComponentStatus;
@@ -43,6 +44,7 @@
import org.jboss.ha.ispn.atomic.AtomicMapFactory;
import org.jboss.ha.ispn.invoker.CacheInvoker;
import org.jboss.metadata.web.jboss.ReplicationConfig;
+import org.jboss.metadata.web.jboss.ReplicationMode;
import org.jboss.web.tomcat.service.session.distributedcache.ispn.AtomicMapEntry;
import org.jboss.web.tomcat.service.session.distributedcache.ispn.DistributedCacheManager;
import org.jboss.web.tomcat.service.session.distributedcache.ispn.SessionAttributeStorage;
@@ -73,38 +75,80 @@
@Test
public void start()
{
+ Configuration configuration = new Configuration();
+ configuration.setCacheMode(CacheMode.REPL_ASYNC);
ReplicationConfig config = new ReplicationConfig();
config.setCacheName("session-cache");
+ config.setReplicationMode(null);
+ config.setBackups(null);
// Validate host contribution to cache name
- this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
- this.start(null, "session-cache", "", "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
- this.start(null, "session-cache", "host1", "", "host1/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", "", "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", "host1", "", "host1/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
// Validate context path contribution to cache name
- this.start(null, "session-cache", null, "/", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
- this.start(null, "session-cache", null, "/context1", "localhost/context1", config, ComponentStatus.INSTANTIATED, true, new Configuration());
- this.start(null, "session-cache", null, "/path/context1", "localhost/path/context1", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start(null, "session-cache", null, "/", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", null, "/context1", "localhost/context1", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", null, "/path/context1", "localhost/path/context1", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
// Validate starting of cache per cache status
- this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.FAILED, true, new Configuration());
- this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INITIALIZING, true, new Configuration());
- this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.RUNNING, false, new Configuration());
- this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.STOPPING, true, new Configuration());
- this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.TERMINATED, true, new Configuration());
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.FAILED, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INITIALIZING, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.RUNNING, false, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.STOPPING, true, configuration, CacheMode.REPL_ASYNC);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.TERMINATED, true, configuration, CacheMode.REPL_ASYNC);
// Validate cache container qualified cache name
config.setCacheName("default:session-cache");
- this.start("default", "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start("default", "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+
+ config.setCacheName("session-cache");
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_SYNC);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+
+ config.setBackups(Integer.valueOf(-1));
+ config.setReplicationMode(null);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_SYNC);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.REPL_ASYNC);
+
+ config.setBackups(Integer.valueOf(0));
+ config.setReplicationMode(null);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.LOCAL);
+
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.LOCAL);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.LOCAL);
+
+ config.setBackups(Integer.valueOf(1));
+ config.setReplicationMode(null);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.DIST_ASYNC);
+
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.DIST_SYNC);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, configuration, CacheMode.DIST_ASYNC);
}
- private DistributedCacheManager<OutgoingDistributableSessionData> start(String containerName, String templateCacheName, String hostName, String contextName, String cacheName, ReplicationConfig config, ComponentStatus cacheStatus, boolean startCache, Configuration configuration)
+ private DistributedCacheManager<OutgoingDistributableSessionData> start(String containerName, String templateCacheName, String hostName, String contextName, String cacheName, ReplicationConfig config, ComponentStatus cacheStatus, boolean startCache, Configuration configuration, CacheMode mode)
{
DistributedCacheManager<OutgoingDistributableSessionData> manager = new DistributedCacheManager<OutgoingDistributableSessionData>(this.manager, this.registry, this.storage, this.invoker, this.atomicMapFactory);
@SuppressWarnings("unchecked")
Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
EmbeddedCacheManager cacheManager = EasyMock.createStrictMock(EmbeddedCacheManager.class);
+ Capture<Configuration> capturedConfiguration = new Capture<Configuration>();
EasyMock.expect(this.manager.getReplicationConfig()).andReturn(config);
@@ -112,8 +156,9 @@
EasyMock.expect(this.manager.getHostName()).andReturn(hostName);
EasyMock.expect(this.manager.getContextName()).andReturn(contextName);
EasyMock.expect(this.container.getCache()).andReturn(cache);
+ EasyMock.expect(cache.getConfiguration()).andReturn(configuration);
EasyMock.expect(cache.getCacheManager()).andReturn(cacheManager);
- EasyMock.expect(cacheManager.defineConfiguration(cacheName, templateCacheName, new Configuration())).andReturn(configuration);
+ EasyMock.expect(cacheManager.defineConfiguration(EasyMock.eq(cacheName), EasyMock.capture(capturedConfiguration))).andReturn(new Configuration());
EasyMock.expect(cacheManager.<String, AtomicMap<Object, Object>>getCache(cacheName)).andReturn(this.cache);
EasyMock.expect(this.cache.getStatus()).andReturn(cacheStatus);
@@ -135,6 +180,10 @@
Assert.assertNotNull(manager.getBatchingManager());
+ Configuration cacheConfiguration = capturedConfiguration.getValue();
+ Assert.assertSame(mode, cacheConfiguration.getCacheMode());
+ Assert.assertEquals((config.getBackups() != null) ? config.getBackups().intValue() : 2, cacheConfiguration.getNumOwners());
+
EasyMock.reset(this.registry, this.manager, this.container, this.storage, this.cache, this.invoker, cache, cacheManager);
return manager;
@@ -145,7 +194,7 @@
ReplicationConfig config = new ReplicationConfig();
config.setCacheName("session-cache");
- return this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ return this.start(null, "session-cache", null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration(), CacheMode.LOCAL);
}
@Test
More information about the jboss-cvs-commits
mailing list