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 void
init
(Supplier<Application> instanceSupplier) Initializes theApplicationWrapper
by setting theApplication
instance from the given supplier.static void
init
(Application app) Initializes theApplicationWrapper
by setting theApplication
instance.static void
init
(Application app, Supplier<Args> argumentParser) Initializes theApplicationWrapper
by setting theApplication
instance and an optional customArgs
parser.static boolean
Returns whether the runtime is shutting down (shutdown()
was called).static void
shutdown()
Shuts down the application and runtime.static void
Starts the application.
-
Constructor Details
-
ApplicationWrapper
public ApplicationWrapper()
-
-
Method Details
-
init
Initializes theApplicationWrapper
by setting theApplication
instance from the given supplier.Equivalent to a call to:
init
(instanceSupplier.get())- Parameters:
instanceSupplier
- The application instance supplier
-
init
Initializes theApplicationWrapper
by setting theApplication
instance.Equivalent to a call to:
init
(app, null)- Parameters:
app
- The application instance
-
init
Initializes theApplicationWrapper
by setting theApplication
instance and an optional customArgs
parser.- Parameters:
app
- The application instanceargumentParser
- TheArgs
parser to use to parse the process startup arguments. May benull
to 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 themain
method- 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.shutdownTimeout
system 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 is2000
milliseconds.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:
true
if shutting down
-