Author: lryan
Date: Tue Nov 11 11:43:01 2008
New Revision: 713128
URL: http://svn.apache.org/viewvc?rev=713128&view=rev
Log:
Minor refactor to allow for programmatic cache configuration
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java?rev=713128&r1=713127&r2=713128&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
Tue Nov 11 11:43:01 2008
@@ -25,18 +25,18 @@
import com.google.common.collect.Maps;
import com.google.inject.Inject;
import com.google.inject.name.Named;
-
import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
import net.sf.ehcache.management.ManagementService;
+import javax.management.MBeanServer;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.util.Map;
import java.util.logging.Logger;
-import javax.management.MBeanServer;
-
public class EhCacheCacheProvider implements CacheProvider {
private final Logger LOG =
Logger.getLogger(EhCacheCacheProvider.class.getName());
private final CacheManager cacheManager;
@@ -47,11 +47,23 @@
@Named("shindig.cache.ehcache.jmx.enabled")
boolean jmxEnabled,
@Named("shindig.cache.ehcache.jmx.stats")
boolean withCacheStats)
throws IOException {
- InputStream configStream = ResourceLoader.open(configPath);
- cacheManager = new CacheManager(configStream);
+ cacheManager = new CacheManager(getConfiguration(configPath));
create(jmxEnabled, withCacheStats);
}
+ /**
+ * Read the cache conifuration from the specified resource.
+ * This function is intended to be overrideable to allow for programmatic
+ * cache configuration.
+ * @param configPath
+ * @return Configuration
+ * @throws IOException
+ */
+ protected Configuration getConfiguration(String configPath) throws
IOException {
+ InputStream configStream = ResourceLoader.open(configPath);
+ return ConfigurationFactory.parseConfiguration(configStream);
+ }
+
public void create(boolean jmxEnabled, boolean withCacheStats) {
/*
* Add in a shutdown hook