HHH-7007 Evict all should work now in multi-region factory environments
This commit is contained in:
parent
5eee526234
commit
13c9dbfc21
|
@ -8,13 +8,10 @@ import java.util.HashSet;
|
||||||
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 java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import javax.transaction.TransactionManager;
|
import javax.transaction.TransactionManager;
|
||||||
|
|
||||||
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
||||||
import org.hibernate.cache.infinispan.util.CacheCommandFactory;
|
import org.hibernate.cache.infinispan.util.CacheCommandFactory;
|
||||||
import org.hibernate.cache.infinispan.util.CacheCommandInitializer;
|
|
||||||
import org.hibernate.cache.spi.CacheDataDescription;
|
import org.hibernate.cache.spi.CacheDataDescription;
|
||||||
import org.hibernate.cache.CacheException;
|
import org.hibernate.cache.CacheException;
|
||||||
import org.hibernate.cache.spi.CollectionRegion;
|
import org.hibernate.cache.spi.CollectionRegion;
|
||||||
|
@ -36,7 +33,6 @@ import org.hibernate.cfg.Settings;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.infinispan.AdvancedCache;
|
import org.infinispan.AdvancedCache;
|
||||||
import org.infinispan.config.Configuration;
|
import org.infinispan.config.Configuration;
|
||||||
import org.infinispan.factories.ComponentRegistry;
|
|
||||||
import org.infinispan.factories.GlobalComponentRegistry;
|
import org.infinispan.factories.GlobalComponentRegistry;
|
||||||
import org.infinispan.manager.DefaultCacheManager;
|
import org.infinispan.manager.DefaultCacheManager;
|
||||||
import org.infinispan.manager.EmbeddedCacheManager;
|
import org.infinispan.manager.EmbeddedCacheManager;
|
||||||
|
@ -164,9 +160,6 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
|
|
||||||
private TransactionManager transactionManager;
|
private TransactionManager transactionManager;
|
||||||
|
|
||||||
private ConcurrentMap<String, BaseRegion> allRegions =
|
|
||||||
new ConcurrentHashMap<String, BaseRegion>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance using the default configuration.
|
* Create a new instance using the default configuration.
|
||||||
*/
|
*/
|
||||||
|
@ -299,7 +292,8 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
log.debug("Stopping Infinispan CacheManager");
|
log.debug("Clear region references and stop Infinispan cache manager");
|
||||||
|
getCacheCommandFactory(manager.getCache().getAdvancedCache()).clearRegions();
|
||||||
manager.stop();
|
manager.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,10 +311,6 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
return Collections.unmodifiableSet(definedConfigurations);
|
return Collections.unmodifiableSet(definedConfigurations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseRegion getRegion(String regionName) {
|
|
||||||
return allRegions.get(regionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
|
protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
|
||||||
try {
|
try {
|
||||||
String configLoc = ConfigurationHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
|
String configLoc = ConfigurationHelper.getString(INFINISPAN_CONFIG_RESOURCE_PROP, properties, DEF_INFINISPAN_CONFIG_RESOURCE);
|
||||||
|
@ -337,7 +327,8 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startRegion(BaseRegion region, String regionName) {
|
private void startRegion(BaseRegion region, String regionName) {
|
||||||
allRegions.put(regionName, region);
|
getCacheCommandFactory(region.getCacheAdapter().getCache().getAdvancedCache())
|
||||||
|
.addRegion(regionName, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, TypeOverrides> initGenericDataTypeOverrides() {
|
private Map<String, TypeOverrides> initGenericDataTypeOverrides() {
|
||||||
|
@ -441,13 +432,14 @@ public class InfinispanRegionFactory implements RegionFactory {
|
||||||
if (!cache.getStatus().allowInvocations()) {
|
if (!cache.getStatus().allowInvocations()) {
|
||||||
cache.start();
|
cache.start();
|
||||||
}
|
}
|
||||||
ComponentRegistry cr = cache.getComponentRegistry();
|
return createCacheWrapper(cache);
|
||||||
cr.getComponent(CacheCommandInitializer.class).setRegionFactory(this);
|
}
|
||||||
|
|
||||||
|
private CacheCommandFactory getCacheCommandFactory(AdvancedCache cache) {
|
||||||
GlobalComponentRegistry globalCr = cache.getComponentRegistry().getGlobalComponentRegistry();
|
GlobalComponentRegistry globalCr = cache.getComponentRegistry().getGlobalComponentRegistry();
|
||||||
// TODO: This is a hack, make it easier to retrieve in Infinispan!
|
// TODO: This is a hack, make it easier to retrieve in Infinispan!
|
||||||
((CacheCommandFactory) ((Map) globalCr.getComponent("org.infinispan.modules.command.factories"))
|
return (CacheCommandFactory) ((Map) globalCr.getComponent("org.infinispan.modules.command.factories"))
|
||||||
.values().iterator().next()).setRegionFactory(this);
|
.values().iterator().next();
|
||||||
return createCacheWrapper(cache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
|
protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package org.hibernate.cache.infinispan.util;
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
||||||
|
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
||||||
import org.infinispan.commands.ReplicableCommand;
|
import org.infinispan.commands.ReplicableCommand;
|
||||||
import org.infinispan.commands.module.ExtendedModuleCommandFactory;
|
import org.infinispan.commands.module.ExtendedModuleCommandFactory;
|
||||||
import org.infinispan.commands.remote.CacheRpcCommand;
|
import org.infinispan.commands.remote.CacheRpcCommand;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command factory
|
* Command factory
|
||||||
|
@ -16,10 +19,15 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class CacheCommandFactory implements ExtendedModuleCommandFactory {
|
public class CacheCommandFactory implements ExtendedModuleCommandFactory {
|
||||||
|
|
||||||
private InfinispanRegionFactory regionFactory;
|
private ConcurrentMap<String, BaseRegion> allRegions =
|
||||||
|
new ConcurrentHashMap<String, BaseRegion>();
|
||||||
|
|
||||||
public void setRegionFactory(InfinispanRegionFactory regionFactory) {
|
public void addRegion(String regionName, BaseRegion region) {
|
||||||
this.regionFactory = regionFactory;
|
allRegions.put(regionName, region);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearRegions() {
|
||||||
|
allRegions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +42,7 @@ public class CacheCommandFactory implements ExtendedModuleCommandFactory {
|
||||||
CacheRpcCommand c;
|
CacheRpcCommand c;
|
||||||
switch (commandId) {
|
switch (commandId) {
|
||||||
case CacheCommandIds.EVICT_ALL:
|
case CacheCommandIds.EVICT_ALL:
|
||||||
c = new EvictAllCommand(cacheName, regionFactory);
|
c = new EvictAllCommand(cacheName, allRegions.get(cacheName));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Not registered to handle command id " + commandId);
|
throw new IllegalArgumentException("Not registered to handle command id " + commandId);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.hibernate.cache.infinispan.util;
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
|
||||||
import org.infinispan.commands.ReplicableCommand;
|
import org.infinispan.commands.ReplicableCommand;
|
||||||
import org.infinispan.commands.module.ModuleCommandInitializer;
|
import org.infinispan.commands.module.ModuleCommandInitializer;
|
||||||
|
|
||||||
|
@ -12,14 +11,12 @@ import org.infinispan.commands.module.ModuleCommandInitializer;
|
||||||
*/
|
*/
|
||||||
public class CacheCommandInitializer implements ModuleCommandInitializer {
|
public class CacheCommandInitializer implements ModuleCommandInitializer {
|
||||||
|
|
||||||
private InfinispanRegionFactory regionFactory;
|
|
||||||
|
|
||||||
public void setRegionFactory(InfinispanRegionFactory regionFactory) {
|
|
||||||
this.regionFactory = regionFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EvictAllCommand buildEvictAllCommand(String regionName) {
|
public EvictAllCommand buildEvictAllCommand(String regionName) {
|
||||||
return new EvictAllCommand(regionName, regionFactory);
|
// No need to pass region factory because no information on that object
|
||||||
|
// is sent around the cluster. However, when the command factory builds
|
||||||
|
// and evict all command remotely, it does need to initialize it with
|
||||||
|
// the right region factory so that it can call it back.
|
||||||
|
return new EvictAllCommand(regionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.hibernate.cache.infinispan.util;
|
package org.hibernate.cache.infinispan.util;
|
||||||
|
|
||||||
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
|
||||||
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
import org.hibernate.cache.infinispan.impl.BaseRegion;
|
||||||
import org.infinispan.commands.remote.BaseRpcCommand;
|
import org.infinispan.commands.remote.BaseRpcCommand;
|
||||||
import org.infinispan.context.InvocationContext;
|
import org.infinispan.context.InvocationContext;
|
||||||
|
@ -13,16 +12,19 @@ import org.infinispan.context.InvocationContext;
|
||||||
*/
|
*/
|
||||||
public class EvictAllCommand extends BaseRpcCommand {
|
public class EvictAllCommand extends BaseRpcCommand {
|
||||||
|
|
||||||
private InfinispanRegionFactory regionFactory;
|
private final BaseRegion region;
|
||||||
|
|
||||||
public EvictAllCommand(String regionName, InfinispanRegionFactory regionFactory) {
|
public EvictAllCommand(String regionName, BaseRegion region) {
|
||||||
super(regionName); // region name and cache names are the same...
|
super(regionName); // region name and cache names are the same...
|
||||||
this.regionFactory = regionFactory;
|
this.region = region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EvictAllCommand(String regionName) {
|
||||||
|
this(regionName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object perform(InvocationContext ctx) throws Throwable {
|
public Object perform(InvocationContext ctx) throws Throwable {
|
||||||
BaseRegion region = regionFactory.getRegion(cacheName);
|
|
||||||
region.invalidateRegion();
|
region.invalidateRegion();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue