From 37475d9c1f6c5caa1f8f823ec3bcc7f0eee0f3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Wed, 6 Dec 2017 10:03:53 +0100 Subject: [PATCH] HHH-10418 Only create validator if none associated with cache --- .../impl/BaseTransactionalDataRegion.java | 18 +++++++++++------- .../util/CacheCommandInitializer.java | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java index 570620d998..4c3eb5653b 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java @@ -17,11 +17,7 @@ import org.hibernate.cache.infinispan.access.TombstoneCallInterceptor; import org.hibernate.cache.infinispan.access.TxInvalidationCacheAccessDelegate; import org.hibernate.cache.infinispan.access.UnorderedDistributionInterceptor; import org.hibernate.cache.infinispan.access.VersionedCallInterceptor; -import org.hibernate.cache.infinispan.util.Caches; -import org.hibernate.cache.infinispan.util.FutureUpdate; -import org.hibernate.cache.infinispan.util.InfinispanMessageLogger; -import org.hibernate.cache.infinispan.util.Tombstone; -import org.hibernate.cache.infinispan.util.VersionedEntry; +import org.hibernate.cache.infinispan.util.*; import org.hibernate.cache.spi.CacheDataDescription; import org.hibernate.cache.spi.CacheKeysFactory; import org.hibernate.cache.spi.TransactionalDataRegion; @@ -148,8 +144,16 @@ public abstract class BaseTransactionalDataRegion assert strategy == Strategy.VALIDATION; return; } - validator = new PutFromLoadValidator(cache, factory); - strategy = Strategy.VALIDATION; + synchronized (this) { + PutFromLoadValidator found = findValidator(cache); + validator = found != null ? found : new PutFromLoadValidator(cache, factory); + strategy = Strategy.VALIDATION; + } + } + + private PutFromLoadValidator findValidator(AdvancedCache cache) { + CacheCommandInitializer cmdInit = cache.getComponentRegistry().getComponent(CacheCommandInitializer.class); + return cmdInit.findPutFromLoadValidator(cache.getName()); } protected void prepareForVersionedEntries() { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java index a1fd0d218d..9a8e361ed7 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java @@ -48,6 +48,10 @@ public class CacheCommandInitializer implements ModuleCommandInitializer { putFromLoadValidators.put(cacheName, putFromLoadValidator); } + public PutFromLoadValidator findPutFromLoadValidator(String cacheName) { + return putFromLoadValidators.get(cacheName); + } + public PutFromLoadValidator removePutFromLoadValidator(String cacheName) { return putFromLoadValidators.remove(cacheName); }