HHH-7204 Clear only regions created by the given region factory
Upgraded to Infinispan 5.1.3.FINAL too.
This commit is contained in:
parent
d159dcef6f
commit
9c55dde595
|
@ -5,7 +5,7 @@ configurations {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
infinispanVersion = '5.1.2.FINAL'
|
infinispanVersion = '5.1.3.FINAL'
|
||||||
jnpVersion = '5.0.3.GA'
|
jnpVersion = '5.0.3.GA'
|
||||||
|
|
||||||
compile project( ':hibernate-core' )
|
compile project( ':hibernate-core' )
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
package org.hibernate.cache.infinispan;
|
package org.hibernate.cache.infinispan;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
|
|
||||||
import org.infinispan.AdvancedCache;
|
import org.infinispan.AdvancedCache;
|
||||||
|
import org.infinispan.Cache;
|
||||||
import org.infinispan.commands.module.ModuleCommandFactory;
|
import org.infinispan.commands.module.ModuleCommandFactory;
|
||||||
import org.infinispan.config.Configuration;
|
import org.infinispan.config.Configuration;
|
||||||
import org.infinispan.factories.GlobalComponentRegistry;
|
import org.infinispan.factories.GlobalComponentRegistry;
|
||||||
|
@ -162,6 +165,8 @@ 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>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance using the default configuration.
|
* Create a new instance using the default configuration.
|
||||||
|
@ -302,7 +307,12 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
log.debug("Clear region references and stop Infinispan cache manager");
|
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();
|
manager.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +346,8 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startRegion(BaseRegion region, String regionName) {
|
private void startRegion(BaseRegion region, String regionName) {
|
||||||
getCacheCommandFactory(region.getCacheAdapter().getCache().getAdvancedCache())
|
regionNames.add(regionName);
|
||||||
|
getCacheCommandFactory(region.getCacheAdapter().getCache())
|
||||||
.addRegion(regionName, region);
|
.addRegion(regionName, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,8 +455,9 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
return createCacheWrapper(cache);
|
return createCacheWrapper(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CacheCommandFactory getCacheCommandFactory(AdvancedCache cache) {
|
private CacheCommandFactory getCacheCommandFactory(Cache cache) {
|
||||||
GlobalComponentRegistry globalCr = cache.getComponentRegistry().getGlobalComponentRegistry();
|
GlobalComponentRegistry globalCr = cache.getAdvancedCache()
|
||||||
|
.getComponentRegistry().getGlobalComponentRegistry();
|
||||||
Map<Byte, ModuleCommandFactory> factories =
|
Map<Byte, ModuleCommandFactory> factories =
|
||||||
(Map<Byte, ModuleCommandFactory>) globalCr.getComponent("org.infinispan.modules.command.factories");
|
(Map<Byte, ModuleCommandFactory>) globalCr.getComponent("org.infinispan.modules.command.factories");
|
||||||
for (ModuleCommandFactory factory : factories.values()) {
|
for (ModuleCommandFactory factory : factories.values()) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.hibernate.cache.infinispan.util;
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -26,8 +27,9 @@ public class CacheCommandFactory implements ExtendedModuleCommandFactory {
|
||||||
allRegions.put(regionName, region);
|
allRegions.put(regionName, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearRegions() {
|
public void clearRegions(List<String> regionNames) {
|
||||||
allRegions.clear();
|
for (String regionName : regionNames)
|
||||||
|
allRegions.remove(regionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue