@Override public BeanGroupEntry<I, T> createValue(I id, Void context) { BeanGroupEntry<I, T> entry = new InfinispanBeanGroupEntry<>(this.factory.createMarshalledValue(new ConcurrentHashMap<>())); BeanGroupEntry<I, T> existing = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).putIfAbsent(this.createKey(id), entry); return (existing == null) ? entry : existing; }
@Override public BeanEntry<I> createValue(I id, I groupId) { BeanEntry<I> entry = new InfinispanBeanEntry<>(this.beanName, groupId); BeanEntry<I> existing = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).putIfAbsent(this.createKey(id), entry); return (existing == null) ? entry : existing; }
@Override public InfinispanSessionMetaData<L> createValue(String id, Void context) { SessionCreationMetaDataEntry<L> creationMetaDataEntry = new SessionCreationMetaDataEntry<>(new SimpleSessionCreationMetaData()); if (this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).putIfAbsent(new SessionCreationMetaDataKey(id), creationMetaDataEntry) != null) { return null; } SessionAccessMetaData accessMetaData = new SimpleSessionAccessMetaData(); this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(new SessionAccessMetaDataKey(id), accessMetaData); return new InfinispanSessionMetaData<>(creationMetaDataEntry.getMetaData(), accessMetaData, creationMetaDataEntry.getLocalContext()); }
/** * {@inheritDoc} */ public Object putIfAbsent(CacheKey key, Object value, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) { return parentCache.putIfAbsent(key, value, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit); }
/** * {@inheritDoc} */ public Object putIfAbsent(CacheKey key, Object value, long lifespan, TimeUnit unit) { return parentCache.putIfAbsent(key, value, lifespan, unit); }
@Override public BeanGroupEntry<I, T> createValue(I id, Void context) { BeanGroupEntry<I, T> entry = new InfinispanBeanGroupEntry<>(this.factory.createMarshalledValue(new ConcurrentHashMap<>())); BeanGroupEntry<I, T> existing = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).putIfAbsent(this.createKey(id), entry); return (existing == null) ? entry : existing; }
/** * @return the current list of files being part of the index */ public Set<String> getFileList() { Set<String> fileList = (Set<String>) cache.get(fileListCacheKey); if (fileList == null) { fileList = new ConcurrentHashSet<String>(); Set<String> prev = (Set<String>) cache.putIfAbsent(fileListCacheKey, fileList); if ( prev != null ) { fileList = prev; } } if (trace) log.trace("Refreshed file listing view"); return fileList; }
@Override public void apply() { if (!localMode && value instanceof FakeValueSet) { // Ensure that a FakeKeySet won't be replicated return; } Object oldValue = setCacheLocalMode().putIfAbsent(key, value); if (oldValue instanceof FakeValueSet) { // The old value is a fake value so we will replace it with the new one setCacheLocalMode(Flag.SKIP_REMOTE_LOOKUP, Flag.IGNORE_RETURN_VALUES).put(key, value); } }
private ClusteredLockImpl createLock(String lockName) { ClusteredLockConfiguration configuration = getConfiguration(lockName); if (configuration == null) { throw new ClusteredLockException(String.format("Lock does %s not exist", lockName)); } ClusteredLockKey key = new ClusteredLockKey(ByteString.fromString(lockName)); cache.putIfAbsent(key, ClusteredLockValue.INITIAL_STATE); ClusteredLockImpl lock = new ClusteredLockImpl(lockName, key, cache, this); return lock; }
@Override public BeanEntry<I> createValue(I id, I groupId) { BeanEntry<I> entry = new InfinispanBeanEntry<>(this.beanName, groupId); BeanEntry<I> existing = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).putIfAbsent(this.createKey(id), entry); return (existing == null) ? entry : existing; }
@Override public boolean defineLock(String name, ClusteredLockConfiguration configuration) { if (trace) { log.tracef("LOCK[%s] defineLock has been called %s", name, configuration); } // TODO: Configuration is not used because we don't support any other mode for now. For that : ISPN-8413 CacheHolder cacheHolder = extractCacheHolder(cacheHolderFuture); cache = cacheHolder.getClusteredLockCache(); ClusteredLockKey key = new ClusteredLockKey(ByteString.fromString(name)); ClusteredLockValue clusteredLockValue = cache.putIfAbsent(key, ClusteredLockValue.INITIAL_STATE); locks.putIfAbsent(name, new ClusteredLockImpl(name, key, cache, this)); return clusteredLockValue == null; }
private Object putIfAbsent() { Object prev = cache.get(key); if (prev == null) { // Generate new version only if key not present prev = cache.putIfAbsent(key, createValue(), buildMetadata()); } if (prev == null) return createSuccessResponse(); else return createNotExecutedResponse(); }
/** * @return the current list of files being part of the index */ @GuardedBy("writeLock") private FileListCacheValue getFileList() { FileListCacheValue fileList = (FileListCacheValue) cache.get(fileListCacheKey); if (fileList == null) { fileList = new FileListCacheValue(); FileListCacheValue prev = (FileListCacheValue) cache.putIfAbsent(fileListCacheKey, fileList); if (prev != null) { fileList = prev; } } if (trace) log.trace("Refreshed file listing view"); return fileList; }
protected void createRemoteEntityInCache(K key, long eventVersion) { VersionedValue<SessionEntityWrapper<V>> remoteSessionVersioned = remoteCache.getWithMetadata(key); // Maybe can happen under some circumstances that remoteCache doesn't yet contain the value sent in the event (maybe just theoretically...) if (remoteSessionVersioned == null || remoteSessionVersioned.getValue() == null) { logger.debugf("Entity '%s' not present in remoteCache. Ignoring create", key.toString()); return; } V remoteSession = remoteSessionVersioned.getValue().getEntity(); SessionEntityWrapper<V> newWrapper = new SessionEntityWrapper<>(remoteSession); logger.debugf("Read session entity wrapper from the remote cache: %s", remoteSession.toString()); // Using putIfAbsent. Theoretic possibility that entity was already put to cache by someone else cache.getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE, Flag.SKIP_CACHE_LOAD, Flag.IGNORE_RETURN_VALUES) .putIfAbsent(key, newWrapper); }
public void testPutIfAbsent() { AdvancedCache<String, String> cache1 = advancedCache(0,"replication"); AdvancedCache<String, String> cache2 = advancedCache(1,"replication"); cache2.withFlags(CACHE_MODE_LOCAL).put("key", "valueOld"); assert cache2.get("key").equals("valueOld"); assert cache1.get("key") == null; cache1.putIfAbsent("key", "value"); assertEquals("value", cache1.get("key")); assertEquals("value", cache2.get("key")); cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value3"); assert cache1.get("key").equals("value"); assert cache2.get("key").equals("value3"); cache1.putIfAbsent("key", "value4"); assert cache1.get("key").equals("value"); assert cache2.get("key").equals("value3"); // should not invalidate cache2!! }
public void testPutIfAbsent() { AdvancedCache<String, String> cache1 = advancedCache(0,"invalidation"); AdvancedCache<String, String> cache2 = advancedCache(1,"invalidation"); assert null == cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value"); assert cache2.get("key").equals("value"); assert cache1.get("key") == null; replListener(cache2).expect(InvalidateCommand.class); cache1.putIfAbsent("key", "value"); replListener(cache2).waitForRpc(); assert cache1.get("key").equals("value"); assert cache2.get("key") == null; assert null == cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2"); assert cache1.get("key").equals("value"); assert cache2.get("key").equals("value2"); cache1.putIfAbsent("key", "value3"); assert cache1.get("key").equals("value"); assert cache2.get("key").equals("value2"); // should not invalidate cache2!! }
@Test(enabled = false, description = "does it make sense to have skip_remote_lookup with conditional commands?") public void testCorrectFunctionalityOnConditionalWrite() { MagicKey k1 = getMagicKey(); c1.put(k1, "value"); assertIsInContainerImmortal(c1, k1); assertIsInContainerImmortal(c2, k1); assertIsNotInL1(c3, k1); assertIsNotInL1(c4, k1); assertNull(c4.getAdvancedCache().withFlags(SKIP_REMOTE_LOOKUP).putIfAbsent(k1, "new_val")); assertIsInContainerImmortal(c1, k1); assertIsInContainerImmortal(c2, k1); assertIsNotInL1(c3, k1); if (l1CacheEnabled) assertIsNotInL1(c4, k1); }
public void testDefaultLifespanPutIfAbsent() { cache().putIfAbsent(1, "v1"); expectCachedThenExpired(1, "v1"); cache().getAdvancedCache().putIfAbsent(2, "v2", new EmbeddedMetadata.Builder().build()); expectCachedThenExpired(2, "v2"); }
public void testPutIfAbsentWithVersion() { final Integer key = 3; NumericVersion version = new NumericVersion(1); assertEquals(null, advCache.putIfAbsent(key, "v1", withVersion(version))); CacheEntry cacheEntry = advCache.getCacheEntry(key); assertEquals(EQUAL, version.compareTo(cacheEntry.getMetadata().version())); }
public void testAtomicPutIfAbsentFromNonOwnerWithFlag(Method m) throws Exception { String key = k(m), value = "value"; String replaced = getFirstNonOwner(key).getAdvancedCache().withFlags(Flag.SKIP_CACHE_STORE).putIfAbsent(key, value); assertNull(replaced); //interesting case: fails to put as value exists, put actually missing in Store replaced = getFirstNonOwner(key).putIfAbsent(key, value); assertEquals(replaced, value); for (Cache<Object, String> c : caches) { assertEquals(replaced, c.get(key)); CacheLoader store = TestingUtil.getFirstLoader(c); assertFalse(store.contains(key)); } }