HHH-10546 InfinispanRegionFactory should stop any caches it starts

This commit is contained in:
Paul Ferraro 2016-02-19 10:01:40 -05:00 committed by Gail Badner
parent 627ecb97b0
commit 213478fc7d
2 changed files with 21 additions and 17 deletions

View File

@ -238,7 +238,7 @@ public class InfinispanRegionFactory implements RegionFactory {
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup; private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
private TransactionManager transactionManager; private TransactionManager transactionManager;
private List<String> regionNames = new ArrayList<String>(); private List<BaseRegion> regions = new ArrayList<BaseRegion>();
private SessionFactoryOptions settings; private SessionFactoryOptions settings;
/** /**
@ -266,7 +266,7 @@ public class InfinispanRegionFactory implements RegionFactory {
} }
final AdvancedCache cache = getCache( regionName, COLLECTION_KEY, properties, metadata); final AdvancedCache cache = getCache( regionName, COLLECTION_KEY, properties, metadata);
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() ); final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
startRegion( region, regionName ); startRegion( region );
return region; return region;
} }
@ -283,7 +283,7 @@ public class InfinispanRegionFactory implements RegionFactory {
} }
final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? ENTITY_KEY : IMMUTABLE_ENTITY_KEY, properties, metadata ); final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? ENTITY_KEY : IMMUTABLE_ENTITY_KEY, properties, metadata );
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() ); final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
startRegion( region, regionName ); startRegion( region );
return region; return region;
} }
@ -295,7 +295,7 @@ public class InfinispanRegionFactory implements RegionFactory {
} }
final AdvancedCache cache = getCache( regionName, NATURAL_ID_KEY, properties, metadata); final AdvancedCache cache = getCache( regionName, NATURAL_ID_KEY, properties, metadata);
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory()); final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory());
startRegion( region, regionName ); startRegion( region );
return region; return region;
} }
@ -313,7 +313,7 @@ public class InfinispanRegionFactory implements RegionFactory {
final AdvancedCache cache = getCache( cacheName, QUERY_KEY, properties, null); final AdvancedCache cache = getCache( cacheName, QUERY_KEY, properties, null);
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, transactionManager, this ); final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, transactionManager, this );
startRegion( region, regionName ); startRegion( region );
return region; return region;
} }
@ -325,7 +325,7 @@ public class InfinispanRegionFactory implements RegionFactory {
} }
final AdvancedCache cache = getCache( regionName, TIMESTAMPS_KEY, properties, null); final AdvancedCache cache = getCache( regionName, TIMESTAMPS_KEY, properties, null);
final TimestampsRegionImpl region = createTimestampsRegion( cache, regionName ); final TimestampsRegionImpl region = createTimestampsRegion( cache, regionName );
startRegion( region, regionName ); startRegion( region );
return region; return region;
} }
@ -430,8 +430,12 @@ public class InfinispanRegionFactory implements RegionFactory {
protected void stopCacheRegions() { protected void stopCacheRegions() {
log.debug( "Clear region references" ); log.debug( "Clear region references" );
getCacheCommandFactory().clearRegions( regionNames ); getCacheCommandFactory().clearRegions( regions );
regionNames.clear(); // Ensure we cleanup any caches we created
for ( BaseRegion region : regions ) {
region.getCache().stop();
}
regions.clear();
} }
protected void stopCacheManager() { protected void stopCacheManager() {
@ -528,9 +532,9 @@ public class InfinispanRegionFactory implements RegionFactory {
return new DefaultCacheManager( holder, true ); return new DefaultCacheManager( holder, true );
} }
private void startRegion(BaseRegion region, String regionName) { private void startRegion(BaseRegion region) {
regionNames.add( regionName ); regions.add( region );
getCacheCommandFactory().addRegion( regionName, region ); getCacheCommandFactory().addRegion( region );
} }
private Map<String, TypeOverrides> initGenericDataTypeOverrides() { private Map<String, TypeOverrides> initGenericDataTypeOverrides() {

View File

@ -6,8 +6,8 @@
*/ */
package org.hibernate.cache.infinispan.util; package org.hibernate.cache.infinispan.util;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -39,8 +39,8 @@ public class CacheCommandFactory implements ExtendedModuleCommandFactory {
* @param regionName name of the region * @param regionName name of the region
* @param region instance to keep track of * @param region instance to keep track of
*/ */
public void addRegion(String regionName, BaseRegion region) { public void addRegion(BaseRegion region) {
allRegions.put( regionName, region ); allRegions.put( region.getName(), region );
} }
/** /**
@ -48,9 +48,9 @@ public class CacheCommandFactory implements ExtendedModuleCommandFactory {
* *
* @param regionNames collection of regions to clear * @param regionNames collection of regions to clear
*/ */
public void clearRegions(List<String> regionNames) { public void clearRegions(Collection<BaseRegion> regions) {
for ( String regionName : regionNames ) { for ( BaseRegion region : regions ) {
allRegions.remove( regionName ); allRegions.remove( region.getName() );
} }
} }