OSGi: - Open Services Gateway Initiative
Motivation
JEE world buzzwords have always been scalability, transaction management, security, high availability, manageability, monitoring etc. Trust me coming from my personal experience it is a stereotypical statement, but we do understand these problems and have successfully crafted solutions for each of them to an acceptable degree. But the major challenge lies in JEE based application deployment and things have basically remained unchanged since the very origin of JEE. No denying the implementation of modularization is implemented in code by dividing code base in modules, whether logical, physical or conceptual, at runtime they are seen as one monolithic application in which, making a change (be it large or small), requires a restart.
Modularity in java is achieved by using
· Java class files
· Java Archive (JAR) files
1.Provide form of physical modularity
2. May contain applications, extensions, or services
3. May declare dependencies
4. May contain package version and sealing information
Java provides the mechanisms to do these things, but they are
· Low level
· Error prone
· Ad hoc
Java's shortcoming are particular evident in its support for both modularity and dynamism
Java Modularity Limitations
· Limited scoping mechanisms
§ No module access modifier
· Simplistic version handling
1. Class path is first version found
2. JAR files assume backwards compatibility at best
· Implicit dependencies
1. Dependencies are implicit in class path ordering
2. JAR files add improvements for extensions, but cannot control visibility
· Split packages by default
1. Class path approach searches until it finds, which leads to shadowing or version mixing
2. JAR files can provide sealing
· Unsophisticated consistency model
1. Cuts across previous issues, it is difficult to ensure class space consistency
2. Missing module concept
3. Classes are too fine grained, packages are too simplistic, class loaders are too low level
· No deployment support
Java Dynamism Limitation
· Low-level support for dynamics
- Class loaders are complicated to use and error prone
· Support for dynamics is still purely manual
- Must be completely managed by the programmer
- Leads to many ad hoc, incompatible solutions
· Limited deployment support
- Unable to load modified classes at runtime
OSGi
OSGi framework provides
- Simple component model
- Component life cycle management
- Service registry
- Standard service definitions (separation of specification & implementation)
OSGi Resolves many deficiencies associated with standard Java support for modularity and dynamism
- Defines a module concept
- Explicit sharing of code (i.e., importing and exporting)
- Automatic management of code dependencies
- Enforces sophisticated consistency rules for class loading
- Life-cycle management
- Manages dynamic deployment and configuration
OSGi framework is used as a modularity mechanism for Java and provides logical and physical system structuring. It has benefits for development and deployment. It provides sophisticated dynamic module life-cycle management. It simplifies creation of dynamically extensible systems, where system components can be added, removed, or rebound at run time while the system as a whole continues to function
OSGi framework promotes a service oriented interaction pattern as shown below: -
OSGi Features
- Simple component and packaging model
Bundles = JARs and contain java classes, resources and meta-data
That is, bundle represents a single component contained in a JAR file. A bundle defines a logical and physical modularity unit with
· Explicit boundaries
- External interface (i.e., exports)
- Internal class path
Java code, resources, and native libraries
· Explicit dependencies
- Package dependencies (i.e., imports)
· Explicit versioning
- Package version, bundle version
· Isolation via class loaders
· Packaging format (bundle JAR file)
- Meta-data explicitly defines boundaries & dependencies as java package imports & exports.
- Dependencies & associated consistency are automatically managed
The framework automatically resolves package dependencies when a bundle is activated
- Matches bundle’s imports to available exports
- Ensures package version consistency
· If a bundle cannot be successfully resolved, then it cannot be activated/used
Hence OSGi is a collection of bundles that interact via service interfaces and these bundles may be independently developed and deployed. Bundles and their associated services may appear or disappear at any time
- Defines a component life cycle
OSGi framework defines dynamic bundle life cycle
· Possible to install, update, and uninstall code at run time
· Automatic package dependency resolution
· Replaces low-level class loaders
- Explicitly considers dynamic scenarios
- Interaction through service interfaces
- Multi-version support
That is, it’s possible to have more than one version of a shared package in memory at the same time. As result for a given bundle, the service registry is implicitly partitioned according to the package versions visible to it
- Import version range
That is, exporters still export a precise version, but importers may specify an open or closed version range. It also eliminates existing backwards compatibility assumption.
Import-Package: ClaimService; version=“[1.0.0,1.5.0)”
Note: - Multi-version sharing and importing version ranges make implementation package sharing possible
- Arbitary export/import attributes
· Exporters may attach arbitrary attributes to their exports, importers can match against these arbitrary attributes
· Exporters may declare attributes as mandatory
· Mandatory attributes provide simple means to limit package visibility
· Importers influence package selection using arbitrary attribute matching
Import-Package: ServiceImpl;
version=“1.0.0”;
myattr=“myvalue”
- Package Consitency model
· Exporters may declare package “uses” dependencies
· Exported packages express dependencies on imported or other
exported packages, which constrain the resolve process
· The framework must ensure that importers do not violate constraints implied by “uses” dependencies.
Hence its pretty conclusive OSGi will provide in true sense modularization in java and much needed deployment ease
No comments:
Post a Comment