Class ApplicationWrapper

java.lang.Object
org.omegazero.common.runtime.ApplicationWrapper

public class ApplicationWrapper extends Object
Provides standard runtime setup procedures for the standalone application running in this runtime.

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 Details

    • ApplicationWrapper

      public ApplicationWrapper()
  • Method Details

    • init

      public static void init(Supplier<Application> instanceSupplier)
      Initializes the ApplicationWrapper by setting the Application instance from the given supplier.

      Equivalent to a call to:

       init(instanceSupplier.get())
       
      Parameters:
      instanceSupplier - The application instance supplier
    • init

      public static void init(Application app)
      Initializes the ApplicationWrapper by setting the Application instance.

      Equivalent to a call to:

       init(app, null)
       
      Parameters:
      app - The application instance
    • init

      public static void init(Application app, Supplier<Args> argumentParser)
      Initializes the ApplicationWrapper by setting the Application instance and an optional custom Args parser.
      Parameters:
      app - The application instance
      argumentParser - The Args parser to use to parse the process startup arguments. May be null to use Args.DefaultFormat
      Throws:
      IllegalStateException - If start(String[]) was called successfully already
    • start

      public static void start(String[] pargs)
      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 the main 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 the org.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 is 2000 milliseconds.

      This method can be called any number of times, but only the first successful invocation has any effect.

      Throws:
      IllegalStateException - If start(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