[jboss-cvs] JBossAS SVN: r108044 - projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 8 11:58:16 EDT 2010
Author: pferraro
Date: 2010-09-08 11:58:16 -0400 (Wed, 08 Sep 2010)
New Revision: 108044
Added:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/CacheContainerSource.java
Removed:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/InfinispanHAPartitionCacheHandler.java
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/HAPartitionCacheHandler.java
Log:
Refactor HAPartitionCacheHandler to be cache container oriented, rather than cache oriented.
This renders the acquire/release methods as no-ops.
Copied: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/CacheContainerSource.java (from rev 108007, projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/InfinispanHAPartitionCacheHandler.java)
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/CacheContainerSource.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/CacheContainerSource.java 2010-09-08 15:58:16 UTC (rev 108044)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.framework.server.ispn;
+
+import org.infinispan.manager.CacheContainer;
+
+/**
+ * A cache container source.
+ * @author Paul Ferraro
+ */
+public interface CacheContainerSource
+{
+ /**
+ * Returns the cache instance associated with this cache handler.
+ * @return an Infinispan cache instance.
+ */
+ CacheContainer getCacheContainer();
+}
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/HAPartitionCacheHandler.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/HAPartitionCacheHandler.java 2010-09-08 15:56:27 UTC (rev 108043)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/HAPartitionCacheHandler.java 2010-09-08 15:58:16 UTC (rev 108044)
@@ -1,25 +1,18 @@
package org.jboss.ha.framework.server.ispn;
import java.util.Properties;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
-import org.infinispan.Cache;
-import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.ha.ispn.CacheContainerRegistry;
import org.jgroups.ChannelFactory;
@SuppressWarnings("deprecation")
-public class HAPartitionCacheHandler<K, V> implements InfinispanHAPartitionCacheHandler<K, V>
+public class HAPartitionCacheHandler implements CacheContainerSource, org.jboss.ha.framework.server.spi.HAPartitionCacheHandler
{
private final CacheContainerRegistry registry;
- private final AtomicReference<Cache<K, V>> cacheReference = new AtomicReference<Cache<K, V>>();
- private final AtomicInteger acquireCount = new AtomicInteger();
private volatile String cacheContainerName;
- private volatile String cacheName;
public HAPartitionCacheHandler(CacheContainerRegistry registry)
{
@@ -28,31 +21,12 @@
/**
* {@inheritDoc}
- * @see org.jboss.ha.framework.server.ispn.InfinispanHAPartitionCacheHandler#getCache()
- */
- @Override
- public Cache<K, V> getCache()
- {
- return this.cacheReference.get();
- }
-
- /**
- * {@inheritDoc}
* @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#acquireCache()
*/
@Override
public void acquireCache()
{
- if (this.cacheReference.get() == null)
- {
- CacheContainer container = this.registry.getCacheContainer(this.cacheContainerName);
-
- String name = this.cacheName;
-
- this.cacheReference.compareAndSet(null, (name != null) ? container.<K, V>getCache(name) : container.<K, V>getCache());
- }
-
- this.acquireCount.incrementAndGet();
+ // No-op
}
/**
@@ -62,17 +36,7 @@
@Override
public void startCache()
{
- Cache<K, V> cache = this.cacheReference.get();
-
- if (cache == null)
- {
- throw new IllegalStateException("You must first acquire a cache before starting it.");
- }
-
- if (cache.getStatus() != ComponentStatus.RUNNING)
- {
- cache.start();
- }
+ // No-op
}
/**
@@ -82,28 +46,26 @@
@Override
public void releaseCache()
{
- int count = this.acquireCount.decrementAndGet();
-
- if (count == 0)
- {
- Cache<K, V> cache = this.cacheReference.getAndSet(null);
-
- if ((cache != null) && (cache.getStatus() == ComponentStatus.RUNNING))
- {
- cache.stop();
- }
- }
- else if (count < 0)
- {
- // Attempt to resolve
- this.acquireCount.compareAndSet(count, count + 1);
-
- throw new IllegalStateException("Attempt to release cache that was not acquired.");
- }
+ // No-op
}
/**
* {@inheritDoc}
+ * @see org.jboss.ha.framework.server.ispn.CacheContainerSource#getCacheContainer()
+ */
+ @Override
+ public CacheContainer getCacheContainer()
+ {
+ return this.getCacheManager();
+ }
+
+ private EmbeddedCacheManager getCacheManager()
+ {
+ return this.registry.getCacheContainer(this.cacheContainerName);
+ }
+
+ /**
+ * {@inheritDoc}
* @see org.jboss.ha.framework.server.spi.HAPartitionCacheHandler#getChannelStackName()
*/
@Override
@@ -124,23 +86,7 @@
private Properties getTransportProperties()
{
- Cache<K, V> cache = this.cacheReference.get();
-
- if (cache == null)
- {
- throw new IllegalStateException("Must acquire cache before getting channel stack name");
- }
-
- CacheContainer container = cache.getCacheManager();
-
- if (!(container instanceof EmbeddedCacheManager))
- {
- throw new IllegalStateException(String.format("Cache container [%s] is not of the expected type: %s", container.getClass().getName(), EmbeddedCacheManager.class.getName()));
- }
-
- EmbeddedCacheManager manager = (EmbeddedCacheManager) container;
-
- return manager.getGlobalConfiguration().getTransportProperties();
+ return this.getCacheManager().getGlobalConfiguration().getTransportProperties();
}
/**
@@ -150,28 +96,9 @@
@Override
public String getCacheConfigName()
{
- StringBuilder builder = new StringBuilder();
-
- if (this.cacheContainerName != null)
- {
- builder.append(this.cacheContainerName);
- }
- if (this.cacheName != null)
- {
- if (builder.length() > 0)
- {
- builder.append("/");
- }
- builder.append(this.cacheName);
- }
- return builder.toString();
+ return this.cacheContainerName;
}
- public void setCacheName(String cacheName)
- {
- this.cacheName = cacheName;
- }
-
public void setCacheContainerName(String cacheContainerName)
{
this.cacheContainerName = cacheContainerName;
Deleted: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/InfinispanHAPartitionCacheHandler.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/InfinispanHAPartitionCacheHandler.java 2010-09-08 15:56:27 UTC (rev 108043)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/framework/server/ispn/InfinispanHAPartitionCacheHandler.java 2010-09-08 15:58:16 UTC (rev 108044)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ha.framework.server.ispn;
-
-import org.infinispan.Cache;
-import org.jboss.ha.framework.server.spi.HAPartitionCacheHandler;
-
-/**
- * Provides access to the underlying Infinispan cache instance of this cache handler.
- * @author Paul Ferraro
- */
-public interface InfinispanHAPartitionCacheHandler<K, V> extends HAPartitionCacheHandler
-{
- /**
- * Returns the cache instance associated with this cache handler.
- * @return an Infinispan cache instance.
- */
- Cache<K, V> getCache();
-}
More information about the jboss-cvs-commits
mailing list