Introduction to Open Service Gateway Initiative (OSGI) Framework
OSGi Framework offers a dynamic modular architecture that has been used in many applications such as Apache Felix, Eclipse Equinox, Knopflerfish etc.. OSGi Framework is a java framework for developing and deploying modular software applications and libraries. The OSGi Alliance formerly known as the Open Service Gateway Initiative is an open standards organization and its maintain the OSGi standard.
OSGi Framework is represents Microkernel Architecture for its plugin development. And plugin architecture has two main components which is Core system and Plugin module. Plugin modules are stand alone independent components, and Core system need know which plugin modules are available to use for service registry etc..
OSGi Framework Architecture
The functionality of the Framework is divided in the following layers.
- Security Layer
- Module Layer
- Life Cycle Layer
- Service Layer
- Actual Services
.
.
Security Layer
The Security Layer is based on Java security but adds a number of constraints and fills in some of the blanks that standard Java leaves open. It defines a secure packaging format as well as the runtime interaction with the Java security layer.
Module Layer
The Module Layer defines a modularization model for Java. It addresses some of the shortcomings of Java’s deployment model. The modularization layer has strict rules for sharing Java packages between bundles or hiding packages from other bundles. The Module Layer can be used without the life cycle and Service Layer. The Life Cycle Layer provides an API to manage the bundles in the Module Layer, while the Service Layer provides a communication model for the bundles.
Life Cycle Layer
The Life Cycle Layer provides a life cycle API to bundles. This API provides a runtime model for bundles. It defines how bundles are started and stopped as well as how bundles are installed, updated and uninstalled. Additionally, it provides a comprehensive event API to allow a management bundle to control the operations of the OSGi framework. The Life Cycle Layer requires the Module Layer but the Security Layer is optional.
Service Layer
Service Layer defines a dynamic collaborative model that is highly integrated with the Life Cycle Layer. The service model is a publish, find and bind model. A service is a normal Java object that is registered under one or more Java interfaces with the service registry. Bundles can register services, search for them, or receive notifications when their registration state changes.
Actual Services
Service Compendium is specifies a number of services that may be available in an OSGi runtime environment. Although the OSGi Core Framework specification is useful in itself already, it only defines the OSGi core infrastructure. The services defined in the compendium specification define the scope and functionality of some common services that bundle developers might want to use.
Ex: Log Service, Http Service, Configuration Admin Service, Metatype Service, User Admin Service, Declarative Services Specification, Event Admin Service, Blueprint Specification, Remote Services Specifications, JTA Specification, JMX Specification, JDBC Specification, JNDI Specification, JPA Specification, Web Applications Specification, Service Tracker Specification, Etc..
Lifecycle of a bundle
OSGi is a dynamic platform. This means that bundles may be installed, started, updated, stopped, and uninstalled at any time during the running of the framework.
.
.
INSTALLED
The bundle has been installed into the OSGi container, but some of the bundle’s dependencies have not yet been met. The bundle requires packages that have not been exported by any currently installed bundle.
RESOLVED
The bundle is installed, and the OSGi system has connected up all the dependencies at a class level and made sure they are all resolved. The bundle is ready to be started. If a bundle is started and all of the bundle’s dependencies are met, the bundle skips this state.
STARTING
A temporary state that the bundle goes through while the bundle is starting, after all dependencies have been resolved.
ACTIVE
The bundle has been successfully activated and is running.
STOPPING
A temporary state that the bundle goes through while the bundle is stopping.
UNINSTALLED
The bundle has been removed from the OSGi container.
OSGi Framework Benefits
- Applications are portable, easier to re-engineer, and adaptable to changing requirements.
- OSGi Framework offers you to Dynamic loading / unloading, configurations and manipulate those bundles without restarting.
- Manages deployments local or remotely.
- OSGi container allows to break the application into individual Modules.
- Manage the cross-dependencies between modules.