From d6d9d37abf17071ff050e45ea37c693e659a4e98 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 28 Sep 2017 03:27:36 +0200 Subject: Implement JPA integration --- .../opendc/extension/topology/Traversable.kt | 43 ---------------------- .../kotlin/nl/atlarge/opendc/kernel/Simulation.kt | 5 +++ .../nl/atlarge/opendc/kernel/sampler/Sampler.kt | 40 ++++++++++++++++++++ .../kotlin/nl/atlarge/opendc/sampler/Sampler.kt | 40 -------------------- .../nl/atlarge/opendc/topology/AdjacencyList.kt | 2 +- .../nl/atlarge/opendc/topology/TopologyBuilder.kt | 11 +----- .../nl/atlarge/opendc/topology/TopologyFactory.kt | 40 ++++++++++++++++++++ .../nl/atlarge/opendc/topology/Traversable.kt | 41 +++++++++++++++++++++ 8 files changed, 129 insertions(+), 93 deletions(-) delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/extension/topology/Traversable.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/sampler/Sampler.kt delete mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/sampler/Sampler.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyFactory.kt create mode 100644 opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Traversable.kt (limited to 'opendc-core/src/main') diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/extension/topology/Traversable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/extension/topology/Traversable.kt deleted file mode 100644 index b5b5ec82..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/extension/topology/Traversable.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.extension.topology - -import nl.atlarge.opendc.topology.Edge - -/** - * Filter a [Set] of [Edge]s based on the tag of the edges and return the origin nodes casted to type `T`. - * - * @param tag The tag of the edges to get. - * @return An [Iterable] of the specified type `T` with the given tag. - */ -inline fun Set>.origins(tag: String) = filter { it.tag == tag }.map { it.from as T } - -/** - * Filter a [Set] of [Edge]s based on the tag of the edges and return the destination nodes casted to type `T`. - * - * @param tag The tag of the edges to get. - * @return An [Iterable] of the specified type `T` with the given tag. - */ -inline fun Set>.destinations(tag: String) = filter { it.tag == tag }.map { it.to as T } diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulation.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulation.kt index 32b45ca2..d07c3ba0 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulation.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/Simulation.kt @@ -61,6 +61,11 @@ interface Simulation { */ val clock: Clock + /** + * The observable state of an [Entity] in simulation, which is provided by the simulation context. + */ + val , S> E.state: S + /** * Step through one cycle in the simulation. This method will process all events in a single tick, update the * internal clock and then return the control to the user. diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/sampler/Sampler.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/sampler/Sampler.kt new file mode 100644 index 00000000..66c33341 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/kernel/sampler/Sampler.kt @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.kernel.sampler + +/** + * A sampler generates data points (samples) of the simulation based on the events that occur to [Entity] instances that + * are part of the simulation. + * + *

[Sampler]s work by observing [Entity] instances in the simulation and transforming this stream of events into a + * stream of data points. + * + *

An example would be a sampler that tracks [Machine] occupation per time unit, which is achieved by observing the + * [Entity]'s event stream and filtering for [JobAssignment] events. + * + * @param The data type of result generated by this sampler. + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface Sampler diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/sampler/Sampler.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/sampler/Sampler.kt deleted file mode 100644 index 2f36e6b7..00000000 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/sampler/Sampler.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 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 nl.atlarge.opendc.sampler - -/** - * A sampler generates data points (samples) of the simulation based on the events that occur to [Entity] instances that - * are part of the simulation. - * - *

[Sampler]s work by observing [Entity] instances in the simulation and transforming this stream of events into a - * stream of data points. - * - *

An example would be a sampler that tracks [Machine] occupation per time unit, which is achieved by observing the - * [Entity]'s event stream and filtering for [JobAssignment] events. - * - * @param The data type of result generated by this sampler. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Sampler diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt index ef9e0396..74b046de 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/AdjacencyList.kt @@ -55,7 +55,7 @@ internal class AdjacencyListTopologyBuilder : TopologyBuilder { * * @return The graph built from this builder. */ - override fun build(): MutableTopology = AdjacencyListTopology() + override fun create(): MutableTopology = AdjacencyListTopology() } /** diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt index d5a57549..bb9c7e8e 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyBuilder.kt @@ -29,19 +29,12 @@ package nl.atlarge.opendc.topology * * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) */ -interface TopologyBuilder { +interface TopologyBuilder : TopologyFactory { /** * Construct a [Topology] from the given block and return it. * * @param block The block to construct the topology. * @return The topology that has been built. */ - fun construct(block: MutableTopology.() -> Unit): MutableTopology = build().apply(block) - - /** - * Build a [Topology] instance from the current state of this builder. - * - * @return The graph built from this builder. - */ - fun build(): MutableTopology + fun construct(block: MutableTopology.() -> Unit): MutableTopology = create().apply(block) } diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyFactory.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyFactory.kt new file mode 100644 index 00000000..42b30a94 --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/TopologyFactory.kt @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * An interface for producing [Topology] instances. Implementors of this interface provide a way of generating a + * topology based on the state of the factory. + * + * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) + */ +interface TopologyFactory { + /** + * Create a [MutableTopology] instance. + * + * @return A mutable topology. + */ + fun create(): MutableTopology +} diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Traversable.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Traversable.kt new file mode 100644 index 00000000..e57060ed --- /dev/null +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/topology/Traversable.kt @@ -0,0 +1,41 @@ +/* + * MIT License + * + * Copyright (c) 2017 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 nl.atlarge.opendc.topology + +/** + * Filter a [Set] of [Edge]s based on the tag of the edges and return the origin nodes casted to type `T`. + * + * @param tag The tag of the edges to get. + * @return An [Iterable] of the specified type `T` with the given tag. + */ +inline fun Set>.origins(tag: String) = filter { it.tag == tag }.map { it.from as T } + +/** + * Filter a [Set] of [Edge]s based on the tag of the edges and return the destination nodes casted to type `T`. + * + * @param tag The tag of the edges to get. + * @return An [Iterable] of the specified type `T` with the given tag. + */ +inline fun Set>.destinations(tag: String) = filter { it.tag == tag }.map { it.to as T } -- cgit v1.2.3