Top Banner
OSGi platform Yuriy Shapovalov EPAM Systems
53

Osgi platform

May 10, 2015

Download

Technology

Open Services Gateway Initiative slides from Kiev JavaDay 2012 (27 October) Conference
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Osgi platform

OSGi platform

Yuriy ShapovalovEPAM Systems

Page 2: Osgi platform

What is it?

“The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that as of 2012 does not exist in standalone Java/VM environments.” – Wikipedia

OSGi Platform

Page 3: Osgi platform

… module system …

“The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that as of 2012 does not exist in standalone Java/VM environments.” – Wikipedia

OSGi Platform

Page 4: Osgi platform

… service platform …

“The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that as of 2012 does not exist in standalone Java/VM environments.” – Wikipedia

OSGi Platform

Page 5: Osgi platform

… for Java programming language …

“The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that as of 2012 does not exist in standalone Java/VM environments.” – Wikipedia

OSGi Platform

Page 6: Osgi platform

…complete and dynamic component model …

“The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that as of 2012 does not exist in standalone Java/VM environments.” – Wikipedia

OSGi Platform

Page 7: Osgi platform

“The Open Services Gateway initiative framework is a module system and service platform for the Java programming language that implements a complete and dynamic component model, something that as of 2012 does not exist in standalone Java/VM environments.” – Wikipedia

OSGi Platform

… does not exist in standalone Java/VM …

Page 8: Osgi platform

OSGi history

o Initially was developed as an embedded platform for the “home gateway”;o and make it easier to deploy Java application on embedded devices

o OSGi Alliance was formed in 1999, and it has following mission:• Maintaining and publishing OSGi specification• Certifying implementations• Organizing events.

o Specification target was: “Define Java-based service platform, full dynamic component model”• Because JVM does not support natively dynamic module

system – starting, stopping, updating application at runtime• JAR dependencies management missing

OSGi Platform 8/42

Page 9: Osgi platform

o Adaptive

o Flexible

o Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 9/42

B C

D E F

G H I

Page 10: Osgi platform

Adaptive

o Flexible

o Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 10/42

A B C

D E F

G H I

Page 11: Osgi platform

Adaptive

o Flexible

o Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 11/42

A B C

D E F

G H I

Page 12: Osgi platform

Adaptive

Flexible

o Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 12/42

A Ba C

D E F

G H I

Bb

Page 13: Osgi platform

Adaptive

Flexible

o Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 13/42

A Ba C

D E F

G H I

Bb

Page 14: Osgi platform

Adaptive

Flexible

Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 14/42

A Ba C

D E F

G H I

Bb

Page 15: Osgi platform

Adaptive

Flexible

Contracts

o Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 15/42

A Ba C

D E F

G H I

Bb

Page 16: Osgi platform

Adaptive

Flexible

Contracts

Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 16/42

A Ba C

D E F

G H

Bb

Page 17: Osgi platform

Adaptive

Flexible

Contracts

Robust

o Secure

o Evolution

o Distributed

The Dream

OSGi Platform 17/42

A Ba C

D E F

G H

Bb

Page 18: Osgi platform

Adaptive

Flexible

Contracts

Robust

Secure

o Evolution

o Distributed

The Dream

OSGi Platform 18/42

A Ba C

D E F

G H

Bb

Page 19: Osgi platform

Adaptive

Flexible

Contracts

Robust

Secure

o Evolution

o Distributed

The Dream

OSGi Platform 19/42

A Ba C

D E F

G H

Bb

Page 20: Osgi platform

Adaptive

Flexible

Contracts

Robust

Secure

o Evolution

o Distributed

The Dream

OSGi Platform 20/42

A Ba C

D E F

G H I v2.0

Bb

Page 21: Osgi platform

Adaptive

Flexible

Contracts

Robust

Secure

Evolution

o Distributed

The Dream

OSGi Platform 21/42

A Ba C

D E F

G H I v2.0

Bb

Page 22: Osgi platform

Adaptive

Flexible

Contracts

Robust

Secure

Evolution

o Distributed

The Dream

OSGi Platform 22/42

A Ba C

D E F

G H I v2.0

Bb

Page 23: Osgi platform

Adaptive

Flexible

Contracts

Robust

Secure

Evolution

Distributed

The Dream

OSGi Platform 23/42

A Ba

D E F

G I v2.0

Bb

Page 24: Osgi platform

What is an OSGi application

o Collection of bundles integrated via Service interfaceso Bundles may be independently developed and deployedo Bundles and their associated services may appear or

disappear at any time

o Resulting application follows a Service-Oriented Component Model approacho Combines Ideas from both component and service orientation

OSGi Platform 24/42

Page 25: Osgi platform

Architecture abstraction

o Application is a set of independent components, collaborating between each other in a service orienting way.

OSGi Platform 25/42

Application

A C D

B E F

Page 26: Osgi platform

Architecture abstraction

o Application implement reduced functionality, all additional features implements as plug-ins

OSGi Platform 26/42

ApplicationA

C

D

B E F

Page 27: Osgi platform

Architecture abstraction

o or even…

OSGi Platform 27/42

Application

A C D

B E

A

B

D

E

Page 28: Osgi platform

× Focus on “what”, not “how”× Encapsulate the implementation details× Formalize the input data (arguments)× Formalize the output data (return values)

Next level of modularity

OSGi Platform 28/42

Subroutines (50’s)

Page 29: Osgi platform

Then systems grew…

Spaghetti Code

Next level of modularity

OSGi Platform 29/42

Subroutines (50’s)

Functions

functionInput (arguments) Output (return)

Page 30: Osgi platform

Next level of modularity

OSGi Platform 30/42

Subroutines (50’s)

Functions

Modules (70’s)

ModuleImported Functions Exported Functions

Then systems grew…

Sharing Proved Hard

Page 31: Osgi platform

Next level of modularity

OSGi Platform 31/42

Subroutines (50’s)

Functions

Classes/Objects (80’s)

Modules (70’s)

TypeImported Members Exported Members

Then systems grew…

Page 32: Osgi platform

Next level of modularity

OSGi Platform 32/42

Subroutines (50’s)

Functions

Classes/Objects (80’s)

Modules (70’s)

Packages (90’s)

TypeImported Types Exported Types

Then systems grew…… and distributed… and multiplies

Page 33: Osgi platform

Small Java App …

Next level of modularity

OSGi Platform 33/42

Page 34: Osgi platform

Next level of modularity

OSGi Platform 34/42

Subroutines (50’s)

Functions

Classes/Objects (80’s)

Modules (70’s)

Packages (90’s)

Bundles (00’s)

Bundle(JAR file)

Imported Packages Exported Packages

Page 35: Osgi platform

Bundle

o A Bundle - is a module in OSGi terminology

o What is a bundle?• Simply a JAR file plus module metadata• Modules metadata is stored in META-INF/MANIFEST.MF

• Define what the module provides and require

o What does a bundle JAR contain?• Java classes (i.e., standard JAR file content)• Resources (e.g., configuration files, images, etc.)• Native code• Embedded JAR files

• Bundles have their own class path

OSGi Platform 35/42

Page 36: Osgi platform

OSGi architecture

OSGi Platform 36/42

OS / Hardware

Java VM

OSGi LayerApplication composite(Bundles)

Security

Module

Life Cycle

Service

BundleBundle

BundleBundle

BundleBundle

Bundle

Page 37: Osgi platform

Life cycle of bundles

OSGi Platform 37/42

INSTALLED

RESOLVED

UNINSTALLED

STARTING

ACTIVE

STOPPING

Page 38: Osgi platform

Services System

o Services are simple POJOs with a published service interfaceo Coupling to the framework is isolated to the Activator and

collaboratorso Services may bind to other services through their published

interfaceso The framework provides a standard Service Factory mechanism

OSGi Platform 38/42

Bundle A Service Registry

Bundle B

Bundle C

Service

publish

track

track

publish

Page 39: Osgi platform

OSGi Bundle Manifest

OSGi Platform 39/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Page 40: Osgi platform

OSGi Bundle Manifest

OSGi Platform 40/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Indicates semantic and syntax

Page 41: Osgi platform

OSGi Bundle Manifest

OSGi Platform 41/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Indicates semantic and syntaxGlobally unique ID

Page 42: Osgi platform

OSGi Bundle Manifest

OSGi Platform 42/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Life cycle entry point

Page 43: Osgi platform

OSGi Bundle Manifest

OSGi Platform 43/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Internal bundle class path

Page 44: Osgi platform

OSGi Bundle Manifest

OSGi Platform 44/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Native code dependencies

Page 45: Osgi platform

OSGi Bundle Manifest

OSGi Platform 45/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package: osgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Optional dependency on a package version

range

Page 46: Osgi platform

OSGi Bundle Manifest

OSGi Platform 46/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Provided package with arbitrary attribute and

excluded classes

Page 47: Osgi platform

OSGi Bundle Manifest

OSGi Platform 47/42

Bundle-ManifestVersion: 2

Bundle-SymbolicName: org.foo.simplebundle

Bundle-Version: 1.0.0

Bundle-Activator: org.foo.Activator

Bundle-ClassPath: .,org/foo/embedded.jar

Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86,foo.dll; osname=Windows 7; processor=x86

Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; resolution:="optional"

Export-Package: org.foo.service; version=1.1; vendor="org.foo:"; exclude:="*Impl", org.foo.service.bar; version=1.1; uses:="org.foo.service"

Provided package with dependency on

exported package

Page 48: Osgi platform

Declarative Services

o Declarative services provides a minimally intrusive way to:• Define components that provide and use services• Automate dependency resolution and maintenance

OSGi Platform 48/42

package foo.impl;public class HelloImpl implements foo.HelloService { LogService log; protected void setLog(LogService l) { log = l; } protected void unsetLog(LogService l) { log = null; } public void sayHello(String s) { log.log(LogService.LOG_INFO, "Hello " + s); }}

Page 49: Osgi platform

Declarative Services

o Declarative services component metadata:

OSGi Platform 49/42

<?xml version="1.0" encoding="UTF-8"?><component name="example.hello"> <implementation class="foo.impl.HelloImpl"/> <service> <provide interface="foo.HelloService"/> </service> <reference name="LOG" interface="org.osgi.service.log.LogService" bind="setLog" unbind="unsetLog" /></component>

Page 50: Osgi platform

OSGi implementations

o Specification it is good, but without implementation it is a dead stuff

o The most popular open source implementation is:

• Equinox

• Apache Felix

• Knopflerfish

OSGi Platform 50/42

Page 51: Osgi platform

OSGi in Enterprise (as example)

o Why?• Create modular and reusable software• Create evolvable software• Create line of products

o What?• Desktop Applications• Web Applications• Service Layers• Content Management Systems• Embedded and Mobile Applications• Cloud Applications

OSGi Platform 51/42

Page 52: Osgi platform

Conclusions

o Java needs improved modularity support• Lagging behind .NET in this area for years• The OSGi framework provides it now

o Importance and relevance of OSGi is growing• Industry support for mobile applications• Significant uptake in the enterprise space

OSGi Platform 52/42

Page 53: Osgi platform

Questions?

OSGi Platform 53/42