Class ApplicationContext

java.lang.Object
org.rapidcontext.app.ApplicationContext

public class ApplicationContext extends Object
The application context. This is a singleton object that contains references to global application settings and objects. It also provides simple procedure execution and resource and plug-in initialization and deinitialization.
Version:
1.0
  • Field Details

    • PATH_CONFIG

      public static final Path PATH_CONFIG
      The path to the global configuration.
    • PATH_PLATFORM

      public static final Path PATH_PLATFORM
      The path to the platform information.
    • INIT_TIME

      public static final Date INIT_TIME
      The class load time (system initialization time).
    • START_TIME

      public static Date START_TIME
      The context start (or reset) time.
  • Method Details

    • init

      protected static ApplicationContext init(File baseDir, File localDir, boolean start)
      Creates and initializes the application context. If the start flag is set, all plug-ins will be loaded along with procedures and the environment configuration. Otherwise only the storages will be initialized. Note that if the context has already been created, it will not be recreated.
      Parameters:
      baseDir - the base application directory
      localDir - the local add-on directory
      start - the initialize plug-ins flag
      Returns:
      the application context created or found
    • destroy

      protected static void destroy()
      Destroys the application context and frees all resources used.
    • getInstance

      public static ApplicationContext getInstance()
      Returns the singleton application context instance.
      Returns:
      the singleton application context instance
    • reset

      public void reset()
      Resets this context and reloads all resources.
    • getConfig

      public Dict getConfig()
      Returns the application configuration.
      Returns:
      the application configuration
    • getStorage

      public Storage getStorage()
      Returns the application data storage. This is the global data storage that contains all loaded plug-ins and maps requests to them in order.
      Returns:
      the application data store
    • getEnvironment

      public Environment getEnvironment()
      Returns the environment used.
      Returns:
      the environment used
    • getWebMatchers

      public WebMatcher[] getWebMatchers()
      Returns the array of cached web matchers (from the web services). This list is only re-read when the context is reset.
      Returns:
      the array of cached web matchers
      See Also:
    • getLibrary

      public Library getLibrary()
      Returns the procedure library used.
      Returns:
      the procedure library used
    • getBaseDir

      public File getBaseDir()
      Returns the application base directory.
      Returns:
      the application base directory
    • getClassLoader

      public ClassLoader getClassLoader()
      Returns the plug-in class loader.
      Returns:
      the plug-in class loader
    • isPluginBuiltIn

      public boolean isPluginBuiltIn(String pluginId)
      Checks if the specified plug-in is built-in (or installed). Note any plug-ins located in the built-in plug-in directory will be considered built-in.
      Parameters:
      pluginId - the unique plug-in id
      Returns:
      true if the plug-in exists and is built-in, or false otherwise
    • installPlugin

      public String installPlugin(File file) throws PluginException
      Installs a plug-in from the specified file. If an existing plug-in with the same id already exists, it will be replaced without warning. After installation, the new plug-in will also be loaded and added to the default configuration for automatic launch on the next restart.
      Parameters:
      file - the plug-in ZIP file
      Returns:
      the unique plug-in id
      Throws:
      PluginException - if the plug-in couldn't be installed correctly
    • uninstallPlugin

      public void uninstallPlugin(String pluginId) throws PluginException
      Uninstalls and removes a plug-in file. If the plug-in is loaded or mounted, it will first be unloaded and the associated storage will be destroyed.
      Parameters:
      pluginId - the unique plug-in id
      Throws:
      PluginException - if the plug-in removal failed
    • loadPlugin

      public void loadPlugin(String pluginId) throws PluginException
      Loads a plug-in. If the plug-in was loaded successfully, it will also be added to the default configuration for automatic launch on the next restart.
      Parameters:
      pluginId - the unique plug-in id
      Throws:
      PluginException - if no plug-in instance could be created or if the plug-in initialization failed
    • unloadPlugin

      public void unloadPlugin(String pluginId) throws PluginException
      Unloads a plug-in. The plug-in will also be removed from the default configuration for automatic launches.
      Parameters:
      pluginId - the unique plug-in id
      Throws:
      PluginException - if the plug-in deinitialization failed
    • execute

      public Object execute(String name, Object[] args, String source, StringBuilder trace) throws ProcedureException
      Executes a procedure within this context.
      Parameters:
      name - the procedure name
      args - the procedure arguments
      source - the call source information
      trace - the trace buffer or null for none
      Returns:
      the result of the call, or null if the call produced no result
      Throws:
      ProcedureException - if the procedure execution failed
    • executeAsync

      public void executeAsync(String name, Object[] args, String source)
      Executes a procedure asynchronously within this context. This method will sleep for 10 minutes after terminating the procedure execution, allowing the results to be fetched from the context by another thread.
      Parameters:
      name - the procedure name
      args - the procedure arguments
      source - the call source information
    • findContext

      public CallContext findContext(Thread thread)
      Finds the currently active call context for a thread.
      Parameters:
      thread - the thread to search for
      Returns:
      the call context found, or null if no context was active
    • findContext

      public CallContext findContext(int threadId)
      Finds the currently active call context for a thread id. The thread id is identical to the hash code for the thread.
      Parameters:
      threadId - the thread id to search for
      Returns:
      the call context found, or null if no context was active