' 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));
}
以上代码无需设置初始查询即可运行。 试着了解什么时候会使用&#39; setInitialQuery&#39;。
答案 0 :(得分:1)
初始查询允许在开始侦听更新之前将光标放在缓存中已有的数据上。它确实是可选的。