Search in sources :

Example 1 with Mutator

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));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Configuration(org.infinispan.configuration.cache.Configuration) Mutator(org.wildfly.clustering.ee.Mutator) Test(org.junit.Test)

Example 2 with Mutator

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);
}
Also used : CacheEntryMutator(org.wildfly.clustering.ee.infinispan.CacheEntryMutator) Mutator(org.wildfly.clustering.ee.Mutator)

Example 3 with Mutator

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);
}
Also used : Mutator(org.wildfly.clustering.ee.Mutator) CacheEntryMutator(org.wildfly.clustering.ee.infinispan.CacheEntryMutator) CacheEntryMutator(org.wildfly.clustering.ee.infinispan.CacheEntryMutator)

Example 4 with 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);
}
Also used : Mutator(org.wildfly.clustering.ee.Mutator) CacheEntryMutator(org.wildfly.clustering.ee.infinispan.CacheEntryMutator)

Example 5 with Mutator

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheEntryMutator(org.wildfly.clustering.ee.infinispan.CacheEntryMutator) Mutator(org.wildfly.clustering.ee.Mutator)

Aggregations

Mutator (org.wildfly.clustering.ee.Mutator)8 CacheEntryMutator (org.wildfly.clustering.ee.infinispan.CacheEntryMutator)6 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 Test (org.junit.Test)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1