Infinispan等效于IMap.valuesPredicate

问题描述

Infinispan是否有与Hazelcast相同的IMap.values(Predicate)?还有可能是非阻塞(异步)?

谢谢。

解决方法

这取决于您要执行的操作。 Infinispan扩展了Java的Stream功能,因此您可以使用Stream接口获取过滤后的值。

示例

//filter by key
cache.values().stream()
    .filterKeys(/*set with keys*/)
    .forEach(/*do something with the value*/) //or collect()

//filter by key and value
cache.getAdvancedCache().cacheEntrySet().stream()
    .filter(entry -> /*check key and value using entry.getKey() or entry.getValue()*/)
    .map(StreamMarshalling.entryToValueFunction()) //extract the value only
    .forEach(/*do something with the value*/; //or collect()

有关流here的Infinispan文档。