Purpose of OSGi :
The primary goal of OSGi is to provide a modular and dynamic architecture for Java applications, solving issues related to classloading, dependency management, and runtime flexibility. It helps in creating scalable, maintainable, and version-aware applications.
OSGi Framework Architecture :
The OSGi framework consists of several layers:
1. Bundles
- These are the modular components of an application (JAR files with extra metadata).
- Each bundle has its own classloader, allowing multiple versions of the same library to exist in an application.
2. Services Layer
- Provides a dynamic service registry where bundles can register, discover, and use services at runtime.
- Enables loose coupling between components.
3. Lifecycle Management
- Each bundle follows a lifecycle (Installed, Resolved, Starting, Active, Stopping, Uninstalled).
- The BundleContext API allows dynamic control of bundles at runtime.
4. Modules Layer
- Defines dependency management using the
MANIFEST.MF file.
- Allows hiding implementation details while exposing only necessary APIs.
5. Security Layer
- Provides a fine-grained permission model to control access to resources and services.
6. Execution Environment
- Defines the Java environment in which OSGi runs (J2SE, J2ME, or custom environments).