From a21ef1bc5f5ece68f26a2b2662aee31f2d816d88 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 3 Nov 2024 18:32:40 +0100 Subject: [PATCH] Fix variable name convention --- .../de/staropensource/engine/base/Engine.java | 120 ++++++++++-------- .../engine/base/EngineInternals.java | 4 +- 2 files changed, 68 insertions(+), 56 deletions(-) diff --git a/base/src/main/java/de/staropensource/engine/base/Engine.java b/base/src/main/java/de/staropensource/engine/base/Engine.java index ec42ad9..f0d73c6 100644 --- a/base/src/main/java/de/staropensource/engine/base/Engine.java +++ b/base/src/main/java/de/staropensource/engine/base/Engine.java @@ -34,6 +34,7 @@ import de.staropensource.engine.base.type.DependencyVector; import de.staropensource.engine.base.type.EngineState; import de.staropensource.engine.base.type.immutable.ImmutableLinkedList; 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.PlaceholderEngine; import de.staropensource.engine.base.utility.information.EngineInformation; @@ -90,7 +91,7 @@ public final class Engine extends SubsystemClass { * @see LoggerInstance * @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. @@ -169,7 +170,7 @@ public final class Engine extends SubsystemClass { } // 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 Engine.getInstance().shutdown(); @@ -192,7 +193,7 @@ public final class Engine extends SubsystemClass { new EngineConfiguration(); EngineConfiguration.getInstance().loadConfiguration(); - logger.info("Initializing engine"); + LOGGER.info("Initializing engine"); initializeClasses(); // Initialize classes if (checkEnvironment()) // Check environment throw new IllegalStateException("Running in an incompatible environment"); @@ -201,7 +202,7 @@ public final class Engine extends SubsystemClass { cacheEvents(); // Cache event listeners startThreads(); // Start threads - logger.verb("Completing early initialization stage"); + LOGGER.verb("Completing early initialization stage"); state = EngineState.STARTUP; // Perform automatic subsystem initialization @@ -212,14 +213,14 @@ public final class Engine extends SubsystemClass { try { initializeSubsystems(); } 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; - 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) { throw exception; } catch (Exception exception) { - logger.error("Engine initialization failed"); - logger.error(Miscellaneous.getStackTraceHeader(exception)); + LOGGER.error("Engine initialization failed"); + LOGGER.error(Miscellaneous.getStackTraceHeader(exception)); for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n")) - logger.error(line); + LOGGER.error(line); throw new RuntimeException("Engine initialization failed", exception); } } @@ -251,12 +252,16 @@ public final class Engine extends SubsystemClass { * @since v1-alpha0 */ private void initializeClasses() { - logger.verb("Initializing engine classes"); + LOGGER.verb("Initializing engine classes"); + + // Initialize essential engine classes new EngineInternals(); PlaceholderEngine.initialize(); - EngineInformation.update(); + + // Non-essential engine classes PrintStreamService.initializeStreams(); + FileAccess.initializeInstances(); } /** @@ -265,35 +270,35 @@ public final class Engine extends SubsystemClass { * @since v1-alpha4 */ private boolean checkEnvironment() { - logger.diag("Checking environment"); + LOGGER.diag("Checking environment"); // Warn about potential Java incompatibilities 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 if (JvmInformation.getImplementationName().equals("Substrate VM") && JvmInformation.getImplementationVendor().equals("GraalVM Community")) { - logger.error("##############################################################################################"); - 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("## 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("## https://git.staropensource.de/StarOpenSource/Engine/issues/3 ##"); - logger.error("## ##"); - 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("## ##"); - logger.error("## We're truly sorry for this inconvenience. The sos!engine will now terminate. ##"); - logger.error("##############################################################################################"); + LOGGER.error("##############################################################################################"); + 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("## 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("## https://git.staropensource.de/StarOpenSource/Engine/issues/3 ##"); + LOGGER.error("## ##"); + 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("## ##"); + LOGGER.error("## We're truly sorry for this inconvenience. The sos!engine will now terminate. ##"); + LOGGER.error("##############################################################################################"); Runtime.getRuntime().exit(255); } // Check if reflective classpath scanning is supported if (checkClasspathScanningSupport()) { - 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("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("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("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."); EngineInternals.getInstance().overrideReflectiveClasspathScanning(false); } @@ -328,7 +333,7 @@ public final class Engine extends SubsystemClass { */ @SuppressWarnings({ "ExtractMethodRecommender" }) private void populateCrashContent() { - logger.diag("Populating crash content"); + LOGGER.diag("Populating crash content"); // Issuer Map<@NotNull String, @NotNull String> crashContentIssuer = new LinkedHashMap<>(); @@ -379,7 +384,7 @@ public final class Engine extends SubsystemClass { * @since v1-alpha0 */ private void cacheEvents() { - logger.diag("Caching events"); + LOGGER.diag("Caching events"); // Internal events EventHelper.cacheEvent(InternalEngineShutdownEvent.class); @@ -397,8 +402,8 @@ public final class Engine extends SubsystemClass { * * @since v1-alpha1 */ - public void startThreads() { - logger.diag("Starting threads"); + private void startThreads() { + LOGGER.diag("Starting threads"); LoggingThread.startThread(); } @@ -424,14 +429,14 @@ public final class Engine extends SubsystemClass { if (initializedClassRaw instanceof SubsystemClass) initializedClass = (SubsystemClass) initializedClassRaw; 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 subsystemsMutable.add(new DependencySubsystemVector(initializedClass.getDependencyVector(), initializedClass)); } catch (Exception exception) { 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() + ": Method invocation error", exception); + 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); } // Update 'subsystems' @@ -461,10 +466,10 @@ public final class Engine extends SubsystemClass { } else for (String path : EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses()) try { - logger.diag("Resolving class " + path); + LOGGER.diag("Resolving class " + path); classes.add(Class.forName(path)); } 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; @@ -485,7 +490,7 @@ public final class Engine extends SubsystemClass { resolver.addVectors(subsystems); // Resolve dependencies and get order - logger.verb("Resolving subsystem dependencies"); + LOGGER.verb("Resolving subsystem dependencies"); try { for (DependencyVector vector : resolver.resolve().getOrder()) // smol workaround order.add((DependencySubsystemVector) vector); @@ -500,25 +505,25 @@ public final class Engine extends SubsystemClass { .append("- ") .append(error); - logger.crash("Found unresolved dependencies:" + list, throwable); + LOGGER.crash("Found unresolved dependencies:" + list, throwable); 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; } // Initialize subsystems - logger.verb("Initializing engine subsystems"); + LOGGER.verb("Initializing engine subsystems"); long initTime; 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 { initTime = Miscellaneous.measureExecutionTime(() -> vector.getSubsystemClass().initializeSubsystem()); } 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; } - 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' @@ -535,7 +540,7 @@ public final class Engine extends SubsystemClass { if (state == EngineState.UNKNOWN || state == EngineState.SHUTDOWN) return; - logger.info("Shutting engine down"); + LOGGER.info("Shutting engine down"); if (state != EngineState.CRASHED) state = EngineState.SHUTDOWN; @@ -554,14 +559,17 @@ public final class Engine extends SubsystemClass { } catch (Exception ignored) {} // Send events - logger.verb("Notifying classes about shutdown"); + LOGGER.verb("Notifying classes about shutdown"); new EngineShutdownEvent().callEvent(); - logger.verb("Notifying subsystems about shutdown"); + LOGGER.verb("Notifying subsystems about shutdown"); new InternalEngineShutdownEvent().callEvent(); + // Delete scheduled files + FileAccess.deleteScheduled(); + // Invoke shutdown handler - logger.verb("Invoking shutdown handler (code " + exitCode + ")"); + LOGGER.verb("Invoking shutdown handler (code " + exitCode + ")"); shutdownHandler.shutdown((short) exitCode); } @@ -581,7 +589,11 @@ public final class Engine extends SubsystemClass { return "base"; } - /** {@inheritDoc} */ + /** + * This method does nothing. + * + * @since v1-alpha1 + */ @Override public void initializeSubsystem() {} @@ -634,12 +646,12 @@ public final class Engine extends SubsystemClass { Runtime.getRuntime().addShutdownHook(thread); Runtime.getRuntime().removeShutdownHook(thread); } catch (IllegalStateException exception) { - logger.warn("Terminating JVM: Already shutting down, skipping"); + LOGGER.warn("Terminating JVM: Already shutting down, skipping"); return; } - logger.warn("Terminating JVM"); - System.exit(exitCode); + LOGGER.warn("Terminating JVM"); + Runtime.getRuntime().exit(exitCode); } } } diff --git a/base/src/main/java/de/staropensource/engine/base/EngineInternals.java b/base/src/main/java/de/staropensource/engine/base/EngineInternals.java index 63a06c9..2f95945 100644 --- a/base/src/main/java/de/staropensource/engine/base/EngineInternals.java +++ b/base/src/main/java/de/staropensource/engine/base/EngineInternals.java @@ -60,7 +60,7 @@ public final class EngineInternals { * @see LoggerInstance * @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. @@ -100,7 +100,7 @@ public final class EngineInternals { if (instance == null && Engine.getInstance() != null) instance = this; 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"); } /**