[SM-2109] Fixed a bug which resulted in having CacheManager initialized always using the default factory . StoreFactory now properly sets listeners to the store.
git-svn-id: https://svn.apache.org/repos/asf/servicemix/utils/trunk@1147077 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/servicemix/store/ehcache/EhCacheStoreFactory.java b/src/main/java/org/apache/servicemix/store/ehcache/EhCacheStoreFactory.java
index ea41750..b76e955 100644
--- a/src/main/java/org/apache/servicemix/store/ehcache/EhCacheStoreFactory.java
+++ b/src/main/java/org/apache/servicemix/store/ehcache/EhCacheStoreFactory.java
@@ -32,6 +32,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.id.IdGenerator;
import org.apache.servicemix.store.Store;
+import org.apache.servicemix.store.StoreListener;
import org.apache.servicemix.store.base.BaseStoreFactory;
/**
@@ -45,7 +46,7 @@
private Map<String, EhCacheStore> stores = new HashMap<String, EhCacheStore>();
private CacheManagerFactory cacheManagerFactory = new CacheManagerFactory();
- private CacheManager cacheManager = cacheManagerFactory.build();
+ private CacheManager cacheManager;
public EhCacheStoreFactory() {
@@ -54,12 +55,21 @@
public synchronized Store open(String name) throws IOException {
EhCacheStore store = stores.get(name);
if (store == null) {
+
+ if(cacheManager == null) {
+ cacheManager = cacheManagerFactory.build();
+ }
+
Cache cache = cacheManager.getCache(name);
if(cache == null) {
cacheManager.addCache(name);
cache = cacheManager.getCache(name);
}
store = new EhCacheStore(cache,idGenerator, name);
+
+ for(StoreListener listener:storeListeners) {
+ store.addListener(listener);
+ }
stores.put(name, store);
}
return store;