[jboss-cvs] JBossAS SVN: r97639 - projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 9 16:48:35 EST 2009
Author: bstansberry at jboss.com
Date: 2009-12-09 16:48:35 -0500 (Wed, 09 Dec 2009)
New Revision: 97639
Modified:
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
Log:
[JBCLUSTER-244] Defer getting cache from manager until start
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2009-12-09 21:19:24 UTC (rev 97638)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/AbstractJBossCacheService.java 2009-12-09 21:48:35 UTC (rev 97639)
@@ -108,8 +108,13 @@
protected Logger log_ = Logger.getLogger(getClass());
- private Cache<Object, Object> plainCache_;
+ private CacheManager cacheManager_;
+ // FIXME make private when FieldBasedJBossCacheService is gone
+ protected Cache<Object, Object> plainCache_;
+ /** Whether our cache was constructor injected */
+ protected final boolean cacheInjected_;
+
/** Context path for webapp + hostName; this + session id is a unique combo. */
protected String combinedPath_;
protected BatchingManager batchingManager;
@@ -135,36 +140,30 @@
protected AbstractJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
{
- this(localManager, Util.findPlainCache(Util.getCacheConfigName(localManager)));
-
+ if (localManager == null)
+ {
+ throw new IllegalArgumentException("localManager is null");
+ }
+ this.manager_ = localManager;
+ establishCacheManager();
this.cacheConfigName_ = Util.getCacheConfigName(localManager);
+ this.cacheInjected_ = false;
}
protected AbstractJBossCacheService(LocalDistributableSessionManager localManager, Cache<Object, Object> cache)
{
- this.manager_ = localManager;
- this.plainCache_ = cache;
-
- this.cacheWrapper_ = new JBossCacheWrapper(plainCache_);
-
- this.useTreeCacheMarshalling_ = plainCache_.getConfiguration().isUseRegionBasedMarshalling();
- boolean purge = true;
- CacheLoaderConfig clc = plainCache_.getConfiguration().getCacheLoaderConfig();
- if(clc != null)
+ if (localManager == null)
{
- usePassivation_ = (clc.isPassivation() && !clc.isShared());
- purge = false;
- for (IndividualCacheLoaderConfig iclc : clc.getIndividualCacheLoaderConfigs())
- {
- if (iclc.isPurgeOnStartup())
- {
- purge = true;
- break;
- }
- }
+ throw new IllegalArgumentException("localManager is null");
}
+ if (cache == null)
+ {
+ throw new IllegalArgumentException("cache is null");
+ }
- this.purgeOnStartStop_ = purge && (this.useBuddyReplication_ || this.useTreeCacheMarshalling_);
+ this.manager_ = localManager;
+ this.plainCache_ = cache;
+ this.cacheInjected_ = true;
}
protected LocalDistributableSessionManager getManager()
@@ -184,6 +183,8 @@
public void start()
{
+ establishCache();
+
this.webAppClassLoader_ = this.manager_.getApplicationClassLoader();
String webAppPath;
@@ -417,7 +418,53 @@
cacheWrapper_.put(fqn, map);
}
+
+ protected void establishCacheManager() throws ClusteringNotSupportedException
+ {
+ this.cacheManager_ = Util.findPlainCacheManager();
+ }
+ protected void establishCache()
+ {
+ if (this.plainCache_ == null)
+ {
+ obtainCacheFromManager();
+ }
+ this.cacheWrapper_ = new JBossCacheWrapper(plainCache_);
+
+ this.useTreeCacheMarshalling_ = plainCache_.getConfiguration().isUseRegionBasedMarshalling();
+ boolean purge = true;
+ CacheLoaderConfig clc = plainCache_.getConfiguration().getCacheLoaderConfig();
+ if(clc != null)
+ {
+ usePassivation_ = (clc.isPassivation() && !clc.isShared());
+ purge = false;
+ for (IndividualCacheLoaderConfig iclc : clc.getIndividualCacheLoaderConfigs())
+ {
+ if (iclc.isPurgeOnStartup())
+ {
+ purge = true;
+ break;
+ }
+ }
+ }
+
+ this.purgeOnStartStop_ = purge && (this.useBuddyReplication_ || this.useTreeCacheMarshalling_);
+ }
+
+ protected void obtainCacheFromManager()
+ {
+ if (this.cacheManager_ == null)
+ {
+ throw new IllegalStateException("No CacheManager available");
+ }
+ if (this.cacheConfigName_ == null)
+ {
+ throw new IllegalStateException("No cache configuration name available");
+ }
+ this.plainCache_ = Util.findPlainCache(this.cacheConfigName_, this.cacheManager_);
+ }
+
/**
* Extension point to allow subclasses to add per-session JBC regions.
*
@@ -653,13 +700,16 @@
{
try
{
- CacheManager cm = CacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
- cm.releaseCache(cacheConfigName);
+ this.cacheManager_.releaseCache(cacheConfigName);
}
catch (Exception e)
{
log_.error("Problem releasing cache to CacheManager -- config is " + cacheConfigName, e);
}
+ finally
+ {
+ this.plainCache_ = null;
+ }
}
protected Object getMarshalledValue(Object value)
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java 2009-12-09 21:19:24 UTC (rev 97638)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/FieldBasedJBossCacheService.java 2009-12-09 21:48:35 UTC (rev 97639)
@@ -22,10 +22,7 @@
package org.jboss.web.tomcat.service.session.distributedcache.impl.jbc;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
@@ -76,13 +73,12 @@
}
}
- private final PojoCache pojoCache_;
+ private PojoCacheManager pojoCacheManager_;
+ private PojoCache pojoCache_;
public FieldBasedJBossCacheService(LocalDistributableSessionManager localManager) throws ClusteringNotSupportedException
{
- this(localManager, Util.findPojoCache(Util.getCacheConfigName(localManager)));
-
- this.cacheConfigName_ = Util.getCacheConfigName(localManager);
+ super(localManager);
}
/**
@@ -94,15 +90,6 @@
{
super(localManager, cache.getCache());
this.pojoCache_ = cache;
- if (!isMarshallingAvailable())
- {
- // BES 16/8/2006 -- throw ISE, not ClusteringNotSupportedException, as a
- // misconfig should be treated differently from the absence of clustering
- // services
- throw new IllegalStateException("replication-granularity value is set to " +
- "'FIELD' but is not supported by the cache service configuration. " +
- "Must set 'useRegionBasedMarshalling' to 'true' in the cache configuration");
- }
}
public boolean getSupportsAttributeOperations()
@@ -210,7 +197,44 @@
setupSessionRegion(fqn);
}
+
@Override
+ protected void establishCacheManager() throws ClusteringNotSupportedException
+ {
+ this.pojoCacheManager_ = Util.findPojoCacheManager();
+ }
+
+ @Override
+ protected void obtainCacheFromManager()
+ {
+ if (this.pojoCacheManager_ == null)
+ {
+ throw new IllegalStateException("No PojoCacheManager available");
+ }
+ if (this.cacheConfigName_ == null)
+ {
+ throw new IllegalStateException("No cache configuration name available");
+ }
+ this.pojoCache_ = Util.findPojoCache(this.cacheConfigName_, this.pojoCacheManager_);
+ this.plainCache_ = this.pojoCache_.getCache();
+ }
+
+ @Override
+ protected void establishCache()
+ {
+ super.establishCache();
+ if (!isMarshallingAvailable())
+ {
+ // BES 16/8/2006 -- throw ISE, not ClusteringNotSupportedException, as a
+ // misconfig should be treated differently from the absence of clustering
+ // services
+ throw new IllegalStateException("replication-granularity value is set to " +
+ "'FIELD' but is not supported by the cache service configuration. " +
+ "Must set 'useRegionBasedMarshalling' to 'true' in the cache configuration");
+ }
+ }
+
+ @Override
protected void setupSessionRegion(Fqn<String> fqn)
{
getCache().getRegion(fqn, true);
@@ -235,13 +259,17 @@
{
try
{
- PojoCacheManager pcm = PojoCacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
- pcm.releaseCache(cacheConfigName);
+ this.pojoCacheManager_.releaseCache(cacheConfigName);
}
catch (Exception e)
{
log_.error("Problem releasing cache to CacheManager -- config is " + cacheConfigName, e);
}
+ finally
+ {
+ this.plainCache_ = null;
+ this.pojoCache_ = null;
+ }
}
public Map<String, Object> getAttributes(String realId)
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java 2009-12-09 21:19:24 UTC (rev 97638)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/impl/jbc/Util.java 2009-12-09 21:48:35 UTC (rev 97639)
@@ -54,6 +54,16 @@
return config.getCacheName();
}
+ /**
+ * Gets a pojo cache with the named configuration
+ *
+ * @param cacheConfigName the name of the configuration
+ * @return the cache
+ * @throws ClusteringNotSupportedException
+ *
+ * @deprecated use {@link #findPojoCache(String, PojoCacheManager)
+ */
+ @Deprecated
public static PojoCache findPojoCache(String cacheConfigName) throws ClusteringNotSupportedException
{
PojoCacheManager pcm = getManagerForPojoCache(cacheConfigName);
@@ -72,6 +82,35 @@
}
}
+ public static PojoCache findPojoCache(String cacheConfigName, PojoCacheManager pcm)
+ {
+ if (!pcm.getConfigurationNames().contains(cacheConfigName))
+ throw new IllegalStateException("PojoCacheManager does not recognize config " + cacheConfigName);
+
+ try
+ {
+ return pcm.getPojoCache(cacheConfigName, true);
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Problem accessing cache " + cacheConfigName, e);
+ }
+ }
+
+ /**
+ * Gets a plain cache with the named configuration
+ *
+ * @param cacheConfigName the name of the configuration
+ * @return the cache
+ * @throws ClusteringNotSupportedException
+ *
+ * @deprecated use {@link #findPlainCache(String, CacheManager)
+ */
+ @Deprecated
public static Cache<Object, Object> findPlainCache(String cacheConfigName) throws ClusteringNotSupportedException
{
CacheManager pcm = getManagerForCache(cacheConfigName);
@@ -90,6 +129,49 @@
}
}
+ public static Cache<Object, Object> findPlainCache(String cacheConfigName, CacheManager cm)
+ {
+ if (!cm.getConfigurationNames().contains(cacheConfigName))
+ throw new IllegalStateException("CacheManager does not recognize config " + cacheConfigName);
+
+ try
+ {
+ return cm.getCache(cacheConfigName, true);
+ }
+ catch (RuntimeException re)
+ {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Problem accessing cache " + cacheConfigName, e);
+ }
+ }
+
+ public static PojoCacheManager findPojoCacheManager() throws ClusteringNotSupportedException
+ {
+ try
+ {
+ return PojoCacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
+ }
+ catch (Throwable t)
+ {
+ throw new ClusteringNotSupportedException("Could not access CacheManager for JBossWeb clustering", t);
+ }
+ }
+
+ public static CacheManager findPlainCacheManager() throws ClusteringNotSupportedException
+ {
+ try
+ {
+ return CacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
+ }
+ catch (Throwable t)
+ {
+ throw new ClusteringNotSupportedException("Could not access CacheManager for JBossWeb clustering", t);
+ }
+ }
+
private static PojoCacheManager getManagerForPojoCache(String cacheConfigName)
throws ClusteringNotSupportedException
{
@@ -143,7 +225,7 @@
}
StringBuilder sb = new StringBuilder(realId.substring(0, 2));
sb.append("****");
- sb.append(sb.substring(length - 6, length));
+ sb.append(realId.substring(length - 6, length));
return sb.toString();
}
}
More information about the jboss-cvs-commits
mailing list