use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.
the class ClusteredCacheTest method findCache.
private Optional<Cache<Object, Person>> findCache(Ownership ownership, Object key) {
List<Cache<Object, Person>> caches = caches();
ClusteringDependentLogic cdl = cache1.getAdvancedCache().getComponentRegistry().getComponent(ClusteringDependentLogic.class);
DistributionInfo distribution = cdl.getCacheTopology().getDistribution(key);
Predicate<Cache<?, ?>> predicate = null;
switch(ownership) {
case PRIMARY:
predicate = c -> c.getAdvancedCache().getRpcManager().getAddress().equals(distribution.primary());
break;
case BACKUP:
predicate = c -> distribution.writeBackups().contains(c.getAdvancedCache().getRpcManager().getAddress());
break;
case NON_OWNER:
predicate = c -> !distribution.writeOwners().contains(c.getAdvancedCache().getRpcManager().getAddress());
}
return caches.stream().filter(predicate).findFirst();
}
use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.
the class ClusteringDependentLogicFactory method construct.
@Override
public Object construct(String componentName) {
CacheMode cacheMode = configuration.clustering().cacheMode();
ClusteringDependentLogic cdl;
if (!cacheMode.isClustered()) {
cdl = new ClusteringDependentLogic.LocalLogic();
} else if (cacheMode.isInvalidation()) {
cdl = new ClusteringDependentLogic.InvalidationLogic();
} else if (cacheMode.isReplicated()) {
cdl = new ClusteringDependentLogic.ReplicationLogic();
} else if (cacheMode.isDistributed()) {
cdl = new ClusteringDependentLogic.DistributionLogic();
} else if (cacheMode.isScattered()) {
cdl = new ClusteringDependentLogic.ScatteredLogic();
} else {
throw CONTAINER.factoryCannotConstructComponent(componentName);
}
return cdl;
}
use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.
the class NonTxStateTransferOverwritingValue2Test method blockEntryCommit.
private void blockEntryCommit(final CheckPoint checkPoint, AdvancedCache<Object, Object> cache) {
ClusteringDependentLogic cdl1 = TestingUtil.extractComponent(cache, ClusteringDependentLogic.class);
ClusteringDependentLogic replaceCdl = new ClusteringDependentLogicDelegator(cdl1) {
@Override
public CompletionStage<Void> commitEntry(CacheEntry entry, FlagAffectedCommand command, InvocationContext ctx, Flag trackFlag, boolean l1Invalidation) {
// skip for clear command!
if (entry instanceof ClearCacheEntry) {
return super.commitEntry(entry, command, ctx, trackFlag, l1Invalidation);
}
final Address source = ctx.getOrigin();
CacheEntry newEntry = new CacheEntryDelegator(entry) {
@Override
public void commit(DataContainer container) {
checkPoint.trigger("pre_commit_entry_" + getKey() + "_from_" + source);
try {
checkPoint.awaitStrict("resume_commit_entry_" + getKey() + "_from_" + source, 10, SECONDS);
} catch (InterruptedException | TimeoutException e) {
throw new RuntimeException(e);
}
super.commit(container);
checkPoint.trigger("post_commit_entry_" + getKey() + "_from_" + source);
}
};
return super.commitEntry(newEntry, command, ctx, trackFlag, l1Invalidation);
}
};
TestingUtil.replaceComponent(cache, ClusteringDependentLogic.class, replaceCdl, true);
}
use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.
the class ClusteredConditionalCommandTest method create.
private <K, V> CacheHelper<K, V> create(List<Cache<K, V>> cacheList) {
CacheHelper<K, V> cacheHelper = new CacheHelper<>();
for (Cache<K, V> cache : cacheList) {
ClusteringDependentLogic clusteringDependentLogic = extractComponent(cache, ClusteringDependentLogic.class);
DistributionInfo distributionInfo = clusteringDependentLogic.getCacheTopology().getDistribution(key);
log.debugf("owners for key %s are %s", key, distributionInfo.writeOwners());
if (distributionInfo.isPrimary()) {
log.debug("Cache " + address(cache) + " is the primary owner");
assertTrue(cacheHelper.addCache(Ownership.PRIMARY, cache));
} else if (distributionInfo.isWriteBackup()) {
log.debug("Cache " + address(cache) + " is the backup owner");
assertTrue(cacheHelper.addCache(Ownership.BACKUP, cache));
} else {
log.debug("Cache " + address(cache) + " is the non owner");
assertTrue(cacheHelper.addCache(Ownership.NON_OWNER, cache) || cacheMode.isScattered());
}
}
return cacheHelper;
}
Aggregations