HHH-7204 Clear only regions created by the given region factory

Upgraded to Infinispan 5.1.3.FINAL too.
This commit is contained in:
Galder Zamarreño 2012-03-28 20:36:35 +02:00
parent d159dcef6f
commit 9c55dde595
3 changed files with 21 additions and 7 deletions

View File

@ -5,7 +5,7 @@ configurations {
}
dependencies {
infinispanVersion = '5.1.2.FINAL'
infinispanVersion = '5.1.3.FINAL'
jnpVersion = '5.0.3.GA'
compile project( ':hibernate-core' )

View File

@ -1,16 +1,19 @@
package org.hibernate.cache.infinispan;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.transaction.TransactionManager;
import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
import org.infinispan.commands.module.ModuleCommandFactory;
import org.infinispan.config.Configuration;
import org.infinispan.factories.GlobalComponentRegistry;
@ -162,6 +165,8 @@ public class InfinispanRegionFactory implements RegionFactory {
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
private TransactionManager transactionManager;
private List<String> regionNames = new ArrayList<String>();
/**
* Create a new instance using the default configuration.
@ -302,7 +307,12 @@ public class InfinispanRegionFactory implements RegionFactory {
*/
public void stop() {
log.debug("Clear region references and stop Infinispan cache manager");
getCacheCommandFactory(manager.getCache().getAdvancedCache()).clearRegions();
getCacheCommandFactory(manager.getCache()).clearRegions(regionNames);
regionNames.clear();
stopCacheManager();
}
protected void stopCacheManager() {
manager.stop();
}
@ -336,7 +346,8 @@ public class InfinispanRegionFactory implements RegionFactory {
}
private void startRegion(BaseRegion region, String regionName) {
getCacheCommandFactory(region.getCacheAdapter().getCache().getAdvancedCache())
regionNames.add(regionName);
getCacheCommandFactory(region.getCacheAdapter().getCache())
.addRegion(regionName, region);
}
@ -444,8 +455,9 @@ public class InfinispanRegionFactory implements RegionFactory {
return createCacheWrapper(cache);
}
private CacheCommandFactory getCacheCommandFactory(AdvancedCache cache) {
GlobalComponentRegistry globalCr = cache.getComponentRegistry().getGlobalComponentRegistry();
private CacheCommandFactory getCacheCommandFactory(Cache cache) {
GlobalComponentRegistry globalCr = cache.getAdvancedCache()
.getComponentRegistry().getGlobalComponentRegistry();
Map<Byte, ModuleCommandFactory> factories =
(Map<Byte, ModuleCommandFactory>) globalCr.getComponent("org.infinispan.modules.command.factories");
for (ModuleCommandFactory factory : factories.values()) {

View File

@ -1,6 +1,7 @@
package org.hibernate.cache.infinispan.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@ -26,8 +27,9 @@ public class CacheCommandFactory implements ExtendedModuleCommandFactory {
allRegions.put(regionName, region);
}
public void clearRegions() {
allRegions.clear();
public void clearRegions(List<String> regionNames) {
for (String regionName : regionNames)
allRegions.remove(regionName);
}
@Override