[jboss-cvs] JBossAS SVN: r107403 - in projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha: jndi/ispn and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 4 17:35:04 EDT 2010


Author: pferraro
Date: 2010-08-04 17:35:04 -0400 (Wed, 04 Aug 2010)
New Revision: 107403

Modified:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/DistributedState.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/jndi/ispn/DistributedTreeManager.java
Log:
Get cache from injected CacheContainerRegistry instead of HAPartitionCacheHandler.

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/DistributedState.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/DistributedState.java	2010-08-04 21:33:41 UTC (rev 107402)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/DistributedState.java	2010-08-04 21:35:04 UTC (rev 107403)
@@ -35,7 +35,7 @@
 import org.infinispan.Cache;
 import org.infinispan.atomic.AtomicMap;
 import org.infinispan.atomic.AtomicMapLookup;
-import org.infinispan.config.Configuration;
+import org.infinispan.lifecycle.ComponentStatus;
 import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
 import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
 import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
@@ -44,6 +44,7 @@
 import org.infinispan.notifications.Listener;
 import org.infinispan.util.SimpleImmutableEntry;
 import org.jboss.ha.framework.server.spi.ManagedDistributedState;
+import org.jboss.ha.ispn.CacheContainerRegistry;
 
 /**
  * This class manages distributed state across the cluster.
@@ -62,21 +63,23 @@
  * @author  <a href="mailto:bill at burkecentral.com">Bill Burke</a>.
  * @author  Scott.Stark at jboss.org
  * @author  Scott Marlow
- * @version $Revision:77673 $
+ * @author  Paul Ferraro
  */
 @Listener
 public class DistributedState 
    implements ManagedDistributedState
 {
    private final ConcurrentMap<String, List<DSListener>> keyListeners = new ConcurrentHashMap<String, List<DSListener>>();
-   private final InfinispanHAPartitionCacheHandler<Serializable, Serializable> cacheHandler;
+   private final CacheContainerRegistry registry;
 
+   private volatile boolean stopCache = false;
+   private volatile String containerName;
+   private volatile String cacheName;
    private volatile Cache<Serializable, Serializable> cache;
-   private volatile boolean replAsync;
 
-   public DistributedState(InfinispanHAPartitionCacheHandler<Serializable, Serializable> cacheHandler)
+   public DistributedState(CacheContainerRegistry registry)
    {
-      this.cacheHandler = cacheHandler;
+      this.registry = registry;
    }
 
    // Public --------------------------------------------------------
@@ -89,7 +92,14 @@
    @Override
    public void startService() throws Exception
    {
-      this.internalSetClusteredCache(cacheHandler.getCache());
+      this.cache = this.registry.getCacheContainer(this.containerName).getCache(this.cacheName);
+      
+      if (this.cache.getStatus() != ComponentStatus.RUNNING)
+      {
+         this.cache.start();
+         this.stopCache = true;
+      }
+      
       this.cache.addListener(this);
    }
 
@@ -97,6 +107,12 @@
    public void stopService() throws Exception
    {      
       this.cache.removeListener(this);
+      
+      if (this.stopCache)
+      {
+         this.cache.stop();
+         this.stopCache = false;
+      }
    }
 
    @Override
@@ -104,6 +120,15 @@
    {
    }
 
+   public void setCacheContainerName(String containerName)
+   {
+      this.containerName = containerName;
+   }
+   
+   public void setCacheName(String cacheName)
+   {
+      this.cacheName = cacheName;
+   }
 /*
 TODO:  jmx support, delete or bring mbean interface back.
    public String listContent() throws Exception
@@ -484,31 +509,6 @@
       }
    }
 
-   
-   // Private ------------------------------------------------------------
-   
-   private void internalSetClusteredCache(Cache<Serializable, Serializable> cache)
-   {
-      this.cache = cache;
-
-      if (this.cache != null)
-      {        
-        Configuration.CacheMode cm = cache.getConfiguration().getCacheMode();
-        if (Configuration.CacheMode.REPL_ASYNC == cm)
-        {
-           this.replAsync = true;
-        }
-        else if (Configuration.CacheMode.REPL_SYNC == cm)
-        {
-           this.replAsync = false;
-        }
-        else
-        {
-           throw new IllegalStateException("Cache must be configured for replication, not " + cm);
-        }
-      }
-   }
-
    private SimpleImmutableEntry<String, Serializable> buildValueCollectionKey(String category, Serializable dskey)
    {
       return new SimpleImmutableEntry<String, Serializable>(category, dskey);

Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/jndi/ispn/DistributedTreeManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/jndi/ispn/DistributedTreeManager.java	2010-08-04 21:33:41 UTC (rev 107402)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/jndi/ispn/DistributedTreeManager.java	2010-08-04 21:35:04 UTC (rev 107403)
@@ -40,11 +40,13 @@
 import javax.naming.NamingException;
 import javax.naming.NotContextException;
 
+import org.infinispan.Cache;
 import org.infinispan.CacheException;
+import org.infinispan.lifecycle.ComponentStatus;
 import org.infinispan.tree.Fqn;
 import org.infinispan.tree.Node;
 import org.infinispan.tree.TreeCache;
-import org.jboss.ha.framework.server.ispn.InfinispanHAPartitionCacheHandler;
+import org.jboss.ha.ispn.CacheContainerRegistry;
 import org.jboss.ha.ispn.tree.DefaultTreeCacheFactory;
 import org.jboss.ha.ispn.tree.TreeCacheFactory;
 import org.jboss.logging.Logger;
@@ -69,27 +71,38 @@
    private static final String DEFAULT_ROOT = "__HA_JNDI__";
    private static final Fqn FQN_ROOT = Fqn.fromString(DEFAULT_ROOT);
 
-   private final InfinispanHAPartitionCacheHandler<String, Binding> cacheHandler;
+   private final CacheContainerRegistry registry;
    private final TreeCacheFactory treeCacheFactory;
    
+   private volatile boolean stopCache = false;
+   private volatile String containerName;
+   private volatile String cacheName;
    private volatile Naming haStub;
    private volatile TreeCache<String, Binding> cache;
 
-   public DistributedTreeManager(InfinispanHAPartitionCacheHandler<String, Binding> cacheHandler)
+   public DistributedTreeManager(CacheContainerRegistry registry)
    {
-      this(cacheHandler, new DefaultTreeCacheFactory());
+      this(registry, new DefaultTreeCacheFactory());
    }
 
-   public DistributedTreeManager(InfinispanHAPartitionCacheHandler<String, Binding> cacheHandler, TreeCacheFactory factory)
+   public DistributedTreeManager(CacheContainerRegistry registry, TreeCacheFactory factory)
    {
-      this.cacheHandler = cacheHandler;
+      this.registry = registry;
       this.treeCacheFactory = factory;
    }
 
    @Override
    public void init()
    {
-      cache = treeCacheFactory.createTreeCache(cacheHandler.getCache());
+      Cache<String, Binding> cache = this.registry.getCacheContainer(this.containerName).getCache(this.cacheName);
+      this.cache = this.treeCacheFactory.createTreeCache(cache);
+      
+      if (cache.getStatus() != ComponentStatus.RUNNING)
+      {
+         this.cache.start();
+         this.stopCache = true;
+      }
+      
       LOG.debug("initializing HAJNDITreeCache root");
    }
 
@@ -97,9 +110,22 @@
    @Override
    public void shutdown()
    {
-      cache = null;
+      if (this.stopCache)
+      {
+         this.cache.stop();
+         this.stopCache = false;
+      }
    }
 
+   public void setCacheContainerName(String containerName)
+   {
+      this.containerName = containerName;
+   }
+   
+   public void setCacheName(String cacheName)
+   {
+      this.cacheName = cacheName;
+   }
 
    @Override
    public Naming getHAStub()



More information about the jboss-cvs-commits mailing list