[jboss-cvs] JBossAS SVN: r79478 - in projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha: jndi/impl/jbc and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 14 13:48:48 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-10-14 13:48:48 -0400 (Tue, 14 Oct 2008)
New Revision: 79478
Modified:
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/DistributedStateImpl.java
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java
projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/jndi/impl/jbc/JBossCacheDistributedTreeManager.java
Log:
[JBAS-6083] Coordinate release of cache
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/DistributedStateImpl.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/DistributedStateImpl.java 2008-10-14 17:21:04 UTC (rev 79477)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/DistributedStateImpl.java 2008-10-14 17:48:48 UTC (rev 79478)
@@ -72,7 +72,7 @@
protected Cache cache;
protected boolean replAsync;
protected HAPartitionCacheHandlerImpl cacheHandler;
- protected boolean cacheFromHandler = false;
+ protected boolean acquiredCache = false;
// Public --------------------------------------------------------
@@ -88,10 +88,20 @@
{
throw new IllegalStateException("No clustered cache available");
}
- cacheHandler.acquireCache();
+
+ Cache c = null;
+ synchronized (cacheHandler)
+ {
+ c = cacheHandler.getCache();
+ if (c == null)
+ {
+ cacheHandler.acquireCache();
+ c = cacheHandler.getCache();
+ acquiredCache = true;
+ }
+ }
cacheHandler.startCache();
- setClusteredCache(cacheHandler.getCache());
- cacheFromHandler = true;
+ setClusteredCache(c);
}
this.cache.addCacheListener(this);
@@ -101,7 +111,7 @@
{
this.cache.removeCacheListener(this);
- if (cacheFromHandler)
+ if (acquiredCache)
{
cacheHandler.releaseCache();
}
@@ -206,7 +216,7 @@
throw new IllegalStateException("Cache must be configured for replication, not " + cm);
}
- cacheFromHandler = false;
+ acquiredCache = false;
}
}
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java 2008-10-14 17:21:04 UTC (rev 79477)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/framework/server/HAPartitionCacheHandlerImpl.java 2008-10-14 17:48:48 UTC (rev 79478)
@@ -22,6 +22,8 @@
package org.jboss.ha.framework.server;
+import java.util.concurrent.atomic.AtomicInteger;
+
import org.jboss.cache.Cache;
import org.jboss.cache.CacheManager;
import org.jboss.cache.CacheStatus;
@@ -38,6 +40,7 @@
private CacheManager cacheManager;
private String cacheConfigName;
private Cache cache;
+ private AtomicInteger acquireCount = new AtomicInteger();
// CacheHandler ------------------------------------------------------------
@@ -49,6 +52,7 @@
cache = cacheManager.getCache(cacheConfigName, true);
}
+ acquireCount.incrementAndGet();
}
public synchronized void startCache() throws Exception
@@ -62,14 +66,17 @@
cache.start();
}
- public synchronized void releaseCache() throws Exception
+ public synchronized void releaseCache() throws Exception
{
if (cache != null)
{
validateState();
- cacheManager.releaseCache(cacheConfigName);
- cache = null;
+ if (acquireCount.decrementAndGet() == 0)
+ {
+ cacheManager.releaseCache(cacheConfigName);
+ cache = null;
+ }
}
}
@@ -113,7 +120,7 @@
this.cacheManager = cacheManager;
}
- public Cache getCache()
+ public synchronized Cache getCache()
{
return cache;
}
Modified: projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/jndi/impl/jbc/JBossCacheDistributedTreeManager.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/jndi/impl/jbc/JBossCacheDistributedTreeManager.java 2008-10-14 17:21:04 UTC (rev 79477)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/main/java/org/jboss/ha/jndi/impl/jbc/JBossCacheDistributedTreeManager.java 2008-10-14 17:48:48 UTC (rev 79478)
@@ -77,7 +77,7 @@
private Naming haStub;
private boolean treeRootSet;
protected HAPartitionCacheHandlerImpl cacheHandler;
- protected boolean cacheFromHandler = false;
+ protected boolean acquiredCache = false;
// Constructor --------------------------------------------------------
@@ -112,11 +112,6 @@
}
this.m_cache = cache;
}
-
- public boolean isCacheFromHandler()
- {
- return cacheFromHandler;
- }
public void setRootFqn(String rootFqn)
{
@@ -145,11 +140,28 @@
throw new IllegalStateException("Must call setHAStub before starting");
}
- if (cacheHandler != null)
+ if (this.m_cache == null)
{
+ if (cacheHandler == null)
+ {
+ throw new IllegalStateException("No clustered cache available");
+ }
+
try
{
- cacheHandler.acquireCache();
+ Cache c = null;
+ synchronized (cacheHandler)
+ {
+ c = cacheHandler.getCache();
+ if (c == null)
+ {
+ cacheHandler.acquireCache();
+ c = cacheHandler.getCache();
+ acquiredCache = true;
+ }
+ }
+ cacheHandler.startCache();
+ setClusteredCache(c);
}
catch (RuntimeException e)
{
@@ -159,23 +171,15 @@
{
throw new RuntimeException(e);
}
-
- setClusteredCache(cacheHandler.getCache());
- cacheFromHandler = true;
}
- if (this.m_cache == null)
- {
- throw new IllegalStateException("Must call setClusteredCache before starting");
- }
-
log.debug("initializing HAJNDITreeCache root");
this.putTreeRoot();
}
public void shutdown()
{
- if (cacheFromHandler)
+ if (acquiredCache)
{
try
{
More information about the jboss-cvs-commits
mailing list