Search in sources :

Example 1 with CommandInterceptor

use of org.infinispan.interceptors.base.CommandInterceptor 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 CommandInterceptor

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

the class BaseTransactionalDataRegion method prepareForVersionedEntries.

protected void prepareForVersionedEntries() {
    if (strategy != null) {
        assert strategy == Strategy.VERSIONED_ENTRIES;
        return;
    }
    replaceCommonInterceptors();
    replaceExpirationManager();
    cache.removeInterceptor(CallInterceptor.class);
    VersionedCallInterceptor tombstoneCallInterceptor = new VersionedCallInterceptor(this, metadata.getVersionComparator());
    cache.getComponentRegistry().registerComponent(tombstoneCallInterceptor, VersionedCallInterceptor.class);
    List<CommandInterceptor> interceptorChain = cache.getInterceptorChain();
    cache.addInterceptor(tombstoneCallInterceptor, interceptorChain.size());
    strategy = Strategy.VERSIONED_ENTRIES;
}
Also used : VersionedCallInterceptor(org.hibernate.cache.infinispan.access.VersionedCallInterceptor) CommandInterceptor(org.infinispan.interceptors.base.CommandInterceptor)

Example 3 with CommandInterceptor

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

the class BaseTransactionalDataRegion method prepareForTombstones.

private void prepareForTombstones() {
    if (strategy != null) {
        assert strategy == Strategy.TOMBSTONES;
        return;
    }
    Configuration configuration = cache.getCacheConfiguration();
    if (configuration.eviction().maxEntries() >= 0) {
        log.evictionWithTombstones();
    }
    replaceCommonInterceptors();
    replaceExpirationManager();
    cache.removeInterceptor(CallInterceptor.class);
    TombstoneCallInterceptor tombstoneCallInterceptor = new TombstoneCallInterceptor(this);
    cache.getComponentRegistry().registerComponent(tombstoneCallInterceptor, TombstoneCallInterceptor.class);
    List<CommandInterceptor> interceptorChain = cache.getInterceptorChain();
    cache.addInterceptor(tombstoneCallInterceptor, interceptorChain.size());
    strategy = Strategy.TOMBSTONES;
}
Also used : Configuration(org.infinispan.configuration.cache.Configuration) CommandInterceptor(org.infinispan.interceptors.base.CommandInterceptor) TombstoneCallInterceptor(org.hibernate.cache.infinispan.access.TombstoneCallInterceptor)

Aggregations

CommandInterceptor (org.infinispan.interceptors.base.CommandInterceptor)3 TombstoneCallInterceptor (org.hibernate.cache.infinispan.access.TombstoneCallInterceptor)1 VersionedCallInterceptor (org.hibernate.cache.infinispan.access.VersionedCallInterceptor)1 CacheCommandInitializer (org.hibernate.cache.infinispan.util.CacheCommandInitializer)1 Configuration (org.infinispan.configuration.cache.Configuration)1 EntryWrappingInterceptor (org.infinispan.interceptors.EntryWrappingInterceptor)1 InvalidationInterceptor (org.infinispan.interceptors.InvalidationInterceptor)1