Skip to content

Commit 5ed3a03

Browse files
committed
Javadoc Clock classes; make ManualClock private[spark]
1 parent 169dd13 commit 5ed3a03

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

core/src/main/scala/org/apache/spark/util/Clock.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
*/
2831
private[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()

core/src/main/scala/org/apache/spark/util/ManualClock.scala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,47 @@
1717

1818
package 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) {

0 commit comments

Comments
 (0)