Allow for disabling automatic subsystem init

This commit is contained in:
JeremyStar™ 2024-07-16 14:44:32 +02:00
parent 5697522641
commit 85bff3b14d
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 49 additions and 29 deletions

View file

@ -135,26 +135,21 @@ public final class Engine implements SubsystemMainClass {
new EngineConfiguration();
EngineConfiguration.getInstance().loadConfiguration();
// Initialize classes
initializeClasses();
initializeClasses(); // Initialize classes
populateCrashContent(); // Populate crash content
precomputeEventListeners(); // Precompute event listeners
startThreads(); // Start threads
// Populate crash content
populateCrashContent();
// Perform automatic subsystem initialization
if (EngineConfiguration.getInstance().isOptimizeSubsystemInitialization()) {
collectSubsystems(); // Collect subsystems
// Precompute event listeners
precomputeEventListeners();
// Start threads
startThreads();
// Collect subsystems
collectSubsystems();
// Initialize subsystems
try {
initializeSubsystems();
} catch (Exception exception) {
logger.crash("Subsystem dependency resolution failed", exception);
// Initialize subsystems
try {
initializeSubsystems();
} catch (Exception exception) {
logger.crash("Subsystem dependency resolution failed", exception);
}
}
});

View file

@ -87,7 +87,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code debug}.
* Gets the value for {@link #debug}.
*
* @return variable value
* @see EngineConfiguration#debug
@ -102,7 +102,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code debugEvents}.
* Gets the value for {@link #debugEvents}.
*
* @return variable value
* @see EngineConfiguration#debugEvents
@ -118,7 +118,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code debugShortcodeConverter}.
* Gets the value for {@link #debugShortcodeConverter}.
*
* @return variable value
* @see EngineConfiguration#debugShortcodeConverter
@ -135,7 +135,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code errorShortcodeConverter}.
* Gets the value for {@link #errorShortcodeConverter}.
*
* @return variable value
* @see EngineConfiguration#errorShortcodeConverter
@ -150,7 +150,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code loggerLevel}.
* Gets the value for {@link #loggerLevel}.
*
* @return variable value
* @see EngineConfiguration#loggerLevel
@ -165,7 +165,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code loggerTemplate}
* Gets the value for {@link #loggerTemplate}
*
* @return variable value
* @see EngineConfiguration#loggerTemplate
@ -181,7 +181,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code loggerImmediateShutdown}.
* Gets the value for {@link #loggerImmediateShutdown}.
*
* @return variable value
* @see EngineConfiguration#loggerImmediateShutdown
@ -196,7 +196,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code loggerForceStandardOutput}.
* Gets the value for {@link #loggerForceStandardOutput}.
*
* @return variable value
* @see EngineConfiguration#loggerForceStandardOutput
@ -212,7 +212,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha1
*
* -- GETTER --
* Gets the value for {@code loggerForceStandardOutput}.
* Gets the value for {@link #loggerForceStandardOutput}.
*
* @return variable value
* @see EngineConfiguration#loggerForceStandardOutput
@ -229,7 +229,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code optimizeLogging}.
* Gets the value for {@link #optimizeLogging}.
*
* @return variable value
* @see EngineConfiguration#optimizeLogging
@ -245,7 +245,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
* @since v1-alpha0
*
* -- GETTER --
* Gets the value for {@code optimizeEvents}.
* Gets the value for {@link #optimizeEvents}.
*
* @return variable value
* @see EngineConfiguration#optimizeEvents
@ -253,6 +253,26 @@ public final class EngineConfiguration implements SubsystemConfiguration {
*/
private boolean optimizeEvents;
/**
* If enabled, will try to automatically initialize every subsystem found though reflection.
* <p>
* This however may fail in certain situation, where manual subsystem initialization may be required.
* For this reason, this can be turned off before the engine initializes.
* Please note though that dependency resolution between subsystems will not be done, be careful when
* initializing subsystems manually.
*
* @see Engine
* @since v1-alpha2
*
* -- GETTER --
* Gets the value for {@link #optimizeSubsystemInitialization}.
*
* @return variable value
* @see EngineConfiguration#optimizeSubsystemInitialization
* @since v1-alpha2
*/
private boolean optimizeSubsystemInitialization;
/**
* Constructs this class.
*
@ -306,6 +326,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
case "optimizeLogging" -> optimizeLogging = parser.getBoolean(group + property);
case "optimizeEvents" -> optimizeEvents = parser.getBoolean(group + property);
case "optimizeSubsystemInitialization" -> optimizeSubsystemInitialization = parser.getBoolean(group + property);
}
} catch (NullPointerException ignored) {}
}
@ -338,6 +359,7 @@ public final class EngineConfiguration implements SubsystemConfiguration {
optimizeLogging = true;
optimizeEvents = true;
optimizeSubsystemInitialization = true;
}
/** {@inheritDoc} */
@ -380,6 +402,9 @@ public final class EngineConfiguration implements SubsystemConfiguration {
case "optimizeEvents" -> {
return optimizeEvents;
}
case "optimizeSubsystemInitialization" -> {
return optimizeSubsystemInitialization;
}
default -> {
return null;
}