File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
core/src/main/scala/org/apache/spark/util Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,23 @@ private[spark] trait Clock {
2525 def waitTillTime (targetTime : Long ): Long
2626}
2727
28+ /**
29+ * A clock backed by the actual time from the OS as reported by the `System` API.
30+ */
2831private [spark] class SystemClock extends Clock {
2932
3033 val minPollTime = 25L
3134
35+ /**
36+ * @return the same time (milliseconds since the epoch)
37+ * as is reported by `System.currentTimeMillis()`
38+ */
3239 def getTimeMillis (): Long = System .currentTimeMillis()
3340
41+ /**
42+ * @param targetTime block until the current time is at least this value
43+ * @return current system time when wait has completed
44+ */
3445 def waitTillTime (targetTime : Long ): Long = {
3546 var currentTime = 0L
3647 currentTime = System .currentTimeMillis()
Original file line number Diff line number Diff line change 1717
1818package org .apache .spark .util
1919
20- class ManualClock (private var time : Long ) extends Clock {
20+ /**
21+ * A `Clock` whose time can be manually set and modified. Its reported time does not change
22+ * as time elapses, but only as its time is modified by callers. This is mainly useful for
23+ * testing.
24+ *
25+ * @param time initial time (in milliseconds since the epoch)
26+ */
27+ private [spark] class ManualClock (private var time : Long ) extends Clock {
2128
29+ /**
30+ * @return `ManualClock` with initial time 0
31+ */
2232 def this () = this (0L )
2333
2434 def getTimeMillis (): Long =
2535 synchronized {
2636 time
2737 }
2838
39+ /**
40+ * @param timeToSet new time (in milliseconds) that the clock should represent
41+ */
2942 def setTime (timeToSet : Long ) =
3043 synchronized {
3144 time = timeToSet
3245 notifyAll()
3346 }
3447
48+ /**
49+ * @param timeToAdd time (in milliseconds) to add to the clock's time
50+ */
3551 def advance (timeToAdd : Long ) =
36- this . synchronized {
52+ synchronized {
3753 time += timeToAdd
3854 notifyAll()
3955 }
4056
57+ /**
58+ * @param targetTime block until the clock time is set or advanced to at least this time
59+ * @return current time reported by the clock when waiting finishes
60+ */
4161 def waitTillTime (targetTime : Long ): Long =
4262 synchronized {
4363 while (time < targetTime) {
You can’t perform that action at this time.
0 commit comments