use of org.wildfly.clustering.ee.Mutator in project wildfly by wildfly.
the class CacheEntryMutatorTestCase method mutateTransactional.
@Test
public void mutateTransactional() {
AdvancedCache<Object, Object> cache = mock(AdvancedCache.class);
Object id = new Object();
Object value = new Object();
Configuration config = new ConfigurationBuilder().transaction().transactionMode(TransactionMode.TRANSACTIONAL).build();
when(cache.getCacheConfiguration()).thenReturn(config);
Mutator mutator = new CacheEntryMutator<>(cache, id, value);
when(cache.getAdvancedCache()).thenReturn(cache);
when(cache.withFlags(Flag.IGNORE_RETURN_VALUES, Flag.FAIL_SILENTLY)).thenReturn(cache);
mutator.mutate();
verify(cache).put(same(id), same(value));
mutator.mutate();
verify(cache, times(1)).put(same(id), same(value));
mutator.mutate();
verify(cache, times(1)).put(same(id), same(value));
}
use of org.wildfly.clustering.ee.Mutator in project wildfly by wildfly.
the class CoarseSessionAttributesFactory method createSessionAttributes.
@Override
public SessionAttributes createSessionAttributes(String id, Map.Entry<Map<String, Object>, V> entry) {
SessionAttributesKey key = new SessionAttributesKey(id);
Mutator mutator = this.properties.isTransactional() && this.cache.getAdvancedCache().getCacheEntry(key).isCreated() ? Mutator.PASSIVE : new CacheEntryMutator<>(this.cache, key, entry.getValue());
return new CoarseSessionAttributes(entry.getKey(), mutator, this.marshaller, this.properties);
}
use of org.wildfly.clustering.ee.Mutator in project wildfly by wildfly.
the class CoarseSessionsFactory method createSessions.
@Override
public Sessions<D, S> createSessions(String ssoId, Map<D, S> value) {
CoarseSessionsKey key = new CoarseSessionsKey(ssoId);
Mutator mutator = new CacheEntryMutator<>(this.cache, key, value);
return new CoarseSessions<>(value, mutator);
}
use of org.wildfly.clustering.ee.Mutator in project wildfly by wildfly.
the class InfinispanSessionMetaDataFactory method createSessionMetaData.
@Override
public InvalidatableSessionMetaData createSessionMetaData(String id, InfinispanSessionMetaData<L> entry) {
SessionCreationMetaDataKey creationMetaDataKey = new SessionCreationMetaDataKey(id);
Mutator creationMutator = this.properties.isTransactional() && this.creationMetaDataCache.getAdvancedCache().getCacheEntry(creationMetaDataKey).isCreated() ? Mutator.PASSIVE : new CacheEntryMutator<>(this.creationMetaDataCache, creationMetaDataKey, new SessionCreationMetaDataEntry<>(entry.getCreationMetaData(), entry.getLocalContext()));
SessionCreationMetaData creationMetaData = new MutableSessionCreationMetaData(entry.getCreationMetaData(), creationMutator);
SessionAccessMetaDataKey accessMetaDataKey = new SessionAccessMetaDataKey(id);
Mutator accessMutator = this.properties.isTransactional() && this.accessMetaDataCache.getAdvancedCache().getCacheEntry(accessMetaDataKey).isCreated() ? Mutator.PASSIVE : new CacheEntryMutator<>(this.accessMetaDataCache, accessMetaDataKey, entry.getAccessMetaData());
SessionAccessMetaData accessMetaData = new MutableSessionAccessMetaData(entry.getAccessMetaData(), accessMutator);
return new SimpleSessionMetaData(creationMetaData, accessMetaData);
}
use of org.wildfly.clustering.ee.Mutator in project wildfly by wildfly.
the class FineSessionAttributes method getAttribute.
@Override
public Object getAttribute(String name) {
Integer attributeId = this.names.get(name);
if (attributeId == null)
return null;
SessionAttributeKey key = this.createKey(attributeId);
V value = this.cache.get(key);
Object attribute = this.read(name, value);
if (attribute != null) {
// If the object is mutable, we need to indicate that the attribute should be replicated
if (!SessionAttributeImmutability.INSTANCE.test(attribute)) {
Mutator mutator = this.mutations.computeIfAbsent(name, k -> new CacheEntryMutator<>(this.cache, key, value));
// If cache is not transactional, mutate on close instead.
if (this.properties.isTransactional()) {
mutator.mutate();
}
}
}
return attribute;
}
Aggregations