Fix variable name convention

This commit is contained in:
JeremyStar™ 2024-11-03 18:32:40 +01:00
parent a619746e8d
commit a21ef1bc5f
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 68 additions and 56 deletions

View file

@ -34,6 +34,7 @@ import de.staropensource.engine.base.type.DependencyVector;
import de.staropensource.engine.base.type.EngineState; import de.staropensource.engine.base.type.EngineState;
import de.staropensource.engine.base.type.immutable.ImmutableLinkedList; import de.staropensource.engine.base.type.immutable.ImmutableLinkedList;
import de.staropensource.engine.base.utility.DependencyResolver; import de.staropensource.engine.base.utility.DependencyResolver;
import de.staropensource.engine.base.utility.FileAccess;
import de.staropensource.engine.base.utility.Miscellaneous; import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.base.utility.PlaceholderEngine; import de.staropensource.engine.base.utility.PlaceholderEngine;
import de.staropensource.engine.base.utility.information.EngineInformation; import de.staropensource.engine.base.utility.information.EngineInformation;
@ -90,7 +91,7 @@ public final class Engine extends SubsystemClass {
* @see LoggerInstance * @see LoggerInstance
* @since v1-alpha0 * @since v1-alpha0
*/ */
private static final LoggerInstance logger = new LoggerInstance.Builder().setClazz(Engine.class).setOrigin("ENGINE").setMetadata(EngineInformation.getVersioningCodename()).build(); private static final LoggerInstance LOGGER = new LoggerInstance.Builder().setClazz(Engine.class).setOrigin("ENGINE").setMetadata(EngineInformation.getVersioningCodename()).build();
/** /**
* Contains the engine state. * Contains the engine state.
@ -169,7 +170,7 @@ public final class Engine extends SubsystemClass {
} }
// Print warning about shutdown // Print warning about shutdown
logger.warn("Trying to shut down engine using shutdown hook.\nThis approach to shutting down the engine and JVM is NOT RECOMMENDED, please use Engine#shutdown() instead."); LOGGER.warn("Trying to shut down engine using shutdown hook.\nThis approach to shutting down the engine and JVM is NOT RECOMMENDED, please use Engine#shutdown() instead.");
// Shutdown // Shutdown
Engine.getInstance().shutdown(); Engine.getInstance().shutdown();
@ -192,7 +193,7 @@ public final class Engine extends SubsystemClass {
new EngineConfiguration(); new EngineConfiguration();
EngineConfiguration.getInstance().loadConfiguration(); EngineConfiguration.getInstance().loadConfiguration();
logger.info("Initializing engine"); LOGGER.info("Initializing engine");
initializeClasses(); // Initialize classes initializeClasses(); // Initialize classes
if (checkEnvironment()) // Check environment if (checkEnvironment()) // Check environment
throw new IllegalStateException("Running in an incompatible environment"); throw new IllegalStateException("Running in an incompatible environment");
@ -201,7 +202,7 @@ public final class Engine extends SubsystemClass {
cacheEvents(); // Cache event listeners cacheEvents(); // Cache event listeners
startThreads(); // Start threads startThreads(); // Start threads
logger.verb("Completing early initialization stage"); LOGGER.verb("Completing early initialization stage");
state = EngineState.STARTUP; state = EngineState.STARTUP;
// Perform automatic subsystem initialization // Perform automatic subsystem initialization
@ -212,14 +213,14 @@ public final class Engine extends SubsystemClass {
try { try {
initializeSubsystems(); initializeSubsystems();
} catch (Exception exception) { } catch (Exception exception) {
logger.error("Subsystem dependency resolution failed"); LOGGER.error("Subsystem dependency resolution failed");
} }
} }
}); });
logger.verb("Completing late initialization stage"); LOGGER.verb("Completing late initialization stage");
state = EngineState.RUNNING; state = EngineState.RUNNING;
logger.info("Initialized sos!engine %engine_version% (commit %engine_git_commit_id_long%-%engine_git_branch%, dirty %engine_git_dirty%) in " + initTime + "ms\nThe StarOpenSource Engine is licensed under the GNU AGPL v3. Copyright (c) 2024 The StarOpenSource Engine Authors."); LOGGER.info("Initialized sos!engine %engine_version% (commit %engine_git_commit_id_long%-%engine_git_branch%, dirty %engine_git_dirty%) in " + initTime + "ms\nThe StarOpenSource Engine is licensed under the GNU AGPL v3. Copyright (c) 2024 The StarOpenSource Engine Authors.");
} }
/** /**
@ -237,10 +238,10 @@ public final class Engine extends SubsystemClass {
} catch (IllegalStateException exception) { } catch (IllegalStateException exception) {
throw exception; throw exception;
} catch (Exception exception) { } catch (Exception exception) {
logger.error("Engine initialization failed"); LOGGER.error("Engine initialization failed");
logger.error(Miscellaneous.getStackTraceHeader(exception)); LOGGER.error(Miscellaneous.getStackTraceHeader(exception));
for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n")) for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n"))
logger.error(line); LOGGER.error(line);
throw new RuntimeException("Engine initialization failed", exception); throw new RuntimeException("Engine initialization failed", exception);
} }
} }
@ -251,12 +252,16 @@ public final class Engine extends SubsystemClass {
* @since v1-alpha0 * @since v1-alpha0
*/ */
private void initializeClasses() { private void initializeClasses() {
logger.verb("Initializing engine classes"); LOGGER.verb("Initializing engine classes");
// Initialize essential engine classes
new EngineInternals(); new EngineInternals();
PlaceholderEngine.initialize(); PlaceholderEngine.initialize();
EngineInformation.update(); EngineInformation.update();
// Non-essential engine classes
PrintStreamService.initializeStreams(); PrintStreamService.initializeStreams();
FileAccess.initializeInstances();
} }
/** /**
@ -265,35 +270,35 @@ public final class Engine extends SubsystemClass {
* @since v1-alpha4 * @since v1-alpha4
*/ */
private boolean checkEnvironment() { private boolean checkEnvironment() {
logger.diag("Checking environment"); LOGGER.diag("Checking environment");
// Warn about potential Java incompatibilities // Warn about potential Java incompatibilities
if (JvmInformation.getJavaVersion() > EngineInformation.getJavaSource()) if (JvmInformation.getJavaVersion() > EngineInformation.getJavaSource())
logger.warn("The StarOpenSource Engine is running on an untested Java version.\nThings may not work as expected or features which can improve performance, stability, compatibility or ease of use may be missing.\nIf you encounter issues, try running a JVM implementing Java " + EngineInformation.getJavaSource()); LOGGER.warn("The StarOpenSource Engine is running on an untested Java version.\nThings may not work as expected or features which can improve performance, stability, compatibility or ease of use may be missing.\nIf you encounter issues, try running a JVM implementing Java " + EngineInformation.getJavaSource());
// Shutdown if running in an unsupported JVM // Shutdown if running in an unsupported JVM
if (JvmInformation.getImplementationName().equals("Substrate VM") && JvmInformation.getImplementationVendor().equals("GraalVM Community")) { if (JvmInformation.getImplementationName().equals("Substrate VM") && JvmInformation.getImplementationVendor().equals("GraalVM Community")) {
logger.error("##############################################################################################"); LOGGER.error("##############################################################################################");
logger.error("## Running in Substrate VM, which is the name of the JVM used by GraalVM native-image. ##"); LOGGER.error("## Running in Substrate VM, which is the name of the JVM used by GraalVM native-image. ##");
logger.error("## The StarOpenSource Engine does not support native-image as using reflection in a certain ##"); LOGGER.error("## The StarOpenSource Engine does not support native-image as using reflection in a certain ##");
logger.error("## way seems to cause the Substrate JVM to crash. Workarounds have failed. ##"); LOGGER.error("## way seems to cause the Substrate JVM to crash. Workarounds have failed. ##");
logger.error("## This has already been noted in issue #3, which you can view here: ##"); LOGGER.error("## This has already been noted in issue #3, which you can view here: ##");
logger.error("## https://git.staropensource.de/StarOpenSource/Engine/issues/3 ##"); LOGGER.error("## https://git.staropensource.de/StarOpenSource/Engine/issues/3 ##");
logger.error("## ##"); LOGGER.error("## ##");
logger.error("## While this is sad, we unfortunately can't do anything against it unless we introduce ##"); LOGGER.error("## While this is sad, we unfortunately can't do anything against it unless we introduce ##");
logger.error("## annoying and stupid changes into the engine, which we don't want to do. ##"); LOGGER.error("## annoying and stupid changes into the engine, which we don't want to do. ##");
logger.error("## ##"); LOGGER.error("## ##");
logger.error("## We're truly sorry for this inconvenience. The sos!engine will now terminate. ##"); LOGGER.error("## We're truly sorry for this inconvenience. The sos!engine will now terminate. ##");
logger.error("##############################################################################################"); LOGGER.error("##############################################################################################");
Runtime.getRuntime().exit(255); Runtime.getRuntime().exit(255);
} }
// Check if reflective classpath scanning is supported // Check if reflective classpath scanning is supported
if (checkClasspathScanningSupport()) { if (checkClasspathScanningSupport()) {
logger.warn("Running in an classpath scanning-unfriendly environment, disabling."); LOGGER.warn("Running in an classpath scanning-unfriendly environment, disabling.");
logger.warn("If shit doesn't work and is expected to be discovered by annotations, you'll need to"); LOGGER.warn("If shit doesn't work and is expected to be discovered by annotations, you'll need to");
logger.warn("either register it first or have to place classes in some package."); LOGGER.warn("either register it first or have to place classes in some package.");
logger.warn("Please consult sos!engine's documentation for more information about this issue."); LOGGER.warn("Please consult sos!engine's documentation for more information about this issue.");
EngineInternals.getInstance().overrideReflectiveClasspathScanning(false); EngineInternals.getInstance().overrideReflectiveClasspathScanning(false);
} }
@ -328,7 +333,7 @@ public final class Engine extends SubsystemClass {
*/ */
@SuppressWarnings({ "ExtractMethodRecommender" }) @SuppressWarnings({ "ExtractMethodRecommender" })
private void populateCrashContent() { private void populateCrashContent() {
logger.diag("Populating crash content"); LOGGER.diag("Populating crash content");
// Issuer // Issuer
Map<@NotNull String, @NotNull String> crashContentIssuer = new LinkedHashMap<>(); Map<@NotNull String, @NotNull String> crashContentIssuer = new LinkedHashMap<>();
@ -379,7 +384,7 @@ public final class Engine extends SubsystemClass {
* @since v1-alpha0 * @since v1-alpha0
*/ */
private void cacheEvents() { private void cacheEvents() {
logger.diag("Caching events"); LOGGER.diag("Caching events");
// Internal events // Internal events
EventHelper.cacheEvent(InternalEngineShutdownEvent.class); EventHelper.cacheEvent(InternalEngineShutdownEvent.class);
@ -397,8 +402,8 @@ public final class Engine extends SubsystemClass {
* *
* @since v1-alpha1 * @since v1-alpha1
*/ */
public void startThreads() { private void startThreads() {
logger.diag("Starting threads"); LOGGER.diag("Starting threads");
LoggingThread.startThread(); LoggingThread.startThread();
} }
@ -424,14 +429,14 @@ public final class Engine extends SubsystemClass {
if (initializedClassRaw instanceof SubsystemClass) if (initializedClassRaw instanceof SubsystemClass)
initializedClass = (SubsystemClass) initializedClassRaw; initializedClass = (SubsystemClass) initializedClassRaw;
else else
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Does not implement " + SubsystemClass.class.getName()); LOGGER.crash("Failed to initialize subsystem " + clazz.getName() + ": Does not implement " + SubsystemClass.class.getName());
//noinspection DataFlowIssue // the crash call will prevent a NullPointerException //noinspection DataFlowIssue // the crash call will prevent a NullPointerException
subsystemsMutable.add(new DependencySubsystemVector(initializedClass.getDependencyVector(), initializedClass)); subsystemsMutable.add(new DependencySubsystemVector(initializedClass.getDependencyVector(), initializedClass));
} catch (Exception exception) { } catch (Exception exception) {
if (exception.getClass() == IllegalStateException.class && exception.getMessage().startsWith("The version string is invalid: ")) if (exception.getClass() == IllegalStateException.class && exception.getMessage().startsWith("The version string is invalid: "))
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Invalid version string: " + exception.getMessage().replace("The version string is invalid: ", "")); LOGGER.crash("Failed to initialize subsystem " + clazz.getName() + ": Invalid version string: " + exception.getMessage().replace("The version string is invalid: ", ""));
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Method invocation error", exception); LOGGER.crash("Failed to initialize subsystem " + clazz.getName() + ": Method invocation error", exception);
} }
// Update 'subsystems' // Update 'subsystems'
@ -461,10 +466,10 @@ public final class Engine extends SubsystemClass {
} else } else
for (String path : EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses()) for (String path : EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses())
try { try {
logger.diag("Resolving class " + path); LOGGER.diag("Resolving class " + path);
classes.add(Class.forName(path)); classes.add(Class.forName(path));
} catch (ClassNotFoundException exception) { } catch (ClassNotFoundException exception) {
logger.error("Failed loading subsystem class " + path + ": Class not found"); LOGGER.error("Failed loading subsystem class " + path + ": Class not found");
} }
return classes; return classes;
@ -485,7 +490,7 @@ public final class Engine extends SubsystemClass {
resolver.addVectors(subsystems); resolver.addVectors(subsystems);
// Resolve dependencies and get order // Resolve dependencies and get order
logger.verb("Resolving subsystem dependencies"); LOGGER.verb("Resolving subsystem dependencies");
try { try {
for (DependencyVector vector : resolver.resolve().getOrder()) // smol workaround for (DependencyVector vector : resolver.resolve().getOrder()) // smol workaround
order.add((DependencySubsystemVector) vector); order.add((DependencySubsystemVector) vector);
@ -500,25 +505,25 @@ public final class Engine extends SubsystemClass {
.append("- ") .append("- ")
.append(error); .append(error);
logger.crash("Found unresolved dependencies:" + list, throwable); LOGGER.crash("Found unresolved dependencies:" + list, throwable);
return; return;
} }
logger.crash("An error occurred trying to resolve subsystem dependencies: " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage())); LOGGER.crash("An error occurred trying to resolve subsystem dependencies: " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
throw throwable; throw throwable;
} }
// Initialize subsystems // Initialize subsystems
logger.verb("Initializing engine subsystems"); LOGGER.verb("Initializing engine subsystems");
long initTime; long initTime;
for (DependencySubsystemVector vector : subsystems) { for (DependencySubsystemVector vector : subsystems) {
logger.diag("Initializing subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + ")"); LOGGER.diag("Initializing subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + ")");
try { try {
initTime = Miscellaneous.measureExecutionTime(() -> vector.getSubsystemClass().initializeSubsystem()); initTime = Miscellaneous.measureExecutionTime(() -> vector.getSubsystemClass().initializeSubsystem());
} catch (Throwable throwable) { } catch (Throwable throwable) {
logger.crash("An error occurred trying to initialize subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + "): " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage())); LOGGER.crash("An error occurred trying to initialize subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + "): " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
throw throwable; throw throwable;
} }
logger.diag("Initialized subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + ") in " + initTime + "ms"); LOGGER.diag("Initialized subsystem " + vector.getSubsystemClass().getName() + " (" + vector.getSubsystemClass().getClass().getName() + ") in " + initTime + "ms");
} }
// Update 'subsystems' // Update 'subsystems'
@ -535,7 +540,7 @@ public final class Engine extends SubsystemClass {
if (state == EngineState.UNKNOWN || state == EngineState.SHUTDOWN) if (state == EngineState.UNKNOWN || state == EngineState.SHUTDOWN)
return; return;
logger.info("Shutting engine down"); LOGGER.info("Shutting engine down");
if (state != EngineState.CRASHED) if (state != EngineState.CRASHED)
state = EngineState.SHUTDOWN; state = EngineState.SHUTDOWN;
@ -554,14 +559,17 @@ public final class Engine extends SubsystemClass {
} catch (Exception ignored) {} } catch (Exception ignored) {}
// Send events // Send events
logger.verb("Notifying classes about shutdown"); LOGGER.verb("Notifying classes about shutdown");
new EngineShutdownEvent().callEvent(); new EngineShutdownEvent().callEvent();
logger.verb("Notifying subsystems about shutdown"); LOGGER.verb("Notifying subsystems about shutdown");
new InternalEngineShutdownEvent().callEvent(); new InternalEngineShutdownEvent().callEvent();
// Delete scheduled files
FileAccess.deleteScheduled();
// Invoke shutdown handler // Invoke shutdown handler
logger.verb("Invoking shutdown handler (code " + exitCode + ")"); LOGGER.verb("Invoking shutdown handler (code " + exitCode + ")");
shutdownHandler.shutdown((short) exitCode); shutdownHandler.shutdown((short) exitCode);
} }
@ -581,7 +589,11 @@ public final class Engine extends SubsystemClass {
return "base"; return "base";
} }
/** {@inheritDoc} */ /**
* This method does nothing.
*
* @since v1-alpha1
*/
@Override @Override
public void initializeSubsystem() {} public void initializeSubsystem() {}
@ -634,12 +646,12 @@ public final class Engine extends SubsystemClass {
Runtime.getRuntime().addShutdownHook(thread); Runtime.getRuntime().addShutdownHook(thread);
Runtime.getRuntime().removeShutdownHook(thread); Runtime.getRuntime().removeShutdownHook(thread);
} catch (IllegalStateException exception) { } catch (IllegalStateException exception) {
logger.warn("Terminating JVM: Already shutting down, skipping"); LOGGER.warn("Terminating JVM: Already shutting down, skipping");
return; return;
} }
logger.warn("Terminating JVM"); LOGGER.warn("Terminating JVM");
System.exit(exitCode); Runtime.getRuntime().exit(exitCode);
} }
} }
} }

View file

@ -60,7 +60,7 @@ public final class EngineInternals {
* @see LoggerInstance * @see LoggerInstance
* @since v1-alpha4 * @since v1-alpha4
*/ */
private static final LoggerInstance logger = new LoggerInstance.Builder().setClazz(EngineInternals.class).setOrigin("ENGINE").build(); private static final LoggerInstance LOGGER = new LoggerInstance.Builder().setClazz(EngineInternals.class).setOrigin("ENGINE").build();
/** /**
* Contains all disabled internal access areas. * Contains all disabled internal access areas.
@ -100,7 +100,7 @@ public final class EngineInternals {
if (instance == null && Engine.getInstance() != null) if (instance == null && Engine.getInstance() != null)
instance = this; instance = this;
else else
logger.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance"); LOGGER.crash("Only one instance of this class is allowed, use getInstance() instead of creating a new instance");
} }
/** /**