Search in sources :

Example 1 with EntryWrappingInterceptor

use of org.infinispan.interceptors.EntryWrappingInterceptor in project hibernate-orm by hibernate.

the class PutFromLoadValidator method addToCache.

/**
	 * Besides the call from constructor, this should be called only from tests when mocking the validator.
	 */
public static void addToCache(AdvancedCache cache, PutFromLoadValidator validator) {
    List<CommandInterceptor> interceptorChain = cache.getInterceptorChain();
    log.debug("Interceptor chain was: " + interceptorChain);
    int position = 0;
    // add interceptor before uses exact match, not instanceof match
    int invalidationPosition = 0;
    int entryWrappingPosition = 0;
    for (CommandInterceptor ci : interceptorChain) {
        if (ci instanceof InvalidationInterceptor) {
            invalidationPosition = position;
        }
        if (ci instanceof EntryWrappingInterceptor) {
            entryWrappingPosition = position;
        }
        position++;
    }
    boolean transactional = cache.getCacheConfiguration().transaction().transactionMode().isTransactional();
    if (transactional) {
        cache.removeInterceptor(invalidationPosition);
        TxInvalidationInterceptor txInvalidationInterceptor = new TxInvalidationInterceptor();
        cache.getComponentRegistry().registerComponent(txInvalidationInterceptor, TxInvalidationInterceptor.class);
        cache.addInterceptor(txInvalidationInterceptor, invalidationPosition);
        // Note that invalidation does *NOT* acquire locks; therefore, we have to start invalidating before
        // wrapping the entry, since if putFromLoad was invoked between wrap and beginInvalidatingKey, the invalidation
        // would not commit the entry removal (as during wrap the entry was not in cache)
        TxPutFromLoadInterceptor txPutFromLoadInterceptor = new TxPutFromLoadInterceptor(validator, cache.getName());
        cache.getComponentRegistry().registerComponent(txPutFromLoadInterceptor, TxPutFromLoadInterceptor.class);
        cache.addInterceptor(txPutFromLoadInterceptor, entryWrappingPosition);
    } else {
        cache.removeInterceptor(invalidationPosition);
        NonTxInvalidationInterceptor nonTxInvalidationInterceptor = new NonTxInvalidationInterceptor(validator);
        cache.getComponentRegistry().registerComponent(nonTxInvalidationInterceptor, NonTxInvalidationInterceptor.class);
        cache.addInterceptor(nonTxInvalidationInterceptor, invalidationPosition);
        NonTxPutFromLoadInterceptor nonTxPutFromLoadInterceptor = new NonTxPutFromLoadInterceptor(validator, cache.getName());
        cache.getComponentRegistry().registerComponent(nonTxPutFromLoadInterceptor, NonTxPutFromLoadInterceptor.class);
        cache.addInterceptor(nonTxPutFromLoadInterceptor, entryWrappingPosition);
        validator.nonTxPutFromLoadInterceptor = nonTxPutFromLoadInterceptor;
    }
    log.debug("New interceptor chain is: " + cache.getInterceptorChain());
    CacheCommandInitializer cacheCommandInitializer = cache.getComponentRegistry().getComponent(CacheCommandInitializer.class);
    cacheCommandInitializer.addPutFromLoadValidator(cache.getName(), validator);
}
Also used : InvalidationInterceptor(org.infinispan.interceptors.InvalidationInterceptor) EntryWrappingInterceptor(org.infinispan.interceptors.EntryWrappingInterceptor) CommandInterceptor(org.infinispan.interceptors.base.CommandInterceptor) CacheCommandInitializer(org.hibernate.cache.infinispan.util.CacheCommandInitializer)

Example 2 with EntryWrappingInterceptor

use of org.infinispan.interceptors.EntryWrappingInterceptor in project hibernate-orm by hibernate.

the class BaseTransactionalDataRegion method replaceCommonInterceptors.

private void replaceCommonInterceptors() {
    CacheMode cacheMode = cache.getCacheConfiguration().clustering().cacheMode();
    if (!cacheMode.isReplicated() && !cacheMode.isDistributed()) {
        return;
    }
    LockingInterceptor lockingInterceptor = new LockingInterceptor();
    cache.getComponentRegistry().registerComponent(lockingInterceptor, LockingInterceptor.class);
    if (!cache.addInterceptorBefore(lockingInterceptor, NonTransactionalLockingInterceptor.class)) {
        throw new IllegalStateException("Misconfigured cache, interceptor chain is " + cache.getInterceptorChain());
    }
    cache.removeInterceptor(NonTransactionalLockingInterceptor.class);
    UnorderedDistributionInterceptor distributionInterceptor = new UnorderedDistributionInterceptor();
    cache.getComponentRegistry().registerComponent(distributionInterceptor, UnorderedDistributionInterceptor.class);
    if (!cache.addInterceptorBefore(distributionInterceptor, NonTxDistributionInterceptor.class)) {
        throw new IllegalStateException("Misconfigured cache, interceptor chain is " + cache.getInterceptorChain());
    }
    cache.removeInterceptor(NonTxDistributionInterceptor.class);
    EntryWrappingInterceptor ewi = cache.getComponentRegistry().getComponent(EntryWrappingInterceptor.class);
    try {
        Field isUsingLockDelegation = EntryWrappingInterceptor.class.getDeclaredField("isUsingLockDelegation");
        isUsingLockDelegation.setAccessible(true);
        isUsingLockDelegation.set(ewi, false);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Field(java.lang.reflect.Field) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) LockingInterceptor(org.hibernate.cache.infinispan.access.LockingInterceptor) NonTxDistributionInterceptor(org.infinispan.interceptors.distribution.NonTxDistributionInterceptor) UnorderedDistributionInterceptor(org.hibernate.cache.infinispan.access.UnorderedDistributionInterceptor) EntryWrappingInterceptor(org.infinispan.interceptors.EntryWrappingInterceptor) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) CacheMode(org.infinispan.configuration.cache.CacheMode)

Aggregations

EntryWrappingInterceptor (org.infinispan.interceptors.EntryWrappingInterceptor)2 Field (java.lang.reflect.Field)1 LockingInterceptor (org.hibernate.cache.infinispan.access.LockingInterceptor)1 UnorderedDistributionInterceptor (org.hibernate.cache.infinispan.access.UnorderedDistributionInterceptor)1 CacheCommandInitializer (org.hibernate.cache.infinispan.util.CacheCommandInitializer)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1 InvalidationInterceptor (org.infinispan.interceptors.InvalidationInterceptor)1 CommandInterceptor (org.infinispan.interceptors.base.CommandInterceptor)1 NonTxDistributionInterceptor (org.infinispan.interceptors.distribution.NonTxDistributionInterceptor)1 NonTransactionalLockingInterceptor (org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor)1