Search in sources :

Example 1 with AnchoredFetchInterceptor

use of org.infinispan.anchored.impl.AnchoredFetchInterceptor in project infinispan by infinispan.

the class AnchoredKeysModule method cacheStarting.

@Override
public void cacheStarting(ComponentRegistry cr, Configuration configuration, String cacheName) {
    BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
    AnchoredKeysConfiguration anchoredKeysConfiguration = configuration.module(AnchoredKeysConfiguration.class);
    if (anchoredKeysConfiguration == null || !anchoredKeysConfiguration.enabled())
        return;
    assert configuration.clustering().cacheMode().isReplicated();
    assert !configuration.clustering().stateTransfer().awaitInitialTransfer();
    assert configuration.clustering().partitionHandling().whenSplit() == PartitionHandling.ALLOW_READ_WRITES;
    assert configuration.clustering().partitionHandling().mergePolicy() == MergePolicy.PREFERRED_NON_NULL;
    if (!globalConfiguration.features().isAvailable(ANCHORED_KEYS_FEATURE))
        throw CONFIG.featureDisabled(ANCHORED_KEYS_FEATURE);
    bcr.registerComponent(AnchorManager.class, new AnchorManager(), true);
    AsyncInterceptorChain interceptorChain = bcr.getComponent(AsyncInterceptorChain.class).wired();
    // Replace the clustering interceptor with our custom interceptor
    ClusteringInterceptor oldDistInterceptor = interceptorChain.findInterceptorExtending(ClusteringInterceptor.class);
    AnchoredDistributionInterceptor distInterceptor = new AnchoredDistributionInterceptor();
    bcr.registerComponent(AnchoredDistributionInterceptor.class, distInterceptor, true);
    boolean interceptorAdded = interceptorChain.addInterceptorBefore(distInterceptor, oldDistInterceptor.getClass());
    assert interceptorAdded;
    interceptorChain.removeInterceptor(oldDistInterceptor.getClass());
    // Add a separate interceptor to fetch the actual values
    // AnchoredDistributionInterceptor cannot do it because it extends NonTxDistributionInterceptor
    AnchoredFetchInterceptor<?, ?> fetchInterceptor = new AnchoredFetchInterceptor<>();
    bcr.registerComponent(AnchoredFetchInterceptor.class, fetchInterceptor, true);
    interceptorAdded = interceptorChain.addInterceptorAfter(fetchInterceptor, AnchoredDistributionInterceptor.class);
    assert interceptorAdded;
    bcr.replaceComponent(StateProvider.class.getName(), new AnchoredStateProvider(), true);
    bcr.replaceComponent(EntryFactory.class.getName(), new AnchoredEntryFactory(), true);
    bcr.replaceComponent(CacheNotifier.class.getName(), new AnchoredCacheNotifier<>(), true);
    bcr.rewire();
}
Also used : EntryFactory(org.infinispan.container.impl.EntryFactory) AnchoredEntryFactory(org.infinispan.anchored.impl.AnchoredEntryFactory) AnchoredDistributionInterceptor(org.infinispan.anchored.impl.AnchoredDistributionInterceptor) StateProvider(org.infinispan.statetransfer.StateProvider) AnchoredStateProvider(org.infinispan.anchored.impl.AnchoredStateProvider) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) AnchorManager(org.infinispan.anchored.impl.AnchorManager) AnchoredKeysConfiguration(org.infinispan.anchored.configuration.AnchoredKeysConfiguration) AnchoredStateProvider(org.infinispan.anchored.impl.AnchoredStateProvider) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) AnchoredCacheNotifier(org.infinispan.anchored.impl.AnchoredCacheNotifier) AnchoredFetchInterceptor(org.infinispan.anchored.impl.AnchoredFetchInterceptor) ClusteringInterceptor(org.infinispan.interceptors.impl.ClusteringInterceptor) AnchoredEntryFactory(org.infinispan.anchored.impl.AnchoredEntryFactory)

Aggregations

AnchoredKeysConfiguration (org.infinispan.anchored.configuration.AnchoredKeysConfiguration)1 AnchorManager (org.infinispan.anchored.impl.AnchorManager)1 AnchoredCacheNotifier (org.infinispan.anchored.impl.AnchoredCacheNotifier)1 AnchoredDistributionInterceptor (org.infinispan.anchored.impl.AnchoredDistributionInterceptor)1 AnchoredEntryFactory (org.infinispan.anchored.impl.AnchoredEntryFactory)1 AnchoredFetchInterceptor (org.infinispan.anchored.impl.AnchoredFetchInterceptor)1 AnchoredStateProvider (org.infinispan.anchored.impl.AnchoredStateProvider)1 EntryFactory (org.infinispan.container.impl.EntryFactory)1 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)1 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)1 ClusteringInterceptor (org.infinispan.interceptors.impl.ClusteringInterceptor)1 CacheNotifier (org.infinispan.notifications.cachelistener.CacheNotifier)1 StateProvider (org.infinispan.statetransfer.StateProvider)1