The question is quite similar to this one, but I need to concentrate on different issues.
Suppose I have an application with a large database (i.e. movie database). The user of the application should be able to add her own plugins and be able to run them.
The scenario could look like this:
- launch the main app
- place stats-plugin.jar in the /app/plugins directory
- tell the main app to load the new plugin
- tell the app to list the plugins
- choose a plugin (e.g. the just installed one) and run it
- the stats-plugin.jar queries the db about movies and counts the horror movies, returns the count
- the main app presents the result
Each plugin could have a couple of standard methods (a common Plugin
interface) that would be called, e.g. onInitialize
, onRun
etc.
What the main app needs to guarantee is that if the plugin crashes (e.g. divides by 0) the main app will remain stable (will show an error dialog for example, but won't crash itself). It should be also possible to limit the time of execution and check what operations the plugin is performing.
This all sums up to a sandboxed plugin environment. The most important things are: plugin-style extensibility and sandboxing the plugins - allowing only for safe operations (e.g. reading the DB, but not updating it).
The plugin doesn't have to be written in Java. It needs to be executable in some way... It could even be a JavaScript file.. if it is possible.
How would you approach such a task?