Osgi platform

Post on 10-May-2015

361 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Open Services Gateway Initiative slides from Kiev JavaDay 2012 (27 October) Conference

Transcript

OSGi platform

Yuriy ShapovalovEPAM Systems

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

… 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

… 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

… 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

…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

“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 …

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

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

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

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

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

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

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

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

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

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

Adaptive

Flexible

Contracts

Robust

Secure

o Evolution

o Distributed

The Dream

OSGi Platform 18/42

A Ba C

D E F

G H

Bb

Adaptive

Flexible

Contracts

Robust

Secure

o Evolution

o Distributed

The Dream

OSGi Platform 19/42

A Ba C

D E F

G H

Bb

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

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

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

Adaptive

Flexible

Contracts

Robust

Secure

Evolution

Distributed

The Dream

OSGi Platform 23/42

A Ba

D E F

G I v2.0

Bb

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

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

Architecture abstraction

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

OSGi Platform 26/42

ApplicationA

C

D

B E F

Architecture abstraction

o or even…

OSGi Platform 27/42

Application

A C D

B E

A

B

D

E

× 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)

Then systems grew…

Spaghetti Code

Next level of modularity

OSGi Platform 29/42

Subroutines (50’s)

Functions

functionInput (arguments) Output (return)

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

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…

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

Small Java App …

Next level of modularity

OSGi Platform 33/42

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

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

OSGi architecture

OSGi Platform 36/42

OS / Hardware

Java VM

OSGi LayerApplication composite(Bundles)

Security

Module

Life Cycle

Service

BundleBundle

BundleBundle

BundleBundle

Bundle

Life cycle of bundles

OSGi Platform 37/42

INSTALLED

RESOLVED

UNINSTALLED

STARTING

ACTIVE

STOPPING

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

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"

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

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

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

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

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

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

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

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

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); }}

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>

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

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

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

Questions?

OSGi Platform 53/42

top related