mgao0 commented on a change in pull request #1000:
URL: https://github.com/apache/helix/pull/1000#discussion_r438286705



##########
File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/CallbackHandler.java
##########
@@ -200,6 +206,43 @@ protected void handleEvent(NotificationContext event) {
         logger.warn("Exception in callback processing thread. Skipping 
callback", e);
       }
     }
+
+    public boolean queueIsEmpty() {
+      return _eventQueue.isEmpty();
+    }
+  }
+
+  /**
+   * This class represents each periodic refresh task
+   * If the deadline passed, enqueue an event to do a refresh
+   * If the deadline has not passed (some events happened in between so don't 
need to do a refresh),
+   * wait until reaching the interval and check again
+   */
+  class RefreshTask implements Runnable {
+    @Override
+    public void run() {
+      try {
+        while (true) {
+          long currentTime = System.currentTimeMillis();
+          long remainingTime = _lastEventTime + _periodicTriggerInterval - 
currentTime;
+          if (remainingTime <= 0) {
+            // If there is no event in the queue, meaning this long idle time 
could be due to lack of events
+            // Otherwise, if there is event in the queue, this long idle time 
is due to slow process of events
+            if (_batchCallbackProcessor == null || 
_batchCallbackProcessor.queueIsEmpty()) {
+              NotificationContext changeContext = new 
NotificationContext(_manager);
+              changeContext.setType(Type.CALLBACK);
+              changeContext.setChangeType(_changeType);
+              enqueueTask(changeContext);
+            }
+            break;
+          } else {
+            wait(remainingTime);
+          }
+        }
+      } catch (Exception e) {

Review comment:
       I have made changes to separate the interrupted exception with other 
exceptions. I will interrupt the thread when interrupted exception is caught, 
is this what you wanted?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to