Fix engine
This commit is contained in:
parent
36da65b45e
commit
a1e843f61e
3 changed files with 122 additions and 13 deletions
|
@ -22,11 +22,13 @@ package de.staropensource.engine.base
|
||||||
import de.staropensource.engine.base.exception.EngineInitializationFailureException
|
import de.staropensource.engine.base.exception.EngineInitializationFailureException
|
||||||
import de.staropensource.engine.base.implementable.Subsystem
|
import de.staropensource.engine.base.implementable.Subsystem
|
||||||
import de.staropensource.engine.base.logging.Logger
|
import de.staropensource.engine.base.logging.Logger
|
||||||
|
import de.staropensource.engine.base.platform.platformEngineBootstrap
|
||||||
|
import de.staropensource.engine.base.platform.platformEngineInitialize
|
||||||
|
import de.staropensource.engine.base.platform.platformEngineReload
|
||||||
|
import de.staropensource.engine.base.platform.platformEngineShutdown
|
||||||
import de.staropensource.engine.base.utility.Environment
|
import de.staropensource.engine.base.utility.Environment
|
||||||
import de.staropensource.engine.base.utility.FileAccess
|
import de.staropensource.engine.base.utility.FileAccess
|
||||||
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
||||||
import java.nio.charset.Charset
|
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
import kotlin.jvm.JvmStatic
|
import kotlin.jvm.JvmStatic
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
@ -186,9 +188,7 @@ class Engine private constructor() {
|
||||||
logger.info("Bootstrapping")
|
logger.info("Bootstrapping")
|
||||||
|
|
||||||
// Run bootstrapping code
|
// Run bootstrapping code
|
||||||
// -> Run checks
|
platformEngineBootstrap()
|
||||||
if (Charset.defaultCharset() != StandardCharsets.UTF_8)
|
|
||||||
logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8")
|
|
||||||
|
|
||||||
// Bootstrap subsystems
|
// Bootstrap subsystems
|
||||||
logger.verb("Bootstrapping subsystems")
|
logger.verb("Bootstrapping subsystems")
|
||||||
|
@ -243,6 +243,7 @@ class Engine private constructor() {
|
||||||
logger.info("Initializing")
|
logger.info("Initializing")
|
||||||
|
|
||||||
// Run initialization code
|
// Run initialization code
|
||||||
|
platformEngineInitialize()
|
||||||
Environment.detect()
|
Environment.detect()
|
||||||
FileAccess.updateDefaultPaths()
|
FileAccess.updateDefaultPaths()
|
||||||
info = BuildInformation(loadPrefix = "sosengine-base")
|
info = BuildInformation(loadPrefix = "sosengine-base")
|
||||||
|
@ -303,7 +304,7 @@ class Engine private constructor() {
|
||||||
logger.info("Reloading")
|
logger.info("Reloading")
|
||||||
|
|
||||||
// Run reload code
|
// Run reload code
|
||||||
// *none yet*
|
platformEngineReload()
|
||||||
|
|
||||||
// Reload subsystems
|
// Reload subsystems
|
||||||
logger.verb("Reloading subsystems")
|
logger.verb("Reloading subsystems")
|
||||||
|
@ -399,13 +400,7 @@ class Engine private constructor() {
|
||||||
state = State.SHUTTING_DOWN
|
state = State.SHUTTING_DOWN
|
||||||
val infoLocal: BuildInformation? = info
|
val infoLocal: BuildInformation? = info
|
||||||
|
|
||||||
// Run shutdown code
|
// Shut subsystems down
|
||||||
Environment.unset()
|
|
||||||
FileAccess.deleteScheduled()
|
|
||||||
FileAccess.unsetDefaultPaths()
|
|
||||||
info = null
|
|
||||||
|
|
||||||
// Initialize subsystems
|
|
||||||
logger.verb("Shutting subsystems down")
|
logger.verb("Shutting subsystems down")
|
||||||
for (subsystem: Subsystem in subsystems) {
|
for (subsystem: Subsystem in subsystems) {
|
||||||
val subsystemVersion: String = subsystem.getVersion()
|
val subsystemVersion: String = subsystem.getVersion()
|
||||||
|
@ -422,6 +417,13 @@ class Engine private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run shutdown code
|
||||||
|
Environment.unset()
|
||||||
|
FileAccess.deleteScheduled()
|
||||||
|
FileAccess.unsetDefaultPaths()
|
||||||
|
info = null
|
||||||
|
platformEngineShutdown(final, crashed)
|
||||||
|
|
||||||
// Print shutdown message
|
// Print shutdown message
|
||||||
if (final)
|
if (final)
|
||||||
logger.info("""
|
logger.info("""
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||||
|
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||||
|
* Licensed under the GNU General Public License v3.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.staropensource.engine.base.platform
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.Engine
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstraps this platform.
|
||||||
|
*
|
||||||
|
* Invoked by [Engine.bootstrap] first.
|
||||||
|
*
|
||||||
|
* @throws Throwable on error
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
expect fun platformEngineBootstrap()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes this platform.
|
||||||
|
*
|
||||||
|
* Invoked by [Engine.initialize] first.
|
||||||
|
*
|
||||||
|
* @throws Throwable on error
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
expect fun platformEngineInitialize()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads this platform.
|
||||||
|
*
|
||||||
|
* Invoked by [Engine.reload] first.
|
||||||
|
*
|
||||||
|
* @throws Throwable on error
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
expect fun platformEngineReload()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts this platform down.
|
||||||
|
*
|
||||||
|
* Invoked by one of the
|
||||||
|
* engine's shutdown methods
|
||||||
|
* last.
|
||||||
|
*
|
||||||
|
* @param final whether this is the last time the engine shuts down. Doesn't actually shut the application down, just changes some messages and does other things
|
||||||
|
* @param crashed enables super careful mode to prevent further breakage
|
||||||
|
* @throws Throwable on error
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
expect fun platformEngineShutdown(final: Boolean, crashed: Boolean = false)
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* STAROPENSOURCE ENGINE SOURCE FILE
|
||||||
|
* Copyright (c) 2024 The StarOpenSource Engine Authors
|
||||||
|
* Licensed under the GNU General Public License v3.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.staropensource.engine.base.platform
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.Engine.Companion.logger
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
|
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
actual fun platformEngineBootstrap() {
|
||||||
|
if (Charset.defaultCharset() != StandardCharsets.UTF_8)
|
||||||
|
logger.crash("The StarOpenSource Engine does not support other charsets than UTF-8")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
actual fun platformEngineInitialize() = Unit
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
actual fun platformEngineReload() = Unit
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
actual fun platformEngineShutdown(final: Boolean, crashed: Boolean) = Unit
|
Loading…
Reference in a new issue