OSGI is a excellent concept that allows multiple different application to be deployed in a single JVM. In an OSGI, each application or unit is called bundle. Each bundle is loaded into the JVM with different class loaders.
Following are major keywords in the OSGI.
- Bundles – Bundles are the OSGi components made by the developers.
- Services – The services layer connects bundles in a dynamic way by offering a publish-find-bind model for plain old Java objects.
- Life-Cycle – The API to install, start, stop, update, and uninstall bundles.
- Modules – The layer that defines how a bundle can import and export code.
- Security – The layer that handles the security aspects.
- Execution Environment – Defines what methods and classes are available in a specific platform.
OSGI is a good operating model if you have a many applications that requires:
- applications tightly interacts with each others.
- requires low latency in processing – this is achieved in OSGI environment as applications are deployed in same JVM. Though applications are partitioned by class loader, they run on same JVM. Thus, application may interact without leaving the JVM, providing the low latency. Here applications are segregated at development time but tightly coupled at run-time for performance.
Disadvantages of OSGI:
- Applications are tightly coupled at run-time environment, even though applications are decoupled through bundle.
- Applications shares same JVM resources; thus requires extra analysis before adding an application to ensure that JVM resources are not overly consumed by one application. This gives rise to a possibility of an application using too much resources while starving other application.
- A problem application can bring down whole OSGI environment; thus introducing run-time risk associated with other application.
- If an OSGI environment needs recycle, this impacts all the application in that environment.
- Applications are tightly coupled in OSGI environment, even though they are total different and separate functional processing.
OSGI and Singleton
Singleton by definition is a single class in the JVM.