@Override public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { RLock writeLock = mapCache.getReadWriteLock(key).writeLock(); writeLock.lock(); try { Lockable item = (Lockable) region.get(session, key); Comparator<Object> comparator = ((TransactionalDataRegion)region).getCacheDataDescription().getVersionComparator(); boolean writeable = item == null || item.isWriteable(txTimestamp, version, comparator); if (writeable) { region.put(session, key, new Item(value, version, region.nextTimestamp())); return true; } return false; } finally { writeLock.unlock(); } }
public IMapRegionCache(final String name, final HazelcastInstance hazelcastInstance, final Properties props, final CacheDataDescription metadata) { this.name = name; this.hazelcastInstance = hazelcastInstance; this.versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; this.map = hazelcastInstance.getMap(this.name); lockTimeout = CacheEnvironment.getLockTimeoutInMillis(props); final long maxOperationTimeout = HazelcastTimestamper.getMaxOperationTimeout(hazelcastInstance); tryLockAndGetTimeout = Math.min(maxOperationTimeout, COMPARISON_VALUE); markerIdCounter = new AtomicLong(); }
@Override public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { checkAccessType(accessType); AccessDelegate accessDelegate = createAccessDelegate(accessType); if ( accessType == AccessType.READ_ONLY || !getCacheDataDescription().isMutable() ) { return new ReadOnlyAccess( this, accessDelegate ); } else { return new ReadWriteAccess( this, accessDelegate ); } } }
@Override public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) { if ( log.isDebugEnabled() ) { log.debugf( "Building entity cache region [%s] (mutable=%s, versioned=%s)", regionName, metadata.isMutable(), metadata.isVersioned() ); } final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? DataType.ENTITY : DataType.IMMUTABLE_ENTITY, metadata ); final EntityRegion region = new EntityRegionImpl(cache, regionName, transactionManager, metadata, this, getCacheKeysFactory()); startRegion((BaseRegion) region); return region; }
public IMapRegionCache(final String name, final HazelcastInstance hazelcastInstance, final Properties props, final CacheDataDescription metadata) { this.name = name; this.hazelcastInstance = hazelcastInstance; this.versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; this.map = hazelcastInstance.getMap(this.name); lockTimeout = CacheEnvironment.getLockTimeoutInMillis(props); final long maxOperationTimeout = HazelcastTimestamper.getMaxOperationTimeout(hazelcastInstance); tryLockAndGetTimeout = Math.min(maxOperationTimeout, COMPARISON_VALUE); markerIdCounter = new AtomicLong(); }
@Override public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException { checkAccessType( accessType ); AccessDelegate accessDelegate = createAccessDelegate(accessType); if ( accessType == AccessType.READ_ONLY || !getCacheDataDescription().isMutable() ) { return new ReadOnlyAccess( this, accessDelegate ); } else { return new ReadWriteAccess( this, accessDelegate ); } } }
@Override public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { RLock writeLock = mapCache.getReadWriteLock(key).writeLock(); writeLock.lock(); try { Lockable item = (Lockable) region.get(session, key); Comparator<Object> comparator = ((TransactionalDataRegion)region).getCacheDataDescription().getVersionComparator(); boolean writeable = item == null || item.isWriteable(txTimestamp, version, comparator); if (writeable) { region.put(session, key, new Item(value, version, region.nextTimestamp())); return true; } return false; } finally { writeLock.unlock(); } }
public IMapRegionCache(final String name, final HazelcastInstance hazelcastInstance, final Properties props, final CacheDataDescription metadata) { this.name = name; this.hazelcastInstance = hazelcastInstance; this.versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; this.map = hazelcastInstance.getMap(this.name); lockTimeout = CacheEnvironment.getLockTimeoutInMillis(props); final long maxOperationTimeout = HazelcastTimestamper.getMaxOperationTimeout(hazelcastInstance); tryLockAndGetTimeout = Math.min(maxOperationTimeout, COMPARISON_VALUE); markerIdCounter = new AtomicLong(); }
@Override public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(RedisCollectionRegion collectionRegion, AccessType accessType) { switch (accessType) { case READ_ONLY: if (collectionRegion.getCacheDataDescription().isMutable()) { log.warn("read-only cache configured for mutable entity collectionRegionName=[{}]", collectionRegion.getName()); } return new ReadOnlyRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); case READ_WRITE: return new ReadWriteRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); case NONSTRICT_READ_WRITE: return new NonStrictReadWriteRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); case TRANSACTIONAL: return new TransactionalRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); default: throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); } }
@Override public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { RLock writeLock = mapCache.getReadWriteLock(key).writeLock(); writeLock.lock(); try { Lockable item = (Lockable) region.get(key); Comparator<Object> comparator = ((TransactionalDataRegion)region).getCacheDataDescription().getVersionComparator(); boolean writeable = item == null || item.isWriteable(txTimestamp, version, comparator); if (writeable) { region.put(key, new Item(value, version, region.nextTimestamp())); return true; } return false; } finally { writeLock.unlock(); } }
public IMapRegionCache(final String name, final HazelcastInstance hazelcastInstance, final Properties props, final CacheDataDescription metadata) { this.name = name; this.hazelcastInstance = hazelcastInstance; this.versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; this.map = hazelcastInstance.getMap(this.name); lockTimeout = CacheEnvironment.getLockTimeoutInMillis(props); final long maxOperationTimeout = HazelcastTimestamper.getMaxOperationTimeout(hazelcastInstance); tryLockAndGetTimeout = Math.min(maxOperationTimeout, COMPARISON_VALUE); markerIdCounter = new AtomicLong(); }
@Override public EntityRegionAccessStrategy createEntityRegionAccessStrategy(RedisEntityRegion entityRegion, AccessType accessType) { switch (accessType) { case READ_ONLY: if (entityRegion.getCacheDataDescription().isMutable()) { log.warn("read-only cache configured for mutable entity regionName=[{}]", entityRegion.getName()); } return new ReadOnlyRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); case READ_WRITE: return new ReadWriteRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); case NONSTRICT_READ_WRITE: return new NonStrictReadWriteRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); case TRANSACTIONAL: return new TransactionalRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); default: throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); } }
@Override public Comparator<Object> getComparator(String subclass) { return metadata.getVersionComparator(); }
/** * @param name the name for this region cache, which is also used to retrieve configuration/topic * @param hazelcastInstance the {@code HazelcastInstance} to which this region cache belongs, used to retrieve * configuration and to lookup an {@link ITopic} to register a {@link MessageListener} * with if {@code withTopic} is {@code true} (optional) * @param metadata metadata describing the cached data, used to compare data versions (optional) * @param withTopic {@code true} to register a {@link MessageListener} with the {@link ITopic} whose name * matches this region cache <i>if</i> a {@code HazelcastInstance} was provided to look * up the topic; otherwise, {@code false} not to register a listener even if an instance * was provided */ public LocalRegionCache(final String name, final HazelcastInstance hazelcastInstance, final CacheDataDescription metadata, final boolean withTopic) { this.hazelcastInstance = hazelcastInstance; try { config = hazelcastInstance != null ? hazelcastInstance.getConfig().findMapConfig(name) : null; } catch (UnsupportedOperationException ignored) { EmptyStatement.ignore(ignored); } versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; cache = new ConcurrentHashMap<Object, Expirable>(); markerIdCounter = new AtomicLong(); messageListener = createMessageListener(); if (withTopic && hazelcastInstance != null) { topic = hazelcastInstance.getTopic(name); topic.addMessageListener(messageListener); } else { topic = null; } }
@Override public CollectionRegionAccessStrategy createCollectionRegionAccessStrategy(RedisCollectionRegion collectionRegion, AccessType accessType) { switch (accessType) { case READ_ONLY: if (collectionRegion.getCacheDataDescription().isMutable()) { log.warn("read-only cache configured for mutable entity collectionRegionName=[{}]", collectionRegion.getName()); } return new ReadOnlyRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); case READ_WRITE: return new ReadWriteRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); case NONSTRICT_READ_WRITE: return new NonStrictReadWriteRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); case TRANSACTIONAL: return new TransactionalRedisCollectionRegionAccessStrategy(collectionRegion, collectionRegion.getSettings()); default: throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); } }
/** * Creates a read/write cache access strategy around the given cache region. */ public AbstractReadWriteRedisAccessStrategy(T region, Settings settings) { super(region, settings); this.versionComparator = region.getCacheDataDescription().getVersionComparator(); }
/** * @param name the name for this region cache, which is also used to retrieve configuration/topic * @param hazelcastInstance the {@code HazelcastInstance} to which this region cache belongs, used to retrieve * configuration and to lookup an {@link ITopic} to register a {@link MessageListener} * with if {@code withTopic} is {@code true} (optional) * @param metadata metadata describing the cached data, used to compare data versions (optional) * @param withTopic {@code true} to register a {@link MessageListener} with the {@link ITopic} whose name * matches this region cache <i>if</i> a {@code HazelcastInstance} was provided to look * up the topic; otherwise, {@code false} not to register a listener even if an instance * was provided */ public LocalRegionCache(final String name, final HazelcastInstance hazelcastInstance, final CacheDataDescription metadata, final boolean withTopic) { this.hazelcastInstance = hazelcastInstance; try { config = hazelcastInstance != null ? hazelcastInstance.getConfig().findMapConfig(name) : null; } catch (UnsupportedOperationException ignored) { EmptyStatement.ignore(ignored); } versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; cache = new ConcurrentHashMap<Object, Expirable>(); markerIdCounter = new AtomicLong(); messageListener = createMessageListener(); if (withTopic && hazelcastInstance != null) { topic = hazelcastInstance.getTopic(name); topic.addMessageListener(messageListener); } else { topic = null; } }
@Override public EntityRegionAccessStrategy createEntityRegionAccessStrategy(RedisEntityRegion entityRegion, AccessType accessType) { switch (accessType) { case READ_ONLY: if (entityRegion.getCacheDataDescription().isMutable()) { log.warn("read-only cache configured for mutable entity regionName=[{}]", entityRegion.getName()); } return new ReadOnlyRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); case READ_WRITE: return new ReadWriteRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); case NONSTRICT_READ_WRITE: return new NonStrictReadWriteRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); case TRANSACTIONAL: return new TransactionalRedisEntityRegionAccessStrategy(entityRegion, entityRegion.getSettings()); default: throw new IllegalArgumentException("unrecognized access strategy type [" + accessType + "]"); } }
/** * Creates a read/write cache access strategy around the given cache region. */ public AbstractReadWriteRedisAccessStrategy(T region, Settings settings) { super(region, settings); this.versionComparator = region.getCacheDataDescription().getVersionComparator(); }
/** * @param name the name for this region cache, which is also used to retrieve configuration/topic * @param hazelcastInstance the {@code HazelcastInstance} to which this region cache belongs, used to retrieve * configuration and to lookup an {@link ITopic} to register a {@link MessageListener} * with if {@code withTopic} is {@code true} (optional) * @param metadata metadata describing the cached data, used to compare data versions (optional) * @param withTopic {@code true} to register a {@link MessageListener} with the {@link ITopic} whose name * matches this region cache <i>if</i> a {@code HazelcastInstance} was provided to look * up the topic; otherwise, {@code false} not to register a listener even if an instance * was provided */ public LocalRegionCache(final String name, final HazelcastInstance hazelcastInstance, final CacheDataDescription metadata, final boolean withTopic) { this.hazelcastInstance = hazelcastInstance; try { config = hazelcastInstance != null ? hazelcastInstance.getConfig().findMapConfig(name) : null; } catch (UnsupportedOperationException ignored) { EmptyStatement.ignore(ignored); } versionComparator = metadata != null && metadata.isVersioned() ? metadata.getVersionComparator() : null; cache = new ConcurrentHashMap<Object, Expirable>(); markerIdCounter = new AtomicLong(); messageListener = createMessageListener(); if (withTopic && hazelcastInstance != null) { topic = hazelcastInstance.getTopic(name); topic.addMessageListener(messageListener); } else { topic = null; } }