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-experiments/opendc-experiments-base/src | |
| 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-experiments/opendc-experiments-base/src')
2 files changed, 7 insertions, 7 deletions
diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/Provisioner.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/Provisioner.kt index 7fe3a2eb..66fcca22 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/Provisioner.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/Provisioner.kt @@ -25,7 +25,7 @@ package org.opendc.experiments.provisioner import org.opendc.experiments.MutableServiceRegistry import org.opendc.experiments.ServiceRegistry import org.opendc.experiments.internal.ServiceRegistryImpl -import java.time.Clock +import java.time.InstantSource import java.util.ArrayDeque import java.util.SplittableRandom import kotlin.coroutines.CoroutineContext @@ -38,15 +38,15 @@ import kotlin.coroutines.CoroutineContext * down after the simulation completes. * * @param coroutineContext The [CoroutineContext] in which the environment is set up. - * @param clock The simulation [Clock]. + * @param clock The simulation clock represented as [InstantSource]. * @param seed A seed for initializing the randomness of the environment. */ -public class Provisioner(coroutineContext: CoroutineContext, clock: Clock, seed: Long) : AutoCloseable { +public class Provisioner(coroutineContext: CoroutineContext, clock: InstantSource, seed: Long) : AutoCloseable { /** * Implementation of [ProvisioningContext]. */ private val context = object : ProvisioningContext { - override val clock: Clock = clock + override val clock: InstantSource = clock override val coroutineContext: CoroutineContext = coroutineContext override val seeder: SplittableRandom = SplittableRandom(seed) override val registry: MutableServiceRegistry = ServiceRegistryImpl() diff --git a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/ProvisioningContext.kt b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/ProvisioningContext.kt index b8679872..7eec6fa4 100644 --- a/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/ProvisioningContext.kt +++ b/opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/ProvisioningContext.kt @@ -23,7 +23,7 @@ package org.opendc.experiments.provisioner import org.opendc.experiments.MutableServiceRegistry -import java.time.Clock +import java.time.InstantSource import java.util.SplittableRandom import java.util.random.RandomGenerator import kotlin.coroutines.CoroutineContext @@ -40,9 +40,9 @@ public interface ProvisioningContext { public val coroutineContext: CoroutineContext /** - * The [Clock] tracking the virtual simulation time. + * The [InstantSource] tracking the virtual simulation time. */ - public val clock: Clock + public val clock: InstantSource /** * A [SplittableRandom] instance used to seed the provisioners. |
