1

I am using apache ignite, there is a code block that looks like this:

query.setLocalListener(cacheEntryEvents -> {
   Set<String> taskIds = new HashSet<>();
   for (CacheEntryEvent<? extends String, ? extends String> e: cacheEntryEvents){
       if (e.getEventType().equals(EventType.CREATED)) {
           taskIds.add(e.getKey());
       }
   }

   if (!taskIds.isEmpty()){
       Set<String> processedTaskId = this.process(taskIds);
       taskProcessed.addAndGet(processedTaskId.size());
       removeCacheEntryExecutor.removeCache(processedTaskId, inactiveTaskCache);
       log.info("Finish processing {} distributed inactive task", processedTaskId.size());
       log.info("---------------------------Current total processed task: " + taskProcessed);
   }
});

My question is that, does the callback function in this local listener executed as a non-blocking function in a separate thread? Or does it blocks the listener? If the latter case is true, then what happens when this.process(taskIds) takes too long to execute? If the former case is true, how does it manage the separated thread?

João Dias
  • 16,277
  • 6
  • 33
  • 45
Jiayu
  • 11
  • 2

1 Answers1

0

No, Continuous Query should not block the caller and the callback function is being executed on a dedicated thread. Check a similar question

To answer the second question, you need to share your this.process(taskIds) method first.

Alexandr Shapkin
  • 2,350
  • 1
  • 6
  • 10
  • Thank you for the answer. So if a blocking function is invoked in the listener's callback function, then will it execute normally? I tried to remove cache entry in the same thread with the callback function, but it does not work. I have to use an executor to schedule that cache removal in a separate thread. – Jiayu Sep 11 '21 at 06:41
  • Yes, it will be executed normally using blocking functions. As per the second option... Can you please share a reproducer or a CQ listener with the removal ops? I'm almost sure it should work that way, i.e. you should be able to remove a key inside a listener, but I might be missing something. – Alexandr Shapkin Sep 12 '21 at 21:58