Package io.quarkus.runtime
Class ApplicationLifecycleManager
java.lang.Object
io.quarkus.runtime.ApplicationLifecycleManager
Manages the lifecycle of a Quarkus application.
The
Application
class is responsible for starting and stopping the application,
but nothing else. This class can be used to run both persistent applications that will run
till they receive a signal, and command mode applications that will run until the main method
returns. This class registers a shutdown hook to properly shut down the application, and handles
exiting with the supplied exit code as well as any exception thrown when starting the application.
This class should be used to run production and dev mode applications, while test use cases will
likely want to just use Application
directly.
This class is static, there can only ever be a single application instance running at any time.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
exit()
Exits without supplying an exit code.static void
exit
(int code) Signals that the application should exit with the given code.static Application
static BiConsumer<Integer,
Throwable> static int
static boolean
static void
run
(Application application, Class<? extends QuarkusApplication> quarkusApplication, BiConsumer<Integer, Throwable> exitCodeHandler, String... args) static void
run
(Application application, String... args) static void
setDefaultExitCodeHandler
(BiConsumer<Integer, Throwable> defaultExitCodeHandler) Sets the default exit code and exception handler for application run through the run method that does not take an exit handler.static void
setDefaultExitCodeHandler
(Consumer<Integer> defaultExitCodeHandler) Sets the default exit code handler for application run through the run method that does not take an exit handler.static void
Waits for the shutdown process to be initiated.
-
Field Details
-
shutdownReason
-
-
Method Details
-
run
-
run
public static void run(Application application, Class<? extends QuarkusApplication> quarkusApplication, BiConsumer<Integer, Throwable> exitCodeHandler, String... args) -
getCurrentApplication
-
getExitCode
public static int getExitCode()- Returns:
- The current exit code that would be reported if the application exits
-
exit
public static void exit()Exits without supplying an exit code. The application will exit with a code of 0 by default, however if this method is called it is still possible for a different exit code to be set. -
getDefaultExitCodeHandler
-
isVmShuttingDown
public static boolean isVmShuttingDown()- Returns:
true
if the VM is shutting down
-
setDefaultExitCodeHandler
Sets the default exit code and exception handler for application run through the run method that does not take an exit handler. By default, this will just callSystem.exit
, however this is not always what is wanted.- Parameters:
defaultExitCodeHandler
- the new default exit handler
-
setDefaultExitCodeHandler
Sets the default exit code handler for application run through the run method that does not take an exit handler. By default, this will just callSystem.exit
, however this is not always what is wanted.- Parameters:
defaultExitCodeHandler
- the new default exit handler
-
exit
public static void exit(int code) Signals that the application should exit with the given code. Note that the first positive exit code will 'win', so if the exit code has already been set then the exit code will be ignored.- Parameters:
code
- The exit code
-
waitForExit
public static void waitForExit()Waits for the shutdown process to be initiated.
-