Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/8417#discussion_r40147304
--- Diff:
streaming/src/main/scala/org/apache/spark/streaming/util/RecurringTimer.scala
---
@@ -87,22 +87,32 @@ class RecurringTimer(clock: Clock, period: Long,
callback: (Long) => Unit, name:
prevTime
}
+ private def triggerActionForNextInterval(): Unit = {
+ clock.waitTillTime(nextTime)
+ callback(nextTime)
+ prevTime = nextTime
+ nextTime += period
+ logDebug("Callback for " + name + " called at time " + prevTime)
+ }
+
/**
* Repeatedly call the callback every interval.
*/
private def loop() {
try {
while (!stopped) {
- clock.waitTillTime(nextTime)
- callback(nextTime)
- prevTime = nextTime
- nextTime += period
- logDebug("Callback for " + name + " called at time " + prevTime)
+ triggerActionForNextInterval()
}
+ triggerActionForNextInterval()
} catch {
case e: InterruptedException =>
}
}
+
+ /*
+ * Return whether `stop` is called.
+ */
+ def isStopped: Boolean = stopped
--- End diff --
To be clear this does not signify that stopping is over (that is calling
the callback has been stopped). This is just signifies that the stopping
processing has been started.
I am wondering whether this is ambiguous, and it may be cleaner to actually
capture the three states - Initialized, Started, Stopping, Stopped. Similar to
what you did for the ReceiverTracker some time ago. Then it becomes easy to
read, reason about and test.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]