Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] HHH-10545, HHH-10546 InfinispanRegionFactory fixes #1269

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -280,7 +280,7 @@ public void validate(Configuration configuration) {
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
private TransactionManager transactionManager;

private List<String> regionNames = new ArrayList<String>();
private List<BaseRegion> regions = new ArrayList<>();
private SessionFactoryOptions settings;

private Boolean globalStats;
Expand Down Expand Up @@ -310,7 +310,7 @@ public CollectionRegion buildCollectionRegion(
}
final AdvancedCache cache = getCache( regionName, DataType.COLLECTION, metadata);
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
startRegion( region, regionName );
startRegion( region );
return region;
}

Expand All @@ -327,7 +327,7 @@ public EntityRegion buildEntityRegion(String regionName, Properties properties,
}
final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? DataType.ENTITY : DataType.IMMUTABLE_ENTITY, metadata );
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
startRegion( region, regionName );
startRegion( region );
return region;
}

Expand All @@ -339,7 +339,7 @@ public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties proper
}
final AdvancedCache cache = getCache( regionName, DataType.NATURAL_ID, metadata);
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory());
startRegion( region, regionName );
startRegion( region );
return region;
}

Expand All @@ -352,7 +352,7 @@ public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties

final AdvancedCache cache = getCache( regionName, DataType.QUERY, null);
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, transactionManager, this );
startRegion( region, regionName );
startRegion( region );
return region;
}

Expand All @@ -364,7 +364,7 @@ public TimestampsRegion buildTimestampsRegion(String regionName, Properties prop
}
final AdvancedCache cache = getCache( regionName, DataType.TIMESTAMPS, null);
final TimestampsRegionImpl region = createTimestampsRegion( cache, regionName );
startRegion( region, regionName );
startRegion( region );
return region;
}

Expand Down Expand Up @@ -495,9 +495,13 @@ public void stop() {

protected void stopCacheRegions() {
log.debug( "Clear region references" );
getCacheCommandFactory( manager.getCache().getAdvancedCache() )
.clearRegions( regionNames );
regionNames.clear();
getCacheCommandFactory().clearRegions( regions );
// Ensure we cleanup any caches we created
regions.forEach( region -> {
region.getCache().stop();
manager.undefineConfiguration( region.getCache().getName() );
} );
regions.clear();
}

protected void stopCacheManager() {
Expand Down Expand Up @@ -555,9 +559,9 @@ private static ConfigurationBuilderHolder parseWithOverridenClassLoader(ParserRe
}
}

private void startRegion(BaseRegion region, String regionName) {
regionNames.add( regionName );
getCacheCommandFactory( region.getCache() ).addRegion( regionName, region );
private void startRegion(BaseRegion region) {
regions.add( region );
getCacheCommandFactory().addRegion( region );
}

private void parseProperty(int prefixLoc, String key, String value) {
Expand Down Expand Up @@ -689,8 +693,8 @@ protected AdvancedCache getCache(String regionName, DataType type, CacheDataDesc
return createCacheWrapper( cache );
}

private CacheCommandFactory getCacheCommandFactory(AdvancedCache cache) {
final GlobalComponentRegistry globalCr = cache.getComponentRegistry().getGlobalComponentRegistry();
private CacheCommandFactory getCacheCommandFactory() {
final GlobalComponentRegistry globalCr = manager.getGlobalComponentRegistry();

final Map<Byte, ModuleCommandFactory> factories =
(Map<Byte, ModuleCommandFactory>) globalCr.getComponent( "org.infinispan.modules.command.factories" );
Expand Down
Expand Up @@ -6,8 +6,8 @@
*/
package org.hibernate.cache.infinispan.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -39,19 +39,17 @@ public class CacheCommandFactory implements ExtendedModuleCommandFactory {
* @param regionName name of the region
* @param region instance to keep track of
*/
public void addRegion(String regionName, BaseRegion region) {
allRegions.put( regionName, region );
public void addRegion(BaseRegion region) {
allRegions.put( region.getName(), region );
}

/**
* Clear all regions from this command factory.
*
* @param regionNames collection of regions to clear
*/
public void clearRegions(List<String> regionNames) {
for ( String regionName : regionNames ) {
allRegions.remove( regionName );
}
public void clearRegions(Collection<BaseRegion> regions) {
regions.forEach( region -> allRegions.remove( region.getName() ) );
}

@Override
Expand Down