Skip to content

Commit

Permalink
[SM-2109] Fixed a bug which resulted in having CacheManager initializ…
Browse files Browse the repository at this point in the history
…ed 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
  • Loading branch information
iocanel committed Jul 15, 2011
1 parent d695455 commit c6850d5
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.id.IdGenerator; import org.apache.servicemix.id.IdGenerator;
import org.apache.servicemix.store.Store; import org.apache.servicemix.store.Store;
import org.apache.servicemix.store.StoreListener;
import org.apache.servicemix.store.base.BaseStoreFactory; import org.apache.servicemix.store.base.BaseStoreFactory;


/** /**
Expand All @@ -45,7 +46,7 @@ public class EhCacheStoreFactory extends BaseStoreFactory{
private Map<String, EhCacheStore> stores = new HashMap<String, EhCacheStore>(); private Map<String, EhCacheStore> stores = new HashMap<String, EhCacheStore>();


private CacheManagerFactory cacheManagerFactory = new CacheManagerFactory(); private CacheManagerFactory cacheManagerFactory = new CacheManagerFactory();
private CacheManager cacheManager = cacheManagerFactory.build(); private CacheManager cacheManager;


public EhCacheStoreFactory() { public EhCacheStoreFactory() {


Expand All @@ -54,12 +55,21 @@ public EhCacheStoreFactory() {
public synchronized Store open(String name) throws IOException { public synchronized Store open(String name) throws IOException {
EhCacheStore store = stores.get(name); EhCacheStore store = stores.get(name);
if (store == null) { if (store == null) {

if(cacheManager == null) {
cacheManager = cacheManagerFactory.build();
}

Cache cache = cacheManager.getCache(name); Cache cache = cacheManager.getCache(name);
if(cache == null) { if(cache == null) {
cacheManager.addCache(name); cacheManager.addCache(name);
cache = cacheManager.getCache(name); cache = cacheManager.getCache(name);
} }
store = new EhCacheStore(cache,idGenerator, name); store = new EhCacheStore(cache,idGenerator, name);

for(StoreListener listener:storeListeners) {
store.addListener(listener);
}
stores.put(name, store); stores.put(name, store);
} }
return store; return store;
Expand Down

0 comments on commit c6850d5

Please sign in to comment.