Interface ProcessEnvironment

All Known Implementing Classes:
BaseProcessEnvironment, DefaultProcessEnvironment

public interface ProcessEnvironment
Interface for installation-specific environment. Processes that use instances of this interface are responsible for determining when to call the various methods. All implementations must setup a ShutdownManager and an implementation of FatalErrorReporter.
  • Method Details

    • getShutdownManager

      ShutdownManager getShutdownManager()
      Access a shared manager for tasks to be executed on shutdown.
      Returns:
      The ShutdownManager
    • getFatalErrorReporter

      FatalErrorReporter getFatalErrorReporter()
      Access a shared fatal error reporter.
      Returns:
      The FatalErrorReporter
    • getMainClassName

      String getMainClassName()
      Access the main class name.
      Returns:
      The main class name
    • onStartup

      void onStartup()
      Hook for setting up an installation-specific environment for a given process.
    • onShutdown

      void onShutdown()
      Hook for shutting down an installation-specific environment for a given process. This is intended for controlled invocation, rather than as part of a shutdown hook - onStartup() should setup any mandatory shutdown hooks, and code in said shutdown hooks should be idempotent w.r.t. onShutdown().
    • get

      static ProcessEnvironment get()
      Accessor the for the global instance. Fails if the instance is null, in order to make programming errors clear.
      Returns:
      The global instance
    • tryGet

      static ProcessEnvironment tryGet()
      Accessor the for the global instance.
      Returns:
      The global instance, or null if it is not set.
    • getGlobalShutdownManager

      static ShutdownManager getGlobalShutdownManager()
    • getGlobalFatalErrorReporter

      static FatalErrorReporter getGlobalFatalErrorReporter()
    • getGlobalMainClassName

      static String getGlobalMainClassName()
    • set

      static ProcessEnvironment set(@NotNull @NotNull ProcessEnvironment instance, boolean allowReplace)
      Setter for the global instance. It is an error to invoke this without allowReplace if the global instance may already have been set.
      Parameters:
      instance - The new global instance
      allowReplace - Whether to allow replacing an existing global instance
      Returns:
      The global instance
    • clear

      static void clear()
      Set the global instance to null, and reset its shutdown manager. Intended for use in unit tests, only.
    • instantiateFromConfiguration

      @NotNull static @NotNull ProcessEnvironment instantiateFromConfiguration(@NotNull @NotNull Configuration configuration, @NotNull @NotNull String mainClassName, @NotNull @NotNull Logger log)
      Instantiate (and set as the global instance) a ProcessEnvironment specified according to the following factory class name properties, in descending order of precedence: mainClassName.processEnvironmentFactory default.processEnvironmentFactory Checked exceptions thrown in this process always result in process termination.
      Parameters:
      configuration - The configuration
      mainClassName - The main class name
      log - The log
      Returns:
      The new ProcessEnvironment
    • basicInteractiveProcessInitialization

      @NotNull static @NotNull ProcessEnvironment basicInteractiveProcessInitialization(@NotNull @NotNull Configuration configuration, @NotNull @NotNull String mainClassName, @NotNull @NotNull Logger log)
      Do the basic installation most interactive (usually client) processes need: (1) instantiateFromConfiguration (2) set (3) Invoke onStartup()
      Parameters:
      configuration - The configuration
      mainClassName - The main class name
      log - The log
      Returns:
      The ProcessEnvironment
    • basicServerInitialization

      @NotNull static @NotNull ProcessEnvironment basicServerInitialization(@NotNull @NotNull Configuration configuration, @NotNull @NotNull String mainClassName, @NotNull @NotNull Logger log)
      Do the basic installation most server processes need: (1) basicInteractiveProcessInitialization (as a subset of what servers need) (2) Set current thread name as mainClassName.main (3) Install the fatal error reporter as default uncaught exception handler
      Parameters:
      configuration - The configuration
      mainClassName - The main class name
      log - The log
      Returns:
      The ProcessEnvironment