OSGI

What Is OSGi?

OSGi Working Group | The Eclipse Foundation
  • OSGi is a Java framework for developing and deploying modular software programs and libraries.
  • As a developer, you use the OSGi specification and tools to create one or more bundles.
  • OSGi defines the lifecycle for these bundles.
  • It also hosts them and supports their interactions in a container.
  • You can think of an OSGi container as roughly analogous to a JVM, with additional powers. Likewise, think of bundles as Java applications with unique abilities. Bundles run inside the OSGi container as client and server components.
  • In OSGi, multiple applications can exist within the same container: the OSGi bundle runtime environment. The container ensures each component is sufficiently isolated, and also has access to any dependencies it requires.

OSGi overview

  1. OSGi framework
    • The framework is the runtime that implements and
      provides OSGi functionality.
  2. OSGi standard services
    • The standard services define reusable APIs for common tasks, such as Logging.

Why we need OSGi?

  • It reduces complexity in almost all aspects of development
  • Code is easier to write and test, reuse is increased, build systems become significantly simpler
  • Deployment is more manageable

Advantages of OSGi

  • You can install, uninstall, start, and stop different modules of your application dynamically without restarting the container.
  • Your application can have more than one version of a particular module running at the same time.
  • OSGi provides very good infrastructure for developing service-oriented applications, as well as embedded, mobile, and rich internet apps.

Usage

  • Healthcare
  • Media Control Systems
  • Telecommunications
  • Enterprise Software Platforms
  • Robotics
  • mobile phones to the open-source Eclipse IDE

OSGi containers

  • It is a Component framework.
  • Three popular open source OSGi containers:
    • Equinox – By Eclipse
    • Apache Felix – By Apache Software Foundation
    • Knopflerfish – By Makewave

OSGI Architecture

  • Module Layer
    • The Bundle
    • Packaging and sharing the code
  • Lifecycle Layer
    • The Container
    • Managing an OSGi application
  • Service Layer
    • The system
    • How OSGi bundles communicate

Module Layer (Bundle Layer)

  • OSGi lets you divide your Java application into bundles
  • Every bundle has a name and a version
  • Bundles can declare dependency on each-other
  • When you drop a bundle in an OSGi container, then the container handles the inter-dependencies automatically.
Sample Manifest.MF file
Manifest-Version: 1.0
Bnd-LastModified: 1618862826488
Build-Jdk: 1.8.0_281
Built-By: Maneesha
Bundle-Description: Simple User Registration Module with REST API.
Bundle-DocURL: http://www.wso2.org/
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-ManifestVersion: 2
Bundle-Name: org.wso2.carbon.identity.user.registration.smu.core
Bundle-SymbolicName: org.wso2.carbon.identity.user.registration.smu.co
 re
Bundle-Vendor: WSO2
Bundle-Version: 0.0.1
Created-By: Apache Maven Bundle Plugin
DynamicImport-Package: *
Export-Package: org.wso2.carbon.identity.user.registration.smu.core;Class=org.wso2.carbon.user.core.service.RealmService)";effective:=act
 ive,osgi.service;filter:="(objectClass=org.wso2.carbon.utils.Configur
 ationContextService)";effective:=active,osgi.ee;filter:="(&(osgi.ee=J
 avaSE)(version=1.8))"
Service-Component: OSGI-INF/org.wso2.carbon.identity.framework.user.re
 gistration.smu.core.component.xml
Tool: Bnd-3.2.0.201605172007

What is Modularity?

  • Modularity is a software designing architecture. 
  • Modularity enables the program to separate the functionality of a large program into independent, interchangeable modules, in such a way that each contains everything necessary to execute only one aspect of the desired functionality.

What is a Module?

  • Logically independent piece
  • Each module in the system has their own boundary and in a single module

Advantages of modularity

  1. The module is small enough to understand and debug
  2. Easy to monitor, control and maintain
  3. Can be tested independently

 Life-cycle Layer

  • A Life-Cycle layer adds bundles that can be dynamically installed, started, stopped, updated and uninstalled.
  • Bundles rely on the module layer for class loading but add an API to manage the modules in run time.
  • The life cycle layer introduces dynamics that are normally not part of an application.
  • Extensive dependency mechanisms are used to assure the correct operation of the environment.
  • Life cycle operations are fully protected with the security architecture.

l.png

  • INSTALLED
    • BundleContex.installBundle() , the operation creates a bundle in this state.
  • RESOLVED
    • All Java classes that the bundle needs are available. This state indicates that the bundle is either ready to be started or has stopped.
  • STARTING
    • The bundle is being started, the BundleActivator.start() the method has been called but the start method has not yet returned. When the bundle has an activation policy, the bundle will remain in the STARTING state until the bundle is activated according to its activation policy.
  • ACTIVE
    • The bundle has been successfully activated and is running; its Bundle Activator start method has been called and returned. If there is an error in the ACTIVE state it will go to the RESOLVED state again, this jumps to RESOLVED state because in that state all the dependencies are resolved so no need to jump to the INSTALLED state again.
  • STOPPING
    • The bundle is being stopped. The BundleActivator.stop() method has been called but the stop method has not yet returned.
  • UNINSTALLED
    • The bundle has been uninstalled. It cannot move into another state.

Service Layer

  • Thus to provide the interaction between bundles, services are used.
  • Services are specified by the Java interface.

Parties in Service

  • Service Provider
    • Bundles can implement this interface and register the service with the Service Registry.
  • Service Consumer
    • Clients of the service can find it in the registry

Leave a comment