OSGi platform

Yuriy Shapovalov
EPAM Systems
What is it?
“The Open Services Gateway initiative framework is a
module system and service platform for the Java programmi...
… module system …
“The Open Services Gateway initiative framework is a
module system and service platform for the Java pro...
… service platform …
“The Open Services Gateway initiative framework is a
module system and service platform for the Java ...
… for Java programming language …
“The Open Services Gateway initiative framework is a
module system and service platform ...
…complete and dynamic component model …
“The Open Services Gateway initiative framework is a
module system and service pla...
… does not exist in standalone Java/VM …
“The Open Services Gateway initiative framework is a
module system and service pl...
OSGi history
o Initially was developed as an embedded platform for the “home
gateway”;
o and make it easier to deploy Java...
The Dream
o Adaptive
B

C

D

E

F

G

H

I

o Flexible

o Contracts
o Robust
o Secure
o Evolution
o Distributed

OSGi Pla...
The Dream
 Adaptive
o Flexible

A

B

C

D

E

F

G

H

I

o Contracts
o Robust
o Secure
o Evolution
o Distributed

OSGi ...
The Dream
 Adaptive
o Flexible

A

B

C

D

E

F

G

H

I

o Contracts
o Robust
o Secure
o Evolution
o Distributed

OSGi ...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

o Contracts
o Robust

D

E

F

G

H

I

o Secure
o Evolution
o Distributed
...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

o Contracts
o Robust

D

E

F

G

H

I

o Secure
o Evolution
o Distributed
...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
o Robust

D

E

F

G

H

I

o Secure
o Evolution
o Distributed
...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
o Robust

D

E

F

G

H

I

o Secure
o Evolution
o Distributed
...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

G

F

H

o Secure
o Evolution
o Distributed

OS...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

G

F

H

o Secure
o Evolution
o Distributed

OS...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

G

F

H

 Secure
o Evolution
o Distributed

OS...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

G

F

H

 Secure
o Evolution
o Distributed

OS...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

F

G

H

I v2.0

 Secure
o Evolution
o Distrib...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

F

G

H

I v2.0

 Secure
 Evolution
o Distrib...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

C

 Contracts
 Robust

D

E

F

G

H

I v2.0

 Secure
 Evolution
o Distrib...
The Dream
 Adaptive
 Flexible

A

Ba

Bb

 Contracts
 Robust

D

E

F

 Secure
 Evolution
 Distributed

G

OSGi Pla...
What is an OSGi application

o Collection of bundles integrated via Service interfaces
o Bundles may be independently deve...
Architecture abstraction
o Application is a set of independent components,
collaborating between each other in a service o...
Architecture abstraction
o Application implement reduced functionality, all
additional features implements as plug-ins

C
...
Architecture abstraction
o or even…

Application

A

B

A

C

B

D

E

OSGi Platform

D

E

27/42
Next level of modularity

Subroutines

(50’s)

×
×
×
×

Focus on “what”, not “how”
Encapsulate the implementation details
...
Next level of modularity
Input (arguments)

function

Output (return)

Then systems grew…

Functions

Subroutines

(50’s)
...
Next level of modularity
Imported Functions

Module

Exported Functions

Then systems grew…

Modules

(70’s)

Functions

S...
Next level of modularity
Imported Members

Type

Exported Members

Then systems grew…

Classes/Objects (80’s)
Modules

(70...
Next level of modularity
Imported Types

Packages

(90’s)

Type

Exported Types

Then and multiplies
…… systems grew…
and ...
Next level of modularity
Small Java App …

OSGi Platform

33/42
Next level of modularity
Bundles
Packages

(00’s)

(90’s)

Classes/Objects (80’s)
Modules

Imported Packages

Bundle
(JAR ...
Bundle
o A Bundle - is a module in OSGi terminology
o What is a bundle?
• Simply a JAR file plus module metadata
• Modules...
OSGi architecture
Application composite
(Bundles)

OSGi Layer

Service

Bundle
Bundle

Bundle

Life Cycle

Bundle

Bundle
...
Life cycle of bundles

INSTALLED

STARTING

RESOLVED

ACTIVE

UNINSTALLED

STOPPING

OSGi Platform

37/42
Services System
o Services are simple POJOs with a published service interface
o Coupling to the framework is isolated to ...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0

Indicates ...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0

Native cod...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
OSGi Bundle Manifest
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Acti...
Declarative Services
o Declarative services provides a minimally intrusive way to:
• Define components that provide and us...
Declarative Services
o Declarative services component metadata:
<?xml version="1.0" encoding="UTF-8"?>
<component name="ex...
OSGi implementations

o Specification it is good, but without implementation it
is a dead stuff
o The most popular open so...
OSGi in Enterprise (as example)
o Why?
• Create modular and reusable software
• Create evolvable software
• Create line of...
Conclusions
o Java needs improved modularity support
• Lagging behind .NET in this area for years
• The OSGi framework pro...
Questions?

OSGi Platform

53/42
Upcoming SlideShare
Loading in …5
×

Osgi platform

658 views

Published on

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

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
658
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Osgi platform

  1. 1. OSGi platform Yuriy Shapovalov EPAM Systems
  2. 2. 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
  3. 3. … 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
  4. 4. … 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
  5. 5. … 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
  6. 6. …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
  7. 7. … does not exist in standalone Java/VM … “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
  8. 8. 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
  9. 9. The Dream o Adaptive B C D E F G H I o Flexible o Contracts o Robust o Secure o Evolution o Distributed OSGi Platform 9/42
  10. 10. The Dream  Adaptive o Flexible A B C D E F G H I o Contracts o Robust o Secure o Evolution o Distributed OSGi Platform 10/42
  11. 11. The Dream  Adaptive o Flexible A B C D E F G H I o Contracts o Robust o Secure o Evolution o Distributed OSGi Platform 11/42
  12. 12. The Dream  Adaptive  Flexible A Ba Bb C o Contracts o Robust D E F G H I o Secure o Evolution o Distributed OSGi Platform 12/42
  13. 13. The Dream  Adaptive  Flexible A Ba Bb C o Contracts o Robust D E F G H I o Secure o Evolution o Distributed OSGi Platform 13/42
  14. 14. The Dream  Adaptive  Flexible A Ba Bb C  Contracts o Robust D E F G H I o Secure o Evolution o Distributed OSGi Platform 14/42
  15. 15. The Dream  Adaptive  Flexible A Ba Bb C  Contracts o Robust D E F G H I o Secure o Evolution o Distributed OSGi Platform 15/42
  16. 16. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E G F H o Secure o Evolution o Distributed OSGi Platform 16/42
  17. 17. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E G F H o Secure o Evolution o Distributed OSGi Platform 17/42
  18. 18. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E G F H  Secure o Evolution o Distributed OSGi Platform 18/42
  19. 19. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E G F H  Secure o Evolution o Distributed OSGi Platform 19/42
  20. 20. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E F G H I v2.0  Secure o Evolution o Distributed OSGi Platform 20/42
  21. 21. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E F G H I v2.0  Secure  Evolution o Distributed OSGi Platform 21/42
  22. 22. The Dream  Adaptive  Flexible A Ba Bb C  Contracts  Robust D E F G H I v2.0  Secure  Evolution o Distributed OSGi Platform 22/42
  23. 23. The Dream  Adaptive  Flexible A Ba Bb  Contracts  Robust D E F  Secure  Evolution  Distributed G OSGi Platform I v2.0 23/42
  24. 24. What is an OSGi application o Collection of bundles integrated via Service interfaces o Bundles may be independently developed and deployed o Bundles and their associated services may appear or disappear at any time o Resulting application follows a Service-Oriented Component Model approach o Combines Ideas from both component and service orientation OSGi Platform 24/42
  25. 25. Architecture abstraction o Application is a set of independent components, collaborating between each other in a service orienting way. Application A C D B E OSGi Platform F 25/42
  26. 26. Architecture abstraction o Application implement reduced functionality, all additional features implements as plug-ins C A Application B D E OSGi Platform F 26/42
  27. 27. Architecture abstraction o or even… Application A B A C B D E OSGi Platform D E 27/42
  28. 28. Next level of modularity Subroutines (50’s) × × × × Focus on “what”, not “how” Encapsulate the implementation details Formalize the input data (arguments) Formalize the output data (return values) OSGi Platform 28/42
  29. 29. Next level of modularity Input (arguments) function Output (return) Then systems grew… Functions Subroutines (50’s) Spaghetti Code OSGi Platform 29/42
  30. 30. Next level of modularity Imported Functions Module Exported Functions Then systems grew… Modules (70’s) Functions Subroutines (50’s) Sharing Proved Hard OSGi Platform 30/42
  31. 31. Next level of modularity Imported Members Type Exported Members Then systems grew… Classes/Objects (80’s) Modules (70’s) Functions Subroutines (50’s) OSGi Platform 31/42
  32. 32. Next level of modularity Imported Types Packages (90’s) Type Exported Types Then and multiplies …… systems grew… and distributed Classes/Objects (80’s) Modules (70’s) Functions Subroutines (50’s) OSGi Platform 32/42
  33. 33. Next level of modularity Small Java App … OSGi Platform 33/42
  34. 34. Next level of modularity Bundles Packages (00’s) (90’s) Classes/Objects (80’s) Modules Imported Packages Bundle (JAR file) Exported Packages (70’s) Functions Subroutines (50’s) OSGi Platform 34/42
  35. 35. 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
  36. 36. OSGi architecture Application composite (Bundles) OSGi Layer Service Bundle Bundle Bundle Life Cycle Bundle Bundle Module Bundle Bundle Security Java VM OS / Hardware OSGi Platform 36/42
  37. 37. Life cycle of bundles INSTALLED STARTING RESOLVED ACTIVE UNINSTALLED STOPPING OSGi Platform 37/42
  38. 38. Services System o Services are simple POJOs with a published service interface o Coupling to the framework is isolated to the Activator and collaborators o Services may bind to other services through their published interfaces o The framework provides a standard Service Factory mechanism track publish Bundle A Bundle B Service Registry track publish Bundle C Service OSGi Platform 38/42
  39. 39. OSGi Bundle Manifest 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 Platform 39/42
  40. 40. OSGi Bundle Manifest Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Indicates semantic Bundle-Activator: org.foo.Activator and syntax 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 Platform 40/42
  41. 41. OSGi Bundle Manifest Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Indicates semantic Globally unique ID and syntax 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 Platform 41/42
  42. 42. OSGi Bundle Manifest 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, Life cycle entry foo.dll; osname=Windows 7; processor=x86 point 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 Platform 42/42
  43. 43. OSGi Bundle Manifest 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 Internal bundle Import-Package:o sgi.service.log; version="[1.0.0,1.1.0)"; class path 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 Platform 43/42
  44. 44. OSGi Bundle Manifest Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Native code Bundle-Activator: org.foo.Activator dependencies 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 Platform 44/42
  45. 45. OSGi Bundle Manifest Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Optional Bundle-ClassPath: .,org/foo/embedded.jar dependency on a package version Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, range 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" OSGi Platform 45/42
  46. 46. OSGi Bundle Manifest Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Provided package with Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 7;arbitrary attribute and processor=x86 excluded classes 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 Platform 46/42
  47. 47. OSGi Bundle Manifest 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, Provided package with foo.dll; osname=Windows 7; processor=x86 dependency on Import-Package:o sgi.service.log; exported package 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 Platform 47/42
  48. 48. Declarative Services o Declarative services provides a minimally intrusive way to: • Define components that provide and use services • Automate dependency resolution and maintenance 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); } } OSGi Platform 48/42
  49. 49. Declarative Services o Declarative services component metadata: <?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 Platform 49/42
  50. 50. 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
  51. 51. 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
  52. 52. 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
  53. 53. Questions? OSGi Platform 53/42

×