Interface Application

  • All Superinterfaces:
    io.clogr.Clogged, com.globalmentor.model.Named<java.lang.String>, java.lang.Runnable
    All Known Implementing Classes:
    AbstractApplication, BaseCliApplication

    public interface Application
    extends java.lang.Runnable, com.globalmentor.model.Named<java.lang.String>, io.clogr.Clogged
    A general application.

    To start an application, call the static start(Application) method, passing it an application instance.

    Author:
    Garret Wilson
    API Note:
    Although an application implements Runnable, it should usually be started using start(), which will eventually (depending on the implementation) call Runnable.run().
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String[] NO_ARGUMENTS
      An array containing no arguments.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean canStart()
      Checks requirements, permissions, and expirations before starting.
      void displayError​(java.lang.String message)
      Deprecated.
      void displayError​(java.lang.String message, java.lang.Throwable throwable)
      Deprecated.
      default void exit()
      Exits the application with no status.
      void exit​(int status)
      Exits the application with the given status.
      java.lang.String[] getArgs()  
      java.util.Optional<com.globalmentor.net.Authenticable> getAuthenticator()  
      java.util.Optional<java.time.LocalDate> getExpirationDate()  
      java.util.prefs.Preferences getPreferences()
      Returns the application user preferences.
      java.lang.String getVersion()  
      void initialize()
      Initializes the application.
      boolean isDebug()
      Returns whether debug mode is enabled.
      default int start()
      Starts the application
      static int start​(Application application)
      Starts an application.
      • Methods inherited from interface io.clogr.Clogged

        getLogger
      • Methods inherited from interface com.globalmentor.model.Named

        getName
      • Methods inherited from interface java.lang.Runnable

        run
    • Field Detail

      • NO_ARGUMENTS

        static final java.lang.String[] NO_ARGUMENTS
        An array containing no arguments.
    • Method Detail

      • getAuthenticator

        java.util.Optional<com.globalmentor.net.Authenticable> getAuthenticator()
        Returns:
        The authenticator object used to retrieve client authentication.
      • getArgs

        java.lang.String[] getArgs()
        Returns:
        The command-line arguments of the application.
      • getVersion

        java.lang.String getVersion()
        Returns:
        The application version string .
      • isDebug

        boolean isDebug()
        Returns whether debug mode is enabled.
        API Note:
        Debug mode enables debug level logging and may also enable other debug functionality.
        Returns:
        The state of debug mode.
      • getPreferences

        java.util.prefs.Preferences getPreferences()
                                            throws java.lang.SecurityException
        Returns the application user preferences.
        Returns:
        The default user preferences for this application.
        Throws:
        java.lang.SecurityException - if a security manager is present and it denies RuntimePermission("preferences").
      • getExpirationDate

        java.util.Optional<java.time.LocalDate> getExpirationDate()
        Returns:
        The expiration date of the application, if there is one.
      • initialize

        void initialize()
                 throws java.lang.Exception
        Initializes the application. This method is called after construction but before application execution.
        Throws:
        java.lang.Exception - if anything goes wrong.
      • start

        default int start()
        Starts the application
        Implementation Specification:
        The default implementation delegates to Runnable.run() and returns a status code of 0.
        Returns:
        The application status.
      • canStart

        boolean canStart()
        Checks requirements, permissions, and expirations before starting.
        Returns:
        true if the checks succeeded.
      • displayError

        @Deprecated
        void displayError​(@Nonnull
                          java.lang.String message,
                          @Nonnull
                          java.lang.Throwable throwable)
        Deprecated.
        Displays an error message to the user for an exception.
        Parameters:
        message - The message to display.
        throwable - The condition that caused the error.
      • displayError

        @Deprecated
        void displayError​(java.lang.String message)
        Deprecated.
        Displays the given error to the user
        Parameters:
        message - The error to display.
      • exit

        default void exit()
        Exits the application with no status.
        Implementation Specification:
        The default implementation delegates to exit(int) with a value of 0.
        See Also:
        exit(int)
      • exit

        void exit​(int status)
        Exits the application with the given status. This method first checks to see if exit can occur.
        Parameters:
        status - The exit status.
      • start

        static int start​(Application application)
        Starts an application.
        Parameters:
        application - The application to start.
        Returns:
        The application status.