Package org.rapidcontext.app
Class ApplicationContext
java.lang.Object
org.rapidcontext.app.ApplicationContext
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturns the current web cache path.protected static void
destroy()
Destroys the application context and frees all resources used.execute
(String name, Object[] args, String source, StringBuilder trace) Executes a procedure within this context.void
executeAsync
(String name, Object[] args, String source) Executes a procedure asynchronously within this context.findContext
(int threadId) Finds the currently active call context for a thread id.findContext
(Thread thread) Finds the currently active call context for a thread.Returns the application base directory.Returns the plug-in class loader.Returns the application configuration.Returns the environment used.static ApplicationContext
Returns the singleton application context instance.Returns the procedure library used.Returns the application data storage.Returns the array of cached web matchers (from the web services).protected static ApplicationContext
Creates and initializes the application context.installPlugin
(File file) Installs a plug-in from the specified file.boolean
isPluginBuiltIn
(String pluginId) Checks if the specified plug-in is built-in (or installed).void
loadPlugin
(String pluginId) Loads a plug-in.void
reset()
Resets this context and reloads all resources.void
uninstallPlugin
(String pluginId) Uninstalls and removes a plug-in file.void
unloadPlugin
(String pluginId) Unloads a plug-in.
-
Field Details
-
PATH_CONFIG
The path to the global configuration. -
PATH_PLATFORM
The path to the platform information. -
INIT_TIME
The class load time (system initialization time). -
START_TIME
The context start (or reset) time.
-
-
Method Details
-
init
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 directorylocalDir
- the local add-on directorystart
- 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
Returns the singleton application context instance.- Returns:
- the singleton application context instance
-
reset
public void reset()Resets this context and reloads all resources. -
cachePath
Returns the current web cache path. This is renewed each time the application context is initialized or reset.- Returns:
- the current web cache path
-
getConfig
Returns the application configuration.- Returns:
- the application configuration
-
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
Returns the environment used.- Returns:
- the environment used
-
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
Returns the procedure library used.- Returns:
- the procedure library used
-
getBaseDir
Returns the application base directory.- Returns:
- the application base directory
-
getClassLoader
Returns the plug-in class loader.- Returns:
- the plug-in class loader
-
isPluginBuiltIn
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
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
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
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
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 nameargs
- the procedure argumentssource
- the call source informationtrace
- 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
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 nameargs
- the procedure argumentssource
- the call source information
-
findContext
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
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
-