use of org.infinispan.interceptors.impl.ClusteringInterceptor 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();
}
Aggregations