[jbosscache-commits] JBoss Cache SVN: r6447 - benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Jul 30 17:20:36 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-07-30 17:20:36 -0400 (Wed, 30 Jul 2008)
New Revision: 6447

Modified:
   benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java
Log:
Added explicit locking for coherence

Modified: benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java
===================================================================
--- benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java	2008-07-30 17:13:20 UTC (rev 6446)
+++ benchmarks/benchmark-fwk/trunk/cache-products/coherence-3.3.1/src/org/cachebench/cachewrappers/Coherence331Wrapper.java	2008-07-30 21:20:36 UTC (rev 6447)
@@ -2,6 +2,7 @@
 
 import com.tangosol.net.CacheFactory;
 import com.tangosol.net.NamedCache;
+import com.tangosol.util.TransactionMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.cachebench.CacheWrapper;
@@ -18,7 +19,8 @@
 public class Coherence331Wrapper implements CacheWrapper
 {
 
-   private NamedCache cache;
+   private TransactionMap cache;
+   private NamedCache nc;
    boolean localmode;
    Map parameters;
    private Log log = LogFactory.getLog(Coherence331Wrapper.class);
@@ -35,43 +37,59 @@
       localmode = (Boolean.parseBoolean((String) parameters.get("localOnly")));
       if (trimmedConfig.indexOf("repl") == 0)
       {
-         cache = CacheFactory.getCache("repl-CacheBenchmarkFramework");
+         nc = CacheFactory.getCache("repl-CacheBenchmarkFramework");
       }
       else if (trimmedConfig.indexOf("dist") == 0)
       {
-         cache = CacheFactory.getCache("dist-CacheBenchmarkFramework");
+         nc = CacheFactory.getCache("dist-CacheBenchmarkFramework");
       }
       else if (trimmedConfig.indexOf("local") == 0)
       {
-         cache = CacheFactory.getCache("local-CacheBenchmarkFramework");
+         nc = CacheFactory.getCache("local-CacheBenchmarkFramework");
       }
       else if (trimmedConfig.indexOf("opt") == 0)
       {
-         cache = CacheFactory.getCache("opt-CacheBenchmarkFramework");
+         nc = CacheFactory.getCache("opt-CacheBenchmarkFramework");
       }
       else if (trimmedConfig.indexOf("near") == 0)
       {
-         cache = CacheFactory.getCache("near-CacheBenchmarkFramework");
+         nc = CacheFactory.getCache("near-CacheBenchmarkFramework");
       }
       else
          throw new RuntimeException("Invalid configuration ('" + trimmedConfig + "'). Configuration name should start with: 'dist', 'repl', 'local', 'opt' or 'near'");
 
-      log.info("Starting Coherence cache " + cache.getCacheName());
+      cache = CacheFactory.getLocalTransaction(nc);
+      log.info("Starting Coherence cache " + nc.getCacheName());
    }
 
    public void tearDown() throws Exception
    {
-      if (cache != null) cache.release();
+      if (cache != null) nc.release();
    }
 
    public void put(List<String> path, Object key, Object value) throws Exception
    {
-      cache.put(pathAsString(path, key), value);
+      cache.lock(key);
+      try
+      {
+         cache.put(pathAsString(path, key), value);
+      }
+      finally
+      {
+         cache.unlock(key);
+      }
    }
 
    public Object get(List<String> path, Object key) throws Exception
    {
-      return cache.get(pathAsString(path, key));
+      try
+      {
+         return cache.get(pathAsString(path, key));
+      }
+      finally
+      {
+         cache.unlock(key);
+      }
    }
 
    public void empty() throws Exception
@@ -81,12 +99,12 @@
 
    public int getNumMembers()
    {
-      return localmode ? 0 : cache.getCacheService().getCluster().getMemberSet().size();
+      return localmode ? 0 : nc.getCacheService().getCluster().getMemberSet().size();
    }
 
    public String getInfo()
    {
-      return cache.getCacheName();
+      return nc.getCacheName();
    }
 
    public Object getReplicatedData(List<String> path, String key) throws Exception




More information about the jbosscache-commits mailing list