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/mux/FlowMultiplexer.kt10
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexerFactory.kt60
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt6
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/MaxMinFlowMultiplexer.kt5
4 files changed, 81 insertions, 0 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexer.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexer.kt
index 3b4583e2..8752c559 100644
--- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexer.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexer.kt
@@ -31,6 +31,16 @@ import org.opendc.simulator.flow.FlowSource
*/
public interface FlowMultiplexer {
/**
+ * The maximum number of inputs supported by the multiplexer.
+ */
+ public val maxInputs: Int
+
+ /**
+ * The maximum number of outputs supported by the multiplexer.
+ */
+ public val maxOutputs: Int
+
+ /**
* The inputs of the multiplexer that can be used to consume sources.
*/
public val inputs: Set<FlowConsumer>
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexerFactory.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexerFactory.kt
new file mode 100644
index 00000000..a863e3ad
--- /dev/null
+++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/FlowMultiplexerFactory.kt
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2022 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.simulator.flow.mux
+
+import org.opendc.simulator.flow.FlowConvergenceListener
+import org.opendc.simulator.flow.FlowEngine
+
+/**
+ * Factory interface for a [FlowMultiplexer] implementation.
+ */
+public fun interface FlowMultiplexerFactory {
+ /**
+ * Construct a new [FlowMultiplexer] using the specified [engine] and [listener].
+ */
+ public fun newMultiplexer(engine: FlowEngine, listener: FlowConvergenceListener?): FlowMultiplexer
+
+ public companion object {
+ /**
+ * A [FlowMultiplexerFactory] constructing a [MaxMinFlowMultiplexer].
+ */
+ private val MAX_MIN_FACTORY = FlowMultiplexerFactory { engine, listener -> MaxMinFlowMultiplexer(engine, listener) }
+
+ /**
+ * A [FlowMultiplexerFactory] constructing a [ForwardingFlowMultiplexer].
+ */
+ private val FORWARDING_FACTORY = FlowMultiplexerFactory { engine, listener -> ForwardingFlowMultiplexer(engine, listener) }
+
+ /**
+ * Return a [FlowMultiplexerFactory] that returns [MaxMinFlowMultiplexer] instances.
+ */
+ @JvmStatic
+ public fun maxMinMultiplexer(): FlowMultiplexerFactory = MAX_MIN_FACTORY
+
+ /**
+ * Return a [ForwardingFlowMultiplexer] that returns [ForwardingFlowMultiplexer] instances.
+ */
+ @JvmStatic
+ public fun forwardingMultiplexer(): FlowMultiplexerFactory = FORWARDING_FACTORY
+ }
+}
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt
index c18b2701..c50e9bbc 100644
--- a/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/main/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexer.kt
@@ -37,6 +37,12 @@ public class ForwardingFlowMultiplexer(
private val engine: FlowEngine,
private val listener: FlowConvergenceListener? = null
) : FlowMultiplexer, FlowConvergenceListener {
+
+ override val maxInputs: Int
+ get() = _outputs.size
+
+ override val maxOutputs: Int = Int.MAX_VALUE
+
override val inputs: Set<FlowConsumer>
get() = _inputs
private val _inputs = mutableSetOf<Input>()
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 7605f67d..f2a4c1a4 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
@@ -37,6 +37,11 @@ public class MaxMinFlowMultiplexer(
private val engine: FlowEngine,
parent: FlowConvergenceListener? = null
) : FlowMultiplexer {
+
+ override val maxInputs: Int = Int.MAX_VALUE
+
+ override val maxOutputs: Int = Int.MAX_VALUE
+
/**
* The inputs of the multiplexer.
*/