osgi overview

27
OSGi Overview Presenter: Alex Proca BJUG - 23 oct 2012

Upload: alex-proca

Post on 14-Apr-2017

1.069 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OSGi overview

OSGi Overview

Presenter: Alex Proca

BJUG - 23 oct 2012

Page 2: OSGi overview

Plan

Problem

Solution

Architecture

Tools

Demo & Q

BJUG - 23 oct 2012

Page 3: OSGi overview

Plan

Problem

Dependency Management

Version Hell

Conflicting dependencies

Class loading issues

Dynamic Behavior

Difficulties to control component lifecycle

Lack of a pure modularity solution

Solution

Architecture

Tools

Demo & Q

BJUG - 23 oct 2012

Page 4: OSGi overview

Dependency Management

BJUG - 23 oct 2012

Version Hell - The first case is when a developer or deployer of a Java application

has accidentally made two different versions of a library available to the system. This will

not be considered an error by the system. Rather, the system will load classes from one

or the other library. Adding the new library to the list of available libraries instead of

replacing it, may see the application still behaving as though the old library is in use,

which it may well be

Conflicting dependencies - Another version of the problem arises when two

libraries (or a library and the application) require different versions of the same third

library. If both versions of the third library use the same class names, there is no way to

load both versions of the third library with the same classloader

Class loading issues - The most complex JAR hell problems arise in circumstances

that take advantage of the full complexity of the classloading system. A Java program is

not required to use only a single "flat" classloader, but instead may be composed of

several (potentially very many) nested, cooperating classloaders. Classes loaded by

different classloaders may interact in complex ways not fully comprehended by a

developer, leading to inexplicable errors or bugs.

Page 5: OSGi overview

Dynamic Behavior

BJUG - 23 oct 2012

Components and services needs to be installed / removed

Components need to get updated / replaced

Components need to be started / stopped

Example

Eclipse install/remove plugins/features

Page 6: OSGi overview

Lack of a pure modularity solution

BJUG - 23 oct 2012

JVM does not address modularity

JAR is a black box

No dependency and no version

Pure JVM modularity ?

Jigsaw for JDK 8

But OSGi is available now

Page 7: OSGi overview

Plan Problem

Solution OSGi layers

Deployment infrastructure Bundle = byte code + metadata (imports / exports)

Bundle Activator

Bundle Dependencies

Bundles have a lifecycle

Bundles have their own class loader

Bundle Versioning

Service Platform

Security Layer

Issues

Related Projects

Tools

Demo & Q

BJUG - 23 oct 2012

Page 8: OSGi overview

OSGi layers

BJUG - 23 oct 2012

OSGi Framework

Bundles (modules)

Execution environment

Application lifecycle

Services

Service registry

Security

Application share the same JVM

Page 9: OSGi overview

Bundle

BJUG - 23 oct 2012

Bundle - Basic deployment entity (~ application, library)

Versioned (1.0.2.rc3 – major, minor, micro, qualifier)

Declaratively specified dependencies

Represented as JAR file of

Code, resources

Extended Manifest file

Bundle fragments

Similar to bundles

Allow extending an existing bundle (often used for testing extended

bundle)

Requires a host bundle

Page 10: OSGi overview

Bundle Activator

BJUG - 23 oct 2012

Class defined in manifest.mf

Bundle-Activator header

Can be an external class

Handle bundle start / stop

Start

Register services

Create service trackers

Start threads

Stop

Release resources

Unregister own services

Release used services

Page 11: OSGi overview

Bundle dependencies

BJUG - 23 oct 2012

Expose packages

List all of (packages + versions + attributes)

Fine grained package filtering

Import Bundle

Require specific versions (ex. [10.0.0, 13.0.1) )

Require bundle

Restricts further changes in API (not recommended)

Bundle Class path

Embedded bundle dependencies

Maven bnd plugin uses this feature to transform some non OSGi

libraries to OSGi bundles

Page 12: OSGi overview

Bundle life cycle

BJUG - 23 oct 2012

Page 13: OSGi overview

Separate classloaders

BJUG - 23 oct 2012

Page 14: OSGi overview

Bundle Versioning

BJUG - 23 oct 2012

ZAB

1.0.0

ZAB

1.1.0

BAR

1.0.4

LIB

1.0.1

FOO

1.0.0

Different versions of ZAB in same JVM

FOO

ZAB

1.0.0

BAR

ZAB

1.0.0

Bad (ClassCastException) FOO

ZAB

1.0.0

BAR

Good

Common

Page 15: OSGi overview

Plan

Problem

Solution

OSGi layers

Deployment infrastructure

Service Platform

Registering Service

Consuming Service

Service Tracker

Security Layer

Issues

Related Projects

Tools

Demo & Q

BJUG - 23 oct 2012

Page 16: OSGi overview

Service

BJUG - 23 oct 2012

Bundles – modular but still static entities

How to communicate between bundles?

Services – dynamic in OSGi

Can appear / disappear at runtime in according to a condition

For one service name multiple providers can exist

Service

Object registered by a bundle

BundleContext.registerService(Interface, Impl, Properties)

Framework automatically unregister all services of stopped bundle

Page 17: OSGi overview

Registering Service

BJUG - 23 oct 2012

Programmatically in Bundle Activator

Problems : semantics not clear

Declaratively

DS

Service-Component header refers to xml declaring the service

Page 18: OSGi overview

Consuming Service

BJUG - 23 oct 2012

Bundle can search for service implementing specific

interface

Components

Declare getter components

Page 19: OSGi overview

Service tracker – Consuming Service

BJUG - 23 oct 2012

Tracking for service

Filters by some properties defined with the service

LDAP syntax (ex. (&(type=“dh”)(heavy=“false”)))

Page 20: OSGi overview

Plan

Problem

Solution

OSGi layers

Deployment infrastructure

Service Platform

Security Layer

Issues

Implementations

Related Projects

Tools

Demo & Q

BJUG - 23 oct 2012

Page 21: OSGi overview

Security Layer

BJUG - 23 oct 2012

Optional (most people does not use security)

Based on Java 2 Security Architecture

4 roles

Developer

Adds local permissions to the bundle by signning

Deployer

Sign the bundle and deploy

Operator

Full control all time

End User

Page 22: OSGi overview

Issues

BJUG - 23 oct 2012

No repository defined in standards

Planned for OSGi4

Equinox have p2 repo

Bundle dependency resolver

Resolving bundles can take long time

Page 23: OSGi overview

Implementations

BJUG - 23 oct 2012

Equinox

Bundles can be directories too

Used by eclipse IDE

Felix

Concierge

Knoplerfish

Page 24: OSGi overview

Related Projects

BJUG - 23 oct 2012

rOSGi – access services in a remote OSGi

Glassfish v3

OSGi replace HK2 (module system)

Uses Apache Felix

Spring DM

Donated to eclipse as Virgo project

Integration of OSGi inside spring

Spring application platform

Similar concepts to OSGi

Defines bundle repository

JSR 227

Java modules, proposed OSGi interoperability

Page 25: OSGi overview

Tools

BJUG - 23 oct 2012

m2eclipse – bridge between eclipse and maven

Tycho – build OSGi with maven

Tycho Extras – utils for OSGi builds

Page 27: OSGi overview

Thank you

BJUG - 23 oct 2012