From ec70b2685f421d3d1e36a6e6c8eebf47d23ff423 Mon Sep 17 00:00:00 2001 From: Vest Date: Sat, 11 Jan 2025 17:39:25 +0100 Subject: [PATCH] Added JavaDoc to Exit* and GracefulExit classes. --- code/src/testcommon/util/ExitFunction.java | 8 +++++ code/src/testcommon/util/ExitInterceptor.java | 9 ++++++ code/src/testcommon/util/GracefulExit.java | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/code/src/testcommon/util/ExitFunction.java b/code/src/testcommon/util/ExitFunction.java index 4fac8881f26..d77ae084549 100644 --- a/code/src/testcommon/util/ExitFunction.java +++ b/code/src/testcommon/util/ExitFunction.java @@ -1,7 +1,15 @@ package util; +/** + * A functional interface that can be used to exit the JVM. + */ @FunctionalInterface public interface ExitFunction { + /** + * Is executed when the JVM should exit. + * + * @param status The status code to exit with + */ void exit(int status); } diff --git a/code/src/testcommon/util/ExitInterceptor.java b/code/src/testcommon/util/ExitInterceptor.java index c511429272a..bfc72ef8628 100644 --- a/code/src/testcommon/util/ExitInterceptor.java +++ b/code/src/testcommon/util/ExitInterceptor.java @@ -1,7 +1,16 @@ package util; +/** + * A functional interface that can be used to intercept the exit of the JVM. + */ @FunctionalInterface public interface ExitInterceptor { + /** + * Is executed when the JVM should exit. + * + * @param status The status code to exit with + * @return true if the exit should be allowed, false if it should be intercepted + */ boolean intercept(int status); } diff --git a/code/src/testcommon/util/GracefulExit.java b/code/src/testcommon/util/GracefulExit.java index 112ae052c4e..691771e115c 100644 --- a/code/src/testcommon/util/GracefulExit.java +++ b/code/src/testcommon/util/GracefulExit.java @@ -7,6 +7,11 @@ import java.util.logging.Level; import java.util.logging.Logger; +/** + * This class provides a mechanism to intercept calls to System.exit and perform additional actions before the JVM exits. + *

+ * This class is thread-safe. + */ public class GracefulExit { private static final Logger LOG = Logger.getLogger(GracefulExit.class.getName()); @@ -24,6 +29,17 @@ private static class Lock private static ExitFunction exitFunction = System::exit; + private GracefulExit() + { + } + + /** + * Exits the JVM with the given status code. This method will call all registered interceptors before exiting. + *

+ * If any interceptor returns false, the exit will be canceled. + * + * @param status The status code to exit with + */ static void exit(int status) { synchronized (lock) @@ -56,6 +72,12 @@ static void exit(int status) } } + /** + * Adds an interceptor to the list of interceptors. This method can be called before or after shutdown has started, + * otherwise an exception will be thrown. + * + * @param interceptor The interceptor to add + */ public static void addExitInterceptor(ExitInterceptor interceptor) { synchronized (lock) @@ -72,6 +94,10 @@ public static void addExitInterceptor(ExitInterceptor interceptor) } } + /** + * Clears all registered interceptors. This method can be called before or after shutdown has started, otherwise an + * exception will be thrown. + */ public static void clearExitInterceptors() { synchronized (lock) @@ -84,6 +110,12 @@ public static void clearExitInterceptors() } } + /** + * Registers an exit function to be called when the JVM exits. This method can be called before or after shutdown has + * started, otherwise an exception will be thrown. + * + * @param exitFunction The exit function to register + */ public static void registerExitFunction(ExitFunction exitFunction) { synchronized (lock)