+ All Categories

OSGi

Date post: 10-May-2015
Category:
Upload: zeeshan-bilal
View: 241 times
Download: 5 times
Share this document with a friend
Popular Tags:
18
OSGi The Dynamic Module System for Java TM
Transcript
Page 1: OSGi

OSGiThe Dynamic Module System for JavaTM

Page 2: OSGi

OS

GiMotivation Growing complexity requires not only highly modular

code, but also systems that are dynamically extensible

Because there should be simpler way to construct software systems than writing , writing, and writing …

No matter which problem domain is your area of concern◦ Embedded systems need to adapt to changing requirements

even though they are deployed out in the field◦ Server applications must be configurable and manageable

without down time◦ Client applications must respond to user desires for new

functionality instantaneously

Page 3: OSGi

OS

GiProblems to AddersLack of PortabilityStale DevicesSoftware SizeSoftware ComplexityLimits OO TechnologyQuality of Service

Page 4: OSGi

OS

GiBackgroundStarted as an embedded platform for the

“home gateway”

Originally under the JCP as JSR-8 (1999)

Maintained by OSGi alliance, consists of a large number of big companies.

Current version: OSGi Release 4.2 (JSR-294)

Page 5: OSGi

OS

GiIntroductionAn interesting platform for creating dynamically

extensible applications

Provides a service-oriented, component based environment

Offers standardized ways to manage the software lifecycle.

OSGi technology is Universal Middleware.

Page 6: OSGi

OS

GiWhat we can achieve Resolves many deficiencies associated with

conventional approaches for modularity and dynamism◦ Provide 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

Page 7: OSGi

OS

GiArchitectural Overview

Page 8: OSGi

OS

GiFramework Layers

L3 - publish/find/bind service model to decouple bundles

L2 - independent life-cycle of bundles without JVM restarts

L1 - a module (or bundle) uses classes from other bundles in a controlled way

L0 - well defined profiles that define the environment in which bundles can work

Page 9: OSGi

OS

GiModule Layer Unit of deployment is bundle, a JAR Separate class loader per bundle Multi-version support (side-by-side) Explicit code boundaries and

dependencies Metadata in the manifest Automatic wiring based on version

ranges

Page 10: OSGi

OS

GiLife-cycle Layer

Managed life cycle◦ States for each bundle;

Allows updates of existing bundles.◦ Dynamically install, start,

update, and uninstall

Page 11: OSGi

OS

GiService Layer Service interfaces allow bundles to

interact by binding interfaces, not implementations

Publish/find/bind intra-VM service model

Page 12: OSGi

OS

GiDynamic Service Lookup

OSGi Framework

Provided Service

Provided Package

installbundle.jar

Automatic package dependency resolution

Manual service dependency resolution Existin

g Bundle

Installed

Bundle

Resolv-ed Bundle

resolve bundle

Page 13: OSGi

OS

GiOSGi Service AdvantagesLightweight services

◦ Direct method invocation

Good design practice◦ Separates interface from implementation◦ Enables reuse, substitutability, loose coupling, and late binding

Dynamic◦ Loose coupling and late binding make it possible to support

run-time dynamism

Application's configuration is simply the set of deployed bundles◦ Deploy only the bundles that you need

Page 14: OSGi

OS

GiPaint ProgramCreate a simple Swing-based paint programDefine a SimpleShape interface to draw shapes

◦ Different implementations of SimpleShape can be created to draw different shapes

◦ Each shape has name and icon properties◦ Available shapes are displayed in tool bar

To draw a shape, click on its button and then click in the drawing canvas◦ Shapes can be dragged, but not resized

Support dynamic deployment of shapes

Page 15: OSGi

OS

GiHigh Level Architecture

Best practice – Try to

centralize interactionwith OSGi API so that

other componentsremain POJOs...onlyShape Tracker willinteract with OSGi

API.Best practice – Do

notmake assumptions

about threads...since we

are creating a Swingapplication, Shape

Tracker sends events on

Swing thread.

Main applicationwindow – gets dynamically

injectedwith available

shapesfrom the Shape

Tracker..

Actual shapeimplementation.

Injected “proxied” shapeimplementation to hideaspects of dynamismand provide a defaultimplementation.

Component that draws the

shape in parent frame; looks

up shape via Drawing Frame

rather than having a direct

reference..

Page 16: OSGi

OS

Gi

DEMO

Page 17: OSGi

OS

GiAdoptionApplications can leverage OSGi

functionality in two ways◦Bundled application

Build entire application as a set of bundles that will run on top of a framework instance

◦Hosted framework Host a framework instance inside the

application and externally interact with bundles/services

Page 18: OSGi

OS

GiAdoption (Bundled vs Hosted)Building your application as a set of bundles is

the preferred approach◦ Allows all parts of application to benefit from OSGi

modularity and dynamism◦ Allows application to run on any framework◦ However, it is not always possible to bundle

application, e.g., legacy situationsHosted framework approach allows piecemeal

OSGi adoption◦ Will likely tie application to a framework

implementation


Recommended