Class Application

java.lang.Object
civitas.celestis.Application

public class Application extends Object
Defines the contract for a generic application using the Plains library. All modules are configured to use System.out as its print stream unless the module instances are specified using the protected constructor by a customized subclass.

Using this class directly should only be done for testing and debugging purposes, and the final application should be a subclass which properly handles the lifecycle of its specific implementation.

  • Field Details

    • EXIT_CODE_NORMAL

      public static final int EXIT_CODE_NORMAL
      The exit code for normal graceful termination of the application.
      Since:
      0.4
      See Also:
    • EXIT_CODE_TERMINATED

      public static final int EXIT_CODE_TERMINATED
      The exit code for forceful termination of the application by means of directly calling terminate(int). (without proper exit procedure)
      Since:
      0.4
      See Also:
    • EXIT_CODE_FATAL_ERROR

      public static final int EXIT_CODE_FATAL_ERROR
      The exit code for forceful termination of the application caused by a fatal error, which makes the application no longer operable.
      Since:
      0.4
      See Also:
    • name

      @Nonnull protected final String name
      The name of this application.
    • version

      @Nonnull protected final String version
      The version of this application.
    • eventManager

      @Nonnull protected final EventManager eventManager
      The event manager instance.
    • scheduler

      @Nonnull protected final Scheduler scheduler
      The scheduler instance.
  • Constructor Details

    • Application

      public Application(@Nonnull String name, @Nonnull String version)
      Creates a new application with the default module configuration.
      Parameters:
      name - The name of this application
      version - The version of this application
    • Application

      protected Application(@Nonnull String name, @Nonnull String version, @Nonnull @ApplicationCritical EventManager eventManager, @Nonnull @ApplicationCritical Scheduler scheduler)
      Creates a new application.
      Parameters:
      name - The name of this application
      version - The version of this application
      eventManager - The event manager instance of this application
      scheduler - The scheduler instance of this application
  • Method Details

    • start

      @ApplicationCritical(created="0.4", lastUpdated="0.4") public void start()
      Initiates this application, initializing all modules and starting the program.
    • stop

      @ApplicationCritical(created="0.4", lastUpdated="0.4") public void stop()
      Gracefully stops the application, giving modules time to finalize their operations.
      See Also:
    • terminate

      @ApplicationCritical(created="0.4", lastUpdated="0.4") public void terminate(int exitCode)
      Forcefully terminates the application, regardless of its current state. This is a destructive action, and only should be called when a fatal error occurs.
      Parameters:
      exitCode - The exit code to send to System.exit(int)
      See Also:
    • getName

      @Nonnull public String getName()
      Returns the name of this application.
      Returns:
      The name of this application
    • getVersion

      @Nonnull public String getVersion()
      Returns the version of this application.
      Returns:
      The version of this application
    • getEventManager

      @Nonnull public EventManager getEventManager()
      Returns the event manager of this application.
      Returns:
      The event manager of this application
    • getScheduler

      @Nonnull public Scheduler getScheduler()
      Returns the scheduler of this application.
      Returns:
      The scheduler of this application
    • toString

      @Nonnull public String toString()
      Serializes this application into a string for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this application