diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-11-09 17:25:59 +0000 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-11-13 15:24:47 +0000 |
| commit | 7a4b2c45a9926de59754b1d7219159656eea6e6d (patch) | |
| tree | 4cf2cd842ec046128401a5b15bd42d86505422c6 /opendc-compute/opendc-compute-service/src/main | |
| parent | c22d744464f91eaa5f1aabee408351e864f36f1d (diff) | |
refactor: Use InstantSource as time source
This change updates the modules of OpenDC to always accept
the `InstantSource` interface as source of time. Previously we used
`java.time.Clock`, but this class is bound to a time zone which does not
make sense for our use-cases.
Since `java.time.Clock` implements `java.time.InstantSource`, it can be
used in places that require an `InstantSource` as parameter. Conversion
from `InstantSource` to `Clock` is also possible by invoking
`InstantSource#withZone`.
Diffstat (limited to 'opendc-compute/opendc-compute-service/src/main')
2 files changed, 4 insertions, 4 deletions
diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt index 85222c10..4ced9569 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/ComputeService.kt @@ -28,8 +28,8 @@ import org.opendc.compute.service.driver.Host import org.opendc.compute.service.internal.ComputeServiceImpl import org.opendc.compute.service.scheduler.ComputeScheduler import org.opendc.compute.service.telemetry.SchedulerStats -import java.time.Clock import java.time.Duration +import java.time.InstantSource import kotlin.coroutines.CoroutineContext /** @@ -87,7 +87,7 @@ public interface ComputeService : AutoCloseable { */ public operator fun invoke( context: CoroutineContext, - clock: Clock, + clock: InstantSource, scheduler: ComputeScheduler, schedulingQuantum: Duration = Duration.ofMinutes(5) ): ComputeService { diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt index b377c3e3..2b755988 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/internal/ComputeServiceImpl.kt @@ -35,9 +35,9 @@ import org.opendc.compute.service.driver.HostListener import org.opendc.compute.service.driver.HostState import org.opendc.compute.service.scheduler.ComputeScheduler import org.opendc.compute.service.telemetry.SchedulerStats -import java.time.Clock import java.time.Duration import java.time.Instant +import java.time.InstantSource import java.util.ArrayDeque import java.util.Deque import java.util.Random @@ -55,7 +55,7 @@ import kotlin.math.max */ internal class ComputeServiceImpl( coroutineContext: CoroutineContext, - private val clock: Clock, + private val clock: InstantSource, private val scheduler: ComputeScheduler, schedulingQuantum: Duration ) : ComputeService, HostListener { |
