2017-10-14 1 views
2

'setInitialQuery'의 목적은 무엇입니까?Apache Ignite - 연속 쿼리

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'를 언제 사용하는지 이해하려고 시도했습니다.

답변

1

초기 쿼리를 사용하면 업데이트 수신을 시작하기 전에 이미 캐시에있는 데이터 위로 커서를 가져갈 수 있습니다. 참으로 선택 사항입니다.