diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 11:48:59 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 12:03:38 +0200 |
| commit | 3528091684f610d80fcebb5b730d3a201e79a99a (patch) | |
| tree | d39ddff0957924b1a9cfbcc5cd2a4fd5f3349798 /opendc-compute | |
| parent | cdc7df3c3d398a7af15014b4c0f6cd495c05fcce (diff) | |
feat(sim/compute): Add completion parameter to startWorkload
This change updates the interface of `SimMachine#startWorkload` to
introduce a parameter `completion` that is invoked when the workload
completes either succesfully or due to failure.
This functionality has often been implemented by wrapping a
`SimWorkload` and catching its exceptions. However, since this
functionality is used in all usages of `SimMachine#startWorkload` we
instead embed it into `SimMachine` itself.
Diffstat (limited to 'opendc-compute')
| -rw-r--r-- | opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt index c07649bd..d07c50bc 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt @@ -43,7 +43,6 @@ import org.opendc.simulator.compute.model.MachineModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit -import org.opendc.simulator.compute.workload.SimWorkload import org.opendc.simulator.flow2.FlowGraph import java.time.Duration import java.time.Instant @@ -284,30 +283,12 @@ public class SimHost( check(_ctx == null) { "Concurrent hypervisor running" } // Launch hypervisor onto machine - _ctx = machine.startWorkload( - object : SimWorkload { - override fun onStart(ctx: SimMachineContext) { - try { - _bootTime = clock.instant() - _state = HostState.UP - hypervisor.onStart(ctx) - } catch (cause: Throwable) { - _state = HostState.ERROR - _ctx = null - throw cause - } - } - - override fun onStop(ctx: SimMachineContext) { - try { - hypervisor.onStop(ctx) - } finally { - _ctx = null - } - } - }, - emptyMap() - ) + _bootTime = clock.instant() + _state = HostState.UP + _ctx = machine.startWorkload(hypervisor, emptyMap()) { cause -> + _state = if (cause != null) HostState.ERROR else HostState.DOWN + _ctx = null + } } /** |
