summaryrefslogtreecommitdiff
path: root/opendc-experiments/opendc-experiments-base/src/main/kotlin
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-11-09 21:59:07 +0000
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-11-13 17:42:01 +0000
commitfb2672afb2d8236d5291cd028196c99d8e4d47f1 (patch)
tree508bbec117239b3d8490cd1bde8d12b6a8ab2155 /opendc-experiments/opendc-experiments-base/src/main/kotlin
parent00ac59e8e9d6a41c2eac55aa25420dce8fa9c6e0 (diff)
refactor: Replace use of CoroutineContext by Dispatcher
This change replaces the use of `CoroutineContext` for passing the `SimulationDispatcher` across the different modules of OpenDC by the lightweight `Dispatcher` interface of the OpenDC common module.
Diffstat (limited to 'opendc-experiments/opendc-experiments-base/src/main/kotlin')
-rw-r--r--opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/Provisioner.kt11
-rw-r--r--opendc-experiments/opendc-experiments-base/src/main/kotlin/org/opendc/experiments/provisioner/ProvisioningContext.kt14
2 files changed, 8 insertions, 17 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 66fcca22..eae5806e 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
@@ -22,13 +22,12 @@
package org.opendc.experiments.provisioner
+import org.opendc.common.Dispatcher
import org.opendc.experiments.MutableServiceRegistry
import org.opendc.experiments.ServiceRegistry
import org.opendc.experiments.internal.ServiceRegistryImpl
-import java.time.InstantSource
import java.util.ArrayDeque
import java.util.SplittableRandom
-import kotlin.coroutines.CoroutineContext
/**
* A helper class to set up the experimental environment in a reproducible manner.
@@ -37,17 +36,15 @@ import kotlin.coroutines.CoroutineContext
* [ProvisioningStep]s are executed sequentially and ensure that the necessary infrastructure is configured and teared
* down after the simulation completes.
*
- * @param coroutineContext The [CoroutineContext] in which the environment is set up.
- * @param clock The simulation clock represented as [InstantSource].
+ * @param dispatcher The [Dispatcher] implementation for scheduling future tasks.
* @param seed A seed for initializing the randomness of the environment.
*/
-public class Provisioner(coroutineContext: CoroutineContext, clock: InstantSource, seed: Long) : AutoCloseable {
+public class Provisioner(dispatcher: Dispatcher, seed: Long) : AutoCloseable {
/**
* Implementation of [ProvisioningContext].
*/
private val context = object : ProvisioningContext {
- override val clock: InstantSource = clock
- override val coroutineContext: CoroutineContext = coroutineContext
+ override val dispatcher: Dispatcher = dispatcher
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 7eec6fa4..e53044ce 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
@@ -22,27 +22,21 @@
package org.opendc.experiments.provisioner
+import org.opendc.common.Dispatcher
import org.opendc.experiments.MutableServiceRegistry
-import java.time.InstantSource
import java.util.SplittableRandom
import java.util.random.RandomGenerator
-import kotlin.coroutines.CoroutineContext
/**
* The [ProvisioningContext] class provides access to shared state between subsequent [ProvisioningStep]s, as well as
- * access to the simulation dispatcher (via [CoroutineContext]), the virtual clock, and a randomness seeder to allow
+ * access to the simulation dispatcher, the virtual clock, and a randomness seeder to allow
* the provisioning steps to initialize the (simulated) resources.
*/
public interface ProvisioningContext {
/**
- * The [CoroutineContext] in which the provisioner runs.
+ * The [Dispatcher] provided by the provisioner to schedule future events during the simulation.
*/
- public val coroutineContext: CoroutineContext
-
- /**
- * The [InstantSource] tracking the virtual simulation time.
- */
- public val clock: InstantSource
+ public val dispatcher: Dispatcher
/**
* A [SplittableRandom] instance used to seed the provisioners.