OSGi module framework in ADempiere
OSGi is a modular framework for Java with many advanced features. For information see http://en.wikipedia.org/wiki/OSGi.
Modular design has many advantages on huge projects such as ADempiere. Integrating OSGi may have huge impact on maintainability of the code.
Integration with ADempiere was done by Schmidt András.
OSGi module framework is not part of the project yet it is just a proposal.
Technical documentation and howto
The Apache Felix OSGi implementation was selected for integration. This is the framework that is easiest to be run embedded.
Embedding an OSGi framework with the following properties could be a common task when converting non-OSGi software to modular design. So I have decided to create a new project for the embedding code. This project's output is a single jar file that contains felix.jar and some helper methods for easier startup. Helper methods' interface are implementation independent so change to Equinox or Knopflerfish can be done by just replacing a single jar of the project.
The properties of embedding:
- Don't use a constant configuration but create a new one for each started instance in a temporary directory.
- Start all plugins in a directory on startup. So installing plugins can be done by just copying them.
- Hot Start plugins, so plugins can be started without restarting the server.
- Export some packages of the host application, so they can be reached from the osgi bundles.
Parameters of the OSGI starter
The exported packages of the host application (so bundles can resolve these packages and load classes from them) are listed in file: "base/src/org/compiere/exported.properties"
This file is a comma and whitespace separated list of package names. It has ".properties" suffix so that it will be packaged into the created jar file without changing the build.xml files.
Initial startup plugins directory
Osgi bundles in this directory will be started on ADempiere (embedded osgi) startup.
Changes made to the source code
- replace class.forName(name) constructions throughout the code with ClassLoaderUtil.loadClass(name). It is imperative as the few lines of class loading n-plicates code all around the project. This util handles OSGI extension mechanisms _and_ class.forName mechanism. OSGI class loading and later extension mechanisms can then be integrated at a single point.
- Hook OSGI startup to server and client startup.
- Include apache felix Osgi framework jar into the project.
- Add a plugin autoloader funcionality to OSGI that scans a directory for new plugins, so installing a plugin does not require hacking with configuration files.
- Add a MANIFEST.MF file to the project with "Export-Package: " tag. This way osgi plugins in Eclipse workspace will be able to resolve dependencies set as packages to the ADempiere project. This package export should be added to each separate project too. As I use single project workspace I could not do that work.