summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-flow/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-flow/src')
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt5
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt20
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt8
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt2
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt4
5 files changed, 22 insertions, 17 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt
index 6fa2971a..5202c252 100644
--- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/FlowForwarder.kt
@@ -226,10 +226,11 @@ public class FlowForwarder(
* Reset the delegate.
*/
private fun reset() {
- if (isCoupled)
+ if (isCoupled) {
_innerCtx?.close()
- else
+ } else {
_innerCtx?.push(0.0)
+ }
delegate = null
hasDelegateStarted = false
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt
index 393a2635..fba3af5f 100644
--- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/internal/FlowConsumerContextImpl.kt
@@ -87,19 +87,21 @@ internal class FlowConsumerContextImpl(
get() = _flags and ConnConvergeSource == ConnConvergeSource
set(value) {
_flags =
- if (value)
+ if (value) {
_flags or ConnConvergeSource
- else
+ } else {
_flags and ConnConvergeSource.inv()
+ }
}
override var shouldConsumerConverge: Boolean
get() = _flags and ConnConvergeConsumer == ConnConvergeConsumer
set(value) {
_flags =
- if (value)
+ if (value) {
_flags or ConnConvergeConsumer
- else
+ } else {
_flags and ConnConvergeConsumer.inv()
+ }
}
/**
@@ -109,10 +111,11 @@ internal class FlowConsumerContextImpl(
get() = _flags and ConnDisableTimers != ConnDisableTimers
set(value) {
_flags =
- if (!value)
+ if (!value) {
_flags or ConnDisableTimers
- else
+ } else {
_flags and ConnDisableTimers.inv()
+ }
}
/**
@@ -241,10 +244,11 @@ internal class FlowConsumerContextImpl(
// IMPORTANT: Re-fetch the flags after the callback might have changed those
flags = _flags
- if (duration != Long.MAX_VALUE)
+ if (duration != Long.MAX_VALUE) {
now + duration
- else
+ } else {
duration
+ }
} else {
deadline
}
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt
index a52a5b0e..d9c6f893 100644
--- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt
@@ -255,7 +255,6 @@ public class MaxMinFlowMultiplexer(
* This method is invoked when one of the inputs converges.
*/
fun convergeInput(input: Input, now: Long) {
-
val lastConverge = _lastConverge
val lastConvergeInput = _lastConvergeInput
val parent = parent
@@ -518,7 +517,7 @@ public class MaxMinFlowMultiplexer(
private val engine: FlowEngine,
private val scheduler: Scheduler,
@JvmField val isCoupled: Boolean,
- initialCapacity: Double,
+ initialCapacity: Double
) : FlowConsumer, FlowConsumerLogic, Comparable<Input> {
/**
* A flag to indicate that the consumer is active.
@@ -787,10 +786,11 @@ public class MaxMinFlowMultiplexer(
return if (_isActivationOutput) {
// If this output is the activation output, synchronously run the scheduler and return the new deadline
val deadline = scheduler.runScheduler(now)
- if (deadline == Long.MAX_VALUE)
+ if (deadline == Long.MAX_VALUE) {
deadline
- else
+ } else {
deadline - now
+ }
} else {
// Output is not the activation output, so trigger activation output and do not install timer for this
// output (by returning `Long.MAX_VALUE`)
diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt
index 1a71580b..2409e174 100644
--- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt
@@ -59,7 +59,7 @@ internal class ForwardingFlowMultiplexerTest {
TraceFlowSource.Fragment(duration * 1000, 3500.0),
TraceFlowSource.Fragment(duration * 1000, 0.0),
TraceFlowSource.Fragment(duration * 1000, 183.0)
- ),
+ )
)
val switch = ForwardingFlowMultiplexer(engine)
diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt
index 34198f17..a6bf8ad8 100644
--- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexerTest.kt
@@ -73,7 +73,7 @@ internal class MaxMinFlowMultiplexerTest {
TraceFlowSource.Fragment(duration * 1000, 3500.0),
TraceFlowSource.Fragment(duration * 1000, 0.0),
TraceFlowSource.Fragment(duration * 1000, 183.0)
- ),
+ )
)
val switch = MaxMinFlowMultiplexer(scheduler)
@@ -111,7 +111,7 @@ internal class MaxMinFlowMultiplexerTest {
TraceFlowSource.Fragment(duration * 1000, 3500.0),
TraceFlowSource.Fragment(duration * 1000, 0.0),
TraceFlowSource.Fragment(duration * 1000, 183.0)
- ),
+ )
)
val workloadB =
TraceFlowSource(