[jboss-cvs] JBossAS SVN: r73749 - in trunk: cluster/src/resources/jboss-cache-manager.sar/META-INF and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 28 12:08:32 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-05-28 12:08:31 -0400 (Wed, 28 May 2008)
New Revision: 73749
Modified:
trunk/cluster/src/main/org/jboss/ha/cachemanager/CacheManager.java
trunk/cluster/src/resources/jboss-cache-manager.sar/META-INF/jboss-cache-manager-beans.xml
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerUnitTestCase.java
Log:
[JBAS-5510] CacheManager can be configured to start a set of caches during its start
Modified: trunk/cluster/src/main/org/jboss/ha/cachemanager/CacheManager.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/cachemanager/CacheManager.java 2008-05-28 15:19:20 UTC (rev 73748)
+++ trunk/cluster/src/main/org/jboss/ha/cachemanager/CacheManager.java 2008-05-28 16:08:31 UTC (rev 73749)
@@ -90,6 +90,8 @@
private boolean registerCachesInJmx = true;
+ private Map<String, Boolean> startupCaches = new HashMap<String, Boolean>();
+
private String jndiName;
private boolean started;
@@ -320,6 +322,8 @@
{
super.start();
+ startEagerStartCaches();
+
CacheManagerLocator locator = CacheManagerLocator.getCacheManagerLocator();
if (locator.getDirectlyRegisteredManager() == null)
locator.registerCacheManager(this);
@@ -345,6 +349,8 @@
{
if (started)
{
+ releaseEagerStartCaches();
+
synchronized (pojoCaches)
{
for (Iterator<Map.Entry<String, PojoCache>> it = pojoCaches.entrySet().iterator(); it.hasNext();)
@@ -481,8 +487,30 @@
}
}
+ public void setEagerStartCaches(Set<String> configNames)
+ {
+ if (configNames != null)
+ {
+ for (String name : configNames)
+ {
+ startupCaches.put(name, Boolean.FALSE);
+ }
+ }
+ }
+ public void setEagerStartPojoCaches(Set<String> configNames)
+ {
+ if (configNames != null)
+ {
+ for (String name : configNames)
+ {
+ startupCaches.put(name, Boolean.TRUE);
+ }
+ }
+ }
+
+
// ------------------------------------------------------ MBeanRegistration
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
@@ -658,5 +686,39 @@
String alias = configAliases.get(configName);
return alias == null ? configName : alias;
}
+
+ private void startEagerStartCaches() throws Exception
+ {
+ for (Map.Entry<String, Boolean> entry : startupCaches.entrySet())
+ {
+ Cache cache = null;
+ if (entry.getValue().booleanValue())
+ {
+ PojoCache pc = getPojoCache(entry.getKey(), true);
+ cache = pc.getCache();
+ }
+ else
+ {
+ cache = getCache(entry.getKey(), true);
+ }
+
+ if (cache.getCacheStatus() != CacheStatus.STARTED)
+ {
+ if (cache.getCacheStatus() != CacheStatus.CREATED)
+ {
+ cache.create();
+ }
+ cache.start();
+ }
+ }
+ }
+
+ private void releaseEagerStartCaches()
+ {
+ for (String name : startupCaches.keySet())
+ {
+ releaseCache(name);
+ }
+ }
}
Modified: trunk/cluster/src/resources/jboss-cache-manager.sar/META-INF/jboss-cache-manager-beans.xml
===================================================================
--- trunk/cluster/src/resources/jboss-cache-manager.sar/META-INF/jboss-cache-manager-beans.xml 2008-05-28 15:19:20 UTC (rev 73748)
+++ trunk/cluster/src/resources/jboss-cache-manager.sar/META-INF/jboss-cache-manager-beans.xml 2008-05-28 16:08:31 UTC (rev 73749)
@@ -40,6 +40,14 @@
</entry>
</map>
</property>
+
+ <!-- Start these caches as part of the start of this CacheManager -->
+ <property name="eagerStartCaches">
+ <set>
+ <value>ha-partition</value>
+ </set>
+ </property>
+
</bean>
</deployment>
\ No newline at end of file
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerUnitTestCase.java 2008-05-28 15:19:20 UTC (rev 73748)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/CacheManagerUnitTestCase.java 2008-05-28 16:08:31 UTC (rev 73749)
@@ -349,4 +349,69 @@
assertEquals(0, registry.getPojoCacheNames().size());
}
+
+ public void testEagerStartCaches() throws Exception
+ {
+ JChannelFactory cf = new JChannelFactory();
+ cf.setMultiplexerConfig(DEFAULT_STACKS_FILE);
+ cf.setExposeChannels(false);
+ cf.start();
+ CacheManager registry = new CacheManager(DEFAULT_CONFIGURATION_FILE, cf);
+
+ Set<String> cores = new HashSet<String>();
+ cores.add("test1");
+ cores.add("test2");
+ registry.setEagerStartCaches(cores);
+ Set<String> pojos = new HashSet<String>();
+ pojos.add("test5");
+ pojos.add("test6");
+ registry.setEagerStartPojoCaches(pojos);
+
+ registry.start();
+
+ assertEquals(cores, registry.getCacheNames());
+ assertEquals(pojos, registry.getPojoCacheNames());
+
+ Set<Cache> caches = new HashSet<Cache>();
+
+ for (String name : cores)
+ {
+ Cache cache = registry.getCache(name, false);
+ assertNotNull(cache);
+ assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+ caches.add(cache);
+ }
+
+ for (String name : pojos)
+ {
+ PojoCache pojocache = registry.getPojoCache(name, false);
+ assertNotNull(pojocache);
+ Cache cache = pojocache.getCache();
+ assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+ caches.add(cache);
+ }
+
+ for (String name : cores)
+ {
+ registry.releaseCache(name);
+ }
+
+ for (String name : pojos)
+ {
+ registry.releaseCache(name);
+ }
+
+ for (Cache cache : caches)
+ {
+ assertEquals(CacheStatus.STARTED, cache.getCacheStatus());
+ }
+
+ registry.stop();
+
+ for (Cache cache : caches)
+ {
+ assertEquals(CacheStatus.DESTROYED, cache.getCacheStatus());
+ }
+
+ }
}
More information about the jboss-cvs-commits
mailing list