Infinispan 分布式缓存并在主键所有者上执行任务

Infinispan distributed cache and executing tasks on primary key owner

是否可以让 Infinispan (9.4+) 在主键所有者上执行任务?就像如果我给它一个缓存,缓存中的一个键和一个 Runnable/Callable,它可以只对那个键的所有者执行那个任务吗?

这类似于 Hazelcast IExecutorService 的 submitToKeyOwner 或 executeOnKeyOwner。

谢谢。

有几种方法。

如果密钥存在,最简单的方法就是使用 DistributedStreams

cache.entrySet().stream().filterKeys(Collections.singleton(key)).forEach((cache, k) -> <do stuff>);

如果密钥不存在,您可以使用 ClusterExecutor

cacheManager.executor().singleNodeSubmission().filterTargets(Collections.singleton(address) .submit(<runnable>);

调用

即可找到目标地址

Address address = cache.getAdvancedCache().getDistributionManager() .getCacheTopology().getDistributionInfo(key).primary();

我还建议您查看此部分 http://infinispan.org/docs/stable/user_guide/user_guide.html#execute_code_grid