Refine search
@Override public void mutate() { // We only ever have to perform a replace once within a batch if ((this.mutated == null) || this.mutated.compareAndSet(false, true)) { // Use FAIL_SILENTLY to prevent mutation from failing locally due to remote exceptions this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.FAIL_SILENTLY).put(this.id, this.value); } } }
@SuppressWarnings("unchecked") public InfinispanSessionMetaDataFactory(Cache<? extends Key<String>, ?> cache, CacheProperties properties) { this.creationMetaDataCache = (Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>>) cache; this.findCreationMetaDataCache = properties.isLockOnRead() ? this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : this.creationMetaDataCache; this.accessMetaDataCache = (Cache<SessionAccessMetaDataKey, SessionAccessMetaData>) cache; this.properties = properties; }
@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()); }
public InfinispanBeanFactory(String beanName, BeanGroupFactory<I, T> groupFactory, Cache<BeanKey<I>, BeanEntry<I>> cache, CacheProperties properties, Duration timeout, PassivationListener<T> listener) { this.beanName = beanName; this.groupFactory = groupFactory; this.cache = cache; this.findCache = properties.isLockOnRead() ? this.cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : this.cache; this.timeout = timeout; this.listener = listener; }
@Override public Map<D, S> createValue(String id, Void context) { Map<D, S> sessions = this.properties.isLockOnRead() ? new HashMap<>() : new ConcurrentHashMap<>(); this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(new CoarseSessionsKey(id), sessions); return sessions; }
@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; }
public void testLocalOnlyClear() { AdvancedCache<String, String> cache1 = advancedCache(0,"invalidation"); AdvancedCache<String, String> cache2 = advancedCache(1,"invalidation"); cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1"); cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2"); assert cache1.get("key").equals("value1"); assert cache2.get("key").equals("value2"); cache1.withFlags(CACHE_MODE_LOCAL).clear(); assert cache1.get("key") == null; assert cache2.get("key") != null; assert cache2.get("key").equals("value2"); }
public InfinispanSSOFactory(Cache<AuthenticationKey, AuthenticationEntry<AV, L>> cache, CacheProperties properties, Marshaller<A, AV> marshaller, LocalContextFactory<L> localContextFactory, SessionsFactory<SV, D, S> sessionsFactory) { this.cache = cache; this.findCache = properties.isLockOnRead() ? cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : cache; this.marshaller = marshaller; this.localContextFactory = localContextFactory; this.sessionsFactory = sessionsFactory; }
@Override public Map.Entry<Map<String, Object>, V> createValue(String id, Void context) { Map<String, Object> attributes = this.properties.isLockOnRead() ? new HashMap<>() : new ConcurrentHashMap<>(); V value = this.marshaller.write(attributes); this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(new SessionAttributesKey(id), value); return new SimpleImmutableEntry<>(attributes, value); }
public void testClear() { AdvancedCache<String, String> cache1 = advancedCache(0,"replication"); AdvancedCache<String, String> cache2 = advancedCache(1,"replication"); cache1.withFlags(CACHE_MODE_LOCAL).put("key", "value1"); cache2.withFlags(CACHE_MODE_LOCAL).put("key", "value2"); assert cache1.get("key").equals("value1"); assert cache2.get("key").equals("value2"); cache1.clear(); assert cache1.get("key") == null; assert cache2.get("key") == null; }
@Override public boolean purge(String id) { return this.remove(id, this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION)); }
private void populateRegistry() { try (Batch batch = this.batcher.createBatch()) { this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(this.group.getAddress(this.group.getLocalMember()), this.entry); } }
public void testCacheLocalInBackupOwner() { final AdvancedCache<Object, String> cache1 = advancedCache(0, cacheName); final AdvancedCache<Object, String> cache2 = advancedCache(1, cacheName); final Object key = new MagicKey("k-bo", cache1); cache2.withFlags(CACHE_MODE_LOCAL).put(key, "value"); assertCacheValue(cache2, key, "value"); assertCacheValue(cache1, key, null); }
@Override public InfinispanSessionMetaData<L> tryValue(String id) { return this.getValue(id, this.findCreationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY)); }
@Override public Map.Entry<Map.Entry<A, AtomicReference<L>>, SV> createValue(String id, A authentication) { AuthenticationEntry<AV, L> entry = new AuthenticationEntry<>(this.marshaller.write(authentication)); this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(new AuthenticationKey(id), entry); SV sessions = this.sessionsFactory.createValue(id, null); return new AbstractMap.SimpleImmutableEntry<>(new AbstractMap.SimpleImmutableEntry<>(authentication, entry.getLocalContext()), sessions); }
public void testConflictsResolvedWithProvidedMergePolicy() { createCluster(); AdvancedCache<Object, Object> cache = getCache(0); ConflictManager<Object, Object> cm = ConflictManagerFactory.get(cache); MagicKey key = new MagicKey(cache(0), cache(1)); cache.put(key, 1); cache.withFlags(Flag.CACHE_MODE_LOCAL).put(key, 2); assertEquals(1, getConflicts(0).count()); cm.resolveConflicts(((preferredEntry, otherEntries) -> preferredEntry)); assertEquals(0, getConflicts(0).count()); }
@Override public int getActiveCount() { try (Stream<Map.Entry<BeanKey<I>, BeanEntry<I>>> entries = this.cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL, Flag.SKIP_CACHE_LOAD).entrySet().stream()) { return (int) entries.filter(this.filter).count(); } }
@Override public Object setAttribute(String name, Object attribute) { if (attribute == null) { return this.removeAttribute(name); } if (this.properties.isMarshalling() && !this.marshaller.isMarshallable(attribute)) { throw new IllegalArgumentException(new NotSerializableException(attribute.getClass().getName())); } V value = this.marshaller.write(attribute); UUID attributeId = this.names.get(name); if (attributeId == null) { UUID newAttributeId = UUID.randomUUID(); this.setNames(this.namesCache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).compute(this.createKey(), this.properties.isTransactional() ? new CopyOnWriteMapPutFunction<>(name, newAttributeId) : new ConcurrentMapPutFunction<>(name, newAttributeId))); attributeId = this.names.get(name); } Object result = this.read(name, this.attributeCache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS).put(this.createKey(attributeId), value)); this.mutations.remove(name); return result; }