summaryrefslogtreecommitdiff
path: root/opendc-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-28 14:41:50 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-28 15:24:17 +0200
commit8bf940eb7b59b5e5e326cfc06d51bdb54393f33b (patch)
tree06c09e29737b219726772ef3d7deb3006ac06493 /opendc-compute
parentdd5bbd55fc6e25efdfe93ec16bd37c5350e04c16 (diff)
perf(compute/sim): Use static logger field
This change updates the `Guest` class implementation to use a static logger field instead of allocation a new logger for every guest.
Diffstat (limited to 'opendc-compute')
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt14
1 files changed, 7 insertions, 7 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
index c12e6fad..ca947625 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
@@ -49,11 +49,6 @@ internal class Guest(
val machine: SimVirtualMachine
) {
/**
- * The logger instance of this guest.
- */
- private val logger = KotlinLogging.logger {}
-
- /**
* The state of the [Guest].
*
* [ServerState.PROVISIONING] is an invalid value for a guest, since it applies before the host is selected for
@@ -68,12 +63,12 @@ internal class Guest(
fun start() {
when (state) {
ServerState.TERMINATED, ServerState.ERROR -> {
- logger.info { "User requested to start server ${server.uid}" }
+ LOGGER.info { "User requested to start server ${server.uid}" }
doStart()
}
ServerState.RUNNING -> return
ServerState.DELETED -> {
- logger.warn { "User tried to start deleted server" }
+ LOGGER.warn { "User tried to start deleted server" }
throw IllegalArgumentException("Server is deleted")
}
else -> assert(false) { "Invalid state transition" }
@@ -239,4 +234,9 @@ internal class Guest(
_downtime += duration
}
}
+
+ private companion object {
+ @JvmStatic
+ private val LOGGER = KotlinLogging.logger {}
+ }
}