Still OSGi

Author: Ayşenur DURGUT, Senior SW Engineer, Defence Applications Software Group

OSGi (OSGi Alliance, formerly the Open Service Gateway Initiative) technology is widely used with Java for over 17 years. Since the framework has been supported by key companies for a long time, its development and stability has grown day by day. Different implementations are available that are developed by important corporations. Widely preferred implementations are Apache Felix, Eclipse Equinox, Knopflerfish and ProSyst. Knopflerfish and ProSyst are built upon Apache Felix. ProSyst is a commercial OSGi container for embedded platforms. OSGi framework also enables remote service connections.

Biggest advantage is providing dynamism: Components can be replaced at runtime without system shut down. Other benefits worth mentioning are increasing reusability and easy versioning.

OSGi architecture is composed of several layers; bundles, services, life cycle, modules, security and execution environment [1]. These layers are briefly explained as follows:

Bundle is one of the key terms for OSGi framework. Bundle is a JAR file with an important difference from the  standard JAR files. Bundle hides all information except information that is explicitly exported for the use of other services.

A bundle registers itself as a service through a defined interface to OSGi environment. A bundle can also be registered with multiple interfaces as several services. After the registration phase, services are available to other services’ access. Services within OSGi environment can track registered services at the environment with service tracker mechanism. Following figure displays service tracking in a nutshell. One of the challenges from developer’s point of view is, all dependencies should be managed, as relied services may not be present for all the execution time. Services should be accessed when they are registered at the environment.

Another pitfall is, service dependencies could cause circular dependencies. One solution for preventing a circular dependency could be constructing a third service for common use.

Life cycle layer manages the installation, start, stop and uninstallation processes of bundles. Bundle manifest defines the bundle activator class. This class contains start and stop methods which are executed at bundle start and stop. Activator class implementation is responsible for internal initialization and cleanup operations. In case of exception, at start method is captured by the life cycle layer and interpreted as bundle is resolved (not started).

Modules contain JAR files forming bundles and extra metadata such as images, xml files etc. Manifest defines which part of the bundle is accessible from the OSGi environment. Next layer is security and it is based on Java 2 security architecture. Execution environment layer defines which bundle will run at a specific environment (Java SE, Java EE, Java versions etc.).

After this brief information about OSGi layer architecture, it should be stated that an important point for OSGi use is orchestration of the bundles as projects get complicated. OSGi provides Start Level API which is responsible from starting bundles according to specified start levels. If start level is not set explicitly, default start level is used. Execution order for bundles which have the same start level is uncertain. In addition, start level does not guarantee services’ presence order. For orchestration of the services, developers should not count on start level adjustment. Service tracker is a safe decision, but it is a challenging path to be followed.

Many developers and architects complain that the management of huge number of services gets harder by time. Those who worry about the complexity of OSGi are waiting for Jigsaw with Java 9 release. Jigsaw is claimed to be much simpler to handle, but with a disadvantage: It will be supported only by Java 9. The risk of migrating existing projects to Jigsaw may not be taken. Since OSGi is widely used and support is still available, it is expected that OSGi will be stronger with Java 9 adaptation.



Leave a Reply

Your email address will not be published.