Class ApplicationWrapper
To use this class, the application must implement the Application interface, which declares a startup and shutdown method, each called once at the start and end of the
application lifecycle.
All methods in this class are static because the methods are each intended to be called only once during the lifetime of the application. This class does significant changes to the runtime and must not be used in a managed container (for example on an application server).
- Since:
- 2.9
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidinit(Supplier<Application> instanceSupplier) Initializes theApplicationWrapperby setting theApplicationinstance from the given supplier.static voidinit(Application app) Initializes theApplicationWrapperby setting theApplicationinstance.static voidinit(Application app, Supplier<Args> argumentParser) Initializes theApplicationWrapperby setting theApplicationinstance and an optional customArgsparser.static booleanReturns whether the runtime is shutting down (shutdown()was called).static voidshutdown()Shuts down the application and runtime.static voidStarts the application.
-
Constructor Details
-
ApplicationWrapper
public ApplicationWrapper()
-
-
Method Details
-
init
Initializes theApplicationWrapperby setting theApplicationinstance from the given supplier.Equivalent to a call to:
init(instanceSupplier.get())- Parameters:
instanceSupplier- The application instance supplier
-
init
Initializes theApplicationWrapperby setting theApplicationinstance.Equivalent to a call to:
init(app, null)- Parameters:
app- The application instance
-
init
Initializes theApplicationWrapperby setting theApplicationinstance and an optional customArgsparser.- Parameters:
app- The application instanceargumentParser- TheArgsparser to use to parse the process startup arguments. May benullto useArgs.DefaultFormat- Throws:
IllegalStateException- Ifstart(String[])was called successfully already
-
start
Starts the application.This method calls
Application.start(Args)in the configured application with the parsed startup arguments.Requires a call to
init(Application, Supplier)to set the application instance and an optional argument parser.This method can only be called once successfully.
- Parameters:
pargs- The process startup arguments, passed to themainmethod- Throws:
IllegalStateException- If this method was called successfully already
-
shutdown
public static void shutdown()Shuts down the application and runtime.This method calls
Application.close()and other exit methods, and will then wait at most for the number of milliseconds set in theorg.omegazero.common.runtime.shutdownTimeoutsystem property for the runtime to exit. If this timeout is exceeded, the runtime is forcibly terminated and a warning message with debug information is printed. The default value is2000milliseconds.This method can be called any number of times, but only the first successful invocation has any effect.
- Throws:
IllegalStateException- Ifstart(String[])was never called successfully
-
isShuttingDown
public static boolean isShuttingDown()Returns whether the runtime is shutting down (shutdown()was called).- Returns:
trueif shutting down
-