You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Hansen Qin <ha...@valorosoltd.com> on 2018/09/07 02:38:59 UTC

回复:how does Ignite Client restart ContinuousQuery when Ignite cluster failed and restart

It is a Map storaging a snapshot of ignite cache data.You can see it defined in my code.

private Map<String, Object> cacheMap = new ConcurrentHashMap<>();

public void continueQueryCache() {
  try {
   IgniteCache<String, Object> clientCache = makeIgniteCache();
   if (clientCache != null) {
    ContinuousQuery<String, Object> query = new ContinuousQuery<>();
    query.setIncludeExpired(true);

    query.setInitialQuery(new ScanQuery<>());

    // listener
    query.setLocalListener(new CacheEntryUpdatedListener<String, Object>() {
     @Override
     public void onUpdated(Iterable<CacheEntryEvent<? extends String, ? extends Object>> evts) {
      for (CacheEntryEvent<? extends String, ? extends Object> e : evts) {
       switch (e.getEventType()) {
       case CREATED:
        cacheMap.put(e.getKey(), e.getValue());
        break;
       case UPDATED:
        cacheMap.put(e.getKey(), e.getValue());
        break;
       case REMOVED:
        cacheMap.remove(e.getKey());
        break;
       case EXPIRED:
        cacheMap.remove(e.getKey());
        break;
       default:
        throw new IllegalStateException("Unknown type: " + e.getEventType());
       }
      }
      LOG.info("reload [{}] objects from remote cache..", cacheMap.size());
     }
    });
    // start query
    QueryCursor<Cache.Entry<String, Object>> cursor = clientCache.query(query);
    for (Entry<String, Object> entry : cursor) {
     cacheMap.put(entry.getKey(), entry.getValue());
    }
   }
  }catch(Exception e) {
   LOG.error("continueQueryCache():get cacheClient error");
  }
 }
------------------------------------------------------------------
发件人:akurbanov <an...@gmail.com>
发送时间:2018年9月6日(星期四) 20:45
收件人:user <us...@ignite.apache.org>
主 题:Re: how does Ignite Client restart ContinuousQuery when Ignite cluster failed and restart

Hello,

Can you clarify what is "local cache" in your use-case? What are you using
as a client for Ignite?



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/


Re: 回复:how does Ignite Client restart ContinuousQuery when Ignite cluster failed and restart

Posted by akurbanov <an...@gmail.com>.
Try using  Near cache <https://apacheignite.readme.io/docs/near-caches>  ,
looks like it perfectly fits what are you have described, you may even use
your expiry policy form distributed cache to be in sync. 

For restarting client refer to documentation:  Reconnecting a client
<https://apacheignite.readme.io/docs/clients-vs-servers#reconnecting-a-client> 
.

Regards.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/