Class Application

java.lang.Object
io.john.amiscaray.quak.core.Application
Direct Known Subclasses:
WebApplication

public abstract class Application extends Object
Represents the base functionality of a quak application. This contains lifecycle hooks you can add callbacks to and methods to start or end the application. Lifecycle hooks include: PRE_START, CONTEXT_LOADED, POST_START, PRE_STOP, POST_STOP.
  • Field Details

    • hasStarted

      protected boolean hasStarted
      Whether the application has started.
    • contextLoaded

      protected boolean contextLoaded
      Whether the application context loaded.
    • classScanPackage

      protected String classScanPackage
      The package from which Quak scans for dependencies. This should be an upmost package containing all classes.
    • args

      protected String[] args
      The program arguments passed to the application.
    • main

      protected Class<?> main
      The class that contains the application's main method.
    • lifecycleListeners

      protected Map<Application.LifecycleState,List<Consumer<Application>>> lifecycleListeners
      A map from lifecycle state to list of lifecycle event consumer. The consumers accept this application instance.
  • Constructor Details

    • Application

      public Application(Class<?> main, String[] args)
      Initialize an application.
      Parameters:
      main - The class containing the application's main method.
      args - The program arguments passed to the application.
  • Method Details

    • initLifecycleListeners

      protected void initLifecycleListeners()
      Initializes a map of lifecycle states to lifecycle event consumers.
    • start

      public void start() throws Exception
      Starts the application. In this initialization sequence, in this order, the application: calls any "pre-start" listeners, initializes the application properties, loads the application context, invokes the "context loaded" listeners, calls the startup method, and calls the "post start" listeners.
      Throws:
      Exception - any exceptions from this method will be thrown.
    • stop

      public final void stop() throws Exception
      Stops the application. In this order, this method: calls any "pre stop" listeners, invokes the finish method, and calls any "post stop" listeners.
      Throws:
      Exception - any exceptions from this method will be thrown.
    • finish

      protected abstract void finish() throws Exception
      Unimplemented tear down logic for your application.
      Throws:
      Exception - any exception in this method is thrown.
    • startUp

      protected abstract void startUp() throws Exception
      Unimplemented startup logic for your application.
      Throws:
      Exception - any exception in this method is thrown.
    • startAsync

      public void startAsync()
      Starts the application asynchronously. Notifies anything blocking on this application to stop when it does stop.
    • await

      public void await() throws InterruptedException
      Block while the application is running.
      Throws:
      InterruptedException - if there is a thread interruption.
    • initContext

      protected void initContext()
    • initProperties

      protected void initProperties()
    • on

      public void on(Application.LifecycleState state, Consumer<Application> consumer)
      Register an application lifecycle state listener.
      Parameters:
      state - The lifecycle state.
      consumer - A consumer that is called when this lifecycle state occurs. Accepts this.
    • preStart

      protected void preStart()
    • contextLoaded

      protected void contextLoaded()
    • postStart

      protected void postStart()
    • preStop

      protected void preStop()
    • postStop

      protected void postStop()