[jboss-cvs] CacheBenchFwk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers ...
Manik Surtani
manik at jboss.org
Mon May 21 10:00:48 EDT 2007
User: msurtani
Date: 07/05/21 10:00:48
Modified: cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers
EHCacheTest.java EHCacheWrapper.java
Log:
Added the ability to use bind.address
Revision Changes Path
1.2 +9 -0 CacheBenchFwk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EHCacheTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- EHCacheTest.java 18 May 2007 14:32:09 -0000 1.1
+++ EHCacheTest.java 21 May 2007 14:00:48 -0000 1.2
@@ -6,6 +6,9 @@
import java.net.URL;
import java.io.File;
+import java.util.Properties;
+
+import org.cachebench.CacheWrapper;
/**
* // TODO: Add Javadocs
@@ -19,6 +22,12 @@
public static void main(String[] args) throws Exception
{
+
+ CacheWrapper w = new EHCacheWrapper();
+ Properties p = new Properties();
+ p.setProperty("config", "ehcache-repl-sync.xml");
+ w.init(p);
+
Ehcache cache;
URL url = new URL("file:///Users/manik/Code/CacheBenchFwk/cache-products/ehcache-1.2.4/conf/ehcache-repl-sync.xml");
1.4 +52 -2 CacheBenchFwk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: EHCacheWrapper.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- EHCacheWrapper.java 18 May 2007 14:32:09 -0000 1.3
+++ EHCacheWrapper.java 21 May 2007 14:00:48 -0000 1.4
@@ -4,6 +4,8 @@
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cachebench.SerializableCacheWrapper;
@@ -11,13 +13,14 @@
import java.io.Serializable;
import java.net.URL;
import java.util.Properties;
+import java.util.StringTokenizer;
/**
* An implementation of SerializableCacheWrapper that uses EHCache as an underlying implementation.
*
* @author Manik Surtani (manik at surtani.org)
- * @version $Id: EHCacheWrapper.java,v 1.3 2007/05/18 14:32:09 msurtani Exp $
+ * @version $Id: EHCacheWrapper.java,v 1.4 2007/05/21 14:00:48 msurtani Exp $
*/
public class EHCacheWrapper implements SerializableCacheWrapper
{
@@ -33,10 +36,57 @@
logger.debug("Initializing the cache with props " + parameters);
URL url = getClass().getClassLoader().getResource(parameters.getProperty("config"));
logger.debug("Config URL = " + url);
- manager = CacheManager.create(url);
+ Configuration c = ConfigurationFactory.parseConfiguration(url);
+ c.setSource("URL of " + url);
+
+ // frig the manager to use a bind address as per sys props
+ String bindAddress = System.getProperty("bind.address");
+
+ if (bindAddress!= null)
+ {
+ String props = c.getCacheManagerPeerListenerFactoryConfiguration().getProperties();
+ props = injectBindAddress(props, bindAddress);
+ c.getCacheManagerPeerListenerFactoryConfiguration().setProperties(props);
+ }
+
+ manager = new CacheManager(c);
+
logger.debug("Finish Initializing the cache");
}
+ private String injectBindAddress(String props, String bindAddress)
+ {
+ String newProps = "hostName=" + bindAddress;
+
+ StringTokenizer st = new StringTokenizer(props, ",", false);
+ while (st.hasMoreTokens())
+ {
+ boolean skip = false;
+ String p = st.nextToken();
+ if (p != null)
+ {
+ p.trim();
+ String[] kv = p.split("=");
+ if (kv[0] != null)
+ {
+ kv[0].trim();
+ if (kv[0].equals("hostName"))
+ skip = true;
+ else
+ newProps += ", " + kv[0];
+ }
+ if (kv[1] != null && !skip)
+ {
+ kv[1].trim();
+ newProps += "=" + kv[1];
+ }
+
+ }
+ }
+
+ return newProps;
+ }
+
/* (non-Javadoc)
* @see org.cachebench.CacheWrapper#setUp()
*/
More information about the jboss-cvs-commits
mailing list