“setInitialQuery”的用途是什么?
IgniteCache<Integer, String> cache = ignite.cache("mycache");
// Create new continuous query.
ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();
// Optional initial query to select all keys greater than 10.
qry.setInitialQuery(new ScanQuery<Integer, String>((k, v) -> k > 10)):
// Callback that is called locally when update notifications are received.
qry.setLocalListener((evts) ->
evts.forEach(e -> System.out.println("key=" + e.getKey() + ", val=" + e.getValue())));
// This filter will be evaluated remotely on all nodes.
// Entry that pass this filter will be sent to the caller.
qry.setRemoteFilter(e -> e.getKey() > 10);
// Execute query.
try (QueryCursor<Cache.Entry<Integer, String>> cur = cache.query(qry)) {
// Iterate through existing data stored in cache.
for (Cache.Entry<Integer, String> e : cur)
System.out.println("key=" + e.getKey() + ", val=" + e.getValue());
// Add a few more keys and watch a few more query notifications.
for (int i = 5; i < 15; i++)
cache.put(i, Integer.toString(i));
}
上面的代码无需设置初始查询即可工作。 尝试了解何时使用“setInitialQuery”。
最佳答案
初始查询允许在开始监听更新之前将光标置于缓存中已有的数据上。这确实是可选的。
关于java - Apache Ignite - 连续查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46740212/