Individual regions currently use the same implementation as InfinispanRegionFactory for the next timestamp. Get them to actually call InfinispanRegionFactory to make it easier for users to provide diff implementations if desired.
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18618 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b34bb068a7
commit
671d9db8e2
|
@ -162,7 +162,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
log.debug("Building collection cache region [" + regionName + "]");
|
||||
Cache cache = getCache(regionName, COLLECTION_KEY, properties);
|
||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
||||
CollectionRegionImpl region = new CollectionRegionImpl(cacheAdapter, regionName, metadata, transactionManager);
|
||||
CollectionRegionImpl region = new CollectionRegionImpl(cacheAdapter, regionName, metadata, transactionManager, this);
|
||||
region.start();
|
||||
return region;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
if (log.isDebugEnabled()) log.debug("Building entity cache region [" + regionName + "]");
|
||||
Cache cache = getCache(regionName, ENTITY_KEY, properties);
|
||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
|
||||
EntityRegionImpl region = new EntityRegionImpl(cacheAdapter, regionName, metadata, transactionManager);
|
||||
EntityRegionImpl region = new EntityRegionImpl(cacheAdapter, regionName, metadata, transactionManager, this);
|
||||
region.start();
|
||||
return region;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
log.debug("Building query results cache region [" + regionName + "]");
|
||||
String cacheName = typeOverrides.get(QUERY_KEY).getCacheName();
|
||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(manager.getCache(cacheName));
|
||||
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager);
|
||||
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
|
||||
region.start();
|
||||
return region;
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
log.debug("Building timestamps cache region [" + regionName + "]");
|
||||
String cacheName = typeOverrides.get(TIMESTAMPS_KEY).getCacheName();
|
||||
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(manager.getCache(cacheName));
|
||||
TimestampsRegionImpl region = new TimestampsRegionImpl(cacheAdapter, regionName, transactionManager);
|
||||
TimestampsRegionImpl region = new TimestampsRegionImpl(cacheAdapter, regionName, transactionManager, this);
|
||||
region.start();
|
||||
return region;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import javax.transaction.TransactionManager;
|
|||
import org.hibernate.cache.CacheDataDescription;
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.CollectionRegion;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.access.AccessType;
|
||||
import org.hibernate.cache.access.CollectionRegionAccessStrategy;
|
||||
import org.hibernate.cache.infinispan.access.PutFromLoadValidator;
|
||||
|
@ -20,8 +21,9 @@ import org.infinispan.notifications.Listener;
|
|||
@Listener
|
||||
public class CollectionRegionImpl extends BaseTransactionalDataRegion implements CollectionRegion {
|
||||
|
||||
public CollectionRegionImpl(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata, TransactionManager transactionManager) {
|
||||
super(cacheAdapter, name, metadata, transactionManager);
|
||||
public CollectionRegionImpl(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata,
|
||||
TransactionManager transactionManager, RegionFactory factory) {
|
||||
super(cacheAdapter, name, metadata, transactionManager, factory);
|
||||
}
|
||||
|
||||
public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
|
||||
|
|
|
@ -5,6 +5,7 @@ import javax.transaction.TransactionManager;
|
|||
import org.hibernate.cache.CacheDataDescription;
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.EntityRegion;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.access.AccessType;
|
||||
import org.hibernate.cache.access.EntityRegionAccessStrategy;
|
||||
import org.hibernate.cache.infinispan.access.PutFromLoadValidator;
|
||||
|
@ -20,8 +21,9 @@ import org.infinispan.notifications.Listener;
|
|||
@Listener
|
||||
public class EntityRegionImpl extends BaseTransactionalDataRegion implements EntityRegion {
|
||||
|
||||
public EntityRegionImpl(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata, TransactionManager transactionManager) {
|
||||
super(cacheAdapter, name, metadata, transactionManager);
|
||||
public EntityRegionImpl(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata,
|
||||
TransactionManager transactionManager, RegionFactory factory) {
|
||||
super(cacheAdapter, name, metadata, transactionManager, factory);
|
||||
}
|
||||
|
||||
public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
|
||||
|
|
|
@ -4,6 +4,7 @@ import javax.transaction.TransactionManager;
|
|||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.GeneralDataRegion;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||
|
||||
/**
|
||||
|
@ -15,8 +16,8 @@ import org.hibernate.cache.infinispan.util.CacheAdapter;
|
|||
*/
|
||||
public abstract class BaseGeneralDataRegion extends BaseRegion implements GeneralDataRegion {
|
||||
|
||||
public BaseGeneralDataRegion(CacheAdapter cacheAdapter, String name, TransactionManager transactionManager) {
|
||||
super(cacheAdapter, name, transactionManager);
|
||||
public BaseGeneralDataRegion(CacheAdapter cacheAdapter, String name, TransactionManager transactionManager, RegionFactory factory) {
|
||||
super(cacheAdapter, name, transactionManager, factory);
|
||||
}
|
||||
|
||||
public void evict(Object key) throws CacheException {
|
||||
|
|
|
@ -14,6 +14,7 @@ import javax.transaction.TransactionManager;
|
|||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.Region;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.infinispan.util.AddressAdapter;
|
||||
import org.hibernate.cache.infinispan.util.AddressAdapterImpl;
|
||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||
|
@ -48,14 +49,16 @@ public abstract class BaseRegion implements Region {
|
|||
protected final boolean replication;
|
||||
protected final Object invalidationMutex = new Object();
|
||||
protected final AtomicReference<InvalidateState> invalidateState = new AtomicReference<InvalidateState>(InvalidateState.VALID);
|
||||
private final RegionFactory factory;
|
||||
|
||||
public BaseRegion(CacheAdapter cacheAdapter, String name, TransactionManager transactionManager) {
|
||||
public BaseRegion(CacheAdapter cacheAdapter, String name, TransactionManager transactionManager, RegionFactory factory) {
|
||||
this.cacheAdapter = cacheAdapter;
|
||||
this.name = name;
|
||||
this.transactionManager = transactionManager;
|
||||
this.replication = cacheAdapter.isClusteredReplication();
|
||||
this.address = this.cacheAdapter.getAddress();
|
||||
this.cacheAdapter.addListener(this);
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
@ -126,7 +129,7 @@ public abstract class BaseRegion implements Region {
|
|||
}
|
||||
|
||||
public long nextTimestamp() {
|
||||
return System.currentTimeMillis() / 100;
|
||||
return factory.nextTimestamp();
|
||||
}
|
||||
|
||||
public Map toMap() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.hibernate.cache.infinispan.impl;
|
|||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.cache.CacheDataDescription;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.TransactionalDataRegion;
|
||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||
|
||||
|
@ -17,8 +18,8 @@ public abstract class BaseTransactionalDataRegion extends BaseRegion implements
|
|||
|
||||
private final CacheDataDescription metadata;
|
||||
|
||||
public BaseTransactionalDataRegion(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata, TransactionManager transactionManager) {
|
||||
super(cacheAdapter, name, transactionManager);
|
||||
public BaseTransactionalDataRegion(CacheAdapter cacheAdapter, String name, CacheDataDescription metadata, TransactionManager transactionManager, RegionFactory factory) {
|
||||
super(cacheAdapter, name, transactionManager, factory);
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import javax.transaction.TransactionManager;
|
|||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.QueryResultsRegion;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.infinispan.impl.BaseTransactionalDataRegion;
|
||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||
import org.hibernate.cache.infinispan.util.CacheHelper;
|
||||
|
@ -22,9 +23,8 @@ import org.infinispan.notifications.Listener;
|
|||
public class QueryResultsRegionImpl extends BaseTransactionalDataRegion implements QueryResultsRegion {
|
||||
private boolean localOnly;
|
||||
|
||||
public QueryResultsRegionImpl(CacheAdapter cacheAdapter, String name, Properties properties, TransactionManager transactionManager) {
|
||||
super(cacheAdapter, name, null, transactionManager);
|
||||
|
||||
public QueryResultsRegionImpl(CacheAdapter cacheAdapter, String name, Properties properties, TransactionManager transactionManager, RegionFactory factory) {
|
||||
super(cacheAdapter, name, null, transactionManager, factory);
|
||||
// If Infinispan is using INVALIDATION for query cache, we don't want to propagate changes.
|
||||
// We use the Timestamps cache to manage invalidation
|
||||
localOnly = cacheAdapter.isClusteredInvalidation();
|
||||
|
|
|
@ -8,6 +8,7 @@ import javax.transaction.Transaction;
|
|||
import javax.transaction.TransactionManager;
|
||||
|
||||
import org.hibernate.cache.CacheException;
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
import org.hibernate.cache.TimestampsRegion;
|
||||
import org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion;
|
||||
import org.hibernate.cache.infinispan.util.CacheAdapter;
|
||||
|
@ -32,8 +33,8 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times
|
|||
|
||||
private Map localCache = new ConcurrentHashMap();
|
||||
|
||||
public TimestampsRegionImpl(CacheAdapter cacheAdapter, String name, TransactionManager transactionManager) {
|
||||
super(cacheAdapter, name, transactionManager);
|
||||
public TimestampsRegionImpl(CacheAdapter cacheAdapter, String name, TransactionManager transactionManager, RegionFactory factory) {
|
||||
super(cacheAdapter, name, transactionManager, factory);
|
||||
cacheAdapter.addListener(this);
|
||||
populateLocalCache();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue