From 9c55dde59528a3cb52ce438a4f816f6a9f81b7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarre=C3=B1o?= Date: Wed, 28 Mar 2012 20:36:35 +0200 Subject: [PATCH] HHH-7204 Clear only regions created by the given region factory Upgraded to Infinispan 5.1.3.FINAL too. --- .../hibernate-infinispan.gradle | 2 +- .../infinispan/InfinispanRegionFactory.java | 20 +++++++++++++++---- .../infinispan/util/CacheCommandFactory.java | 6 ++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/hibernate-infinispan/hibernate-infinispan.gradle b/hibernate-infinispan/hibernate-infinispan.gradle index 374ad1a9fc..1b2dba6bc8 100644 --- a/hibernate-infinispan/hibernate-infinispan.gradle +++ b/hibernate-infinispan/hibernate-infinispan.gradle @@ -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' ) diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java index 43c7318824..94cb4d3227 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java @@ -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 regionNames = new ArrayList(); /** * 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 factories = (Map) globalCr.getComponent("org.infinispan.modules.command.factories"); for (ModuleCommandFactory factory : factories.values()) { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandFactory.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandFactory.java index 2eb0dfc6e1..8200cdbc68 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandFactory.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandFactory.java @@ -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 regionNames) { + for (String regionName : regionNames) + allRegions.remove(regionName); } @Override