First Touch with OSGi
Upcoming SlideShare
Loading in...5
×
 

First Touch with OSGi

on

  • 1,760 views

About basic OSGi concepts: why OSGI? what is OSGi? How it benefits us?

About basic OSGi concepts: why OSGI? what is OSGi? How it benefits us?

Statistics

Views

Total Views
1,760
Views on SlideShare
1,737
Embed Views
23

Actions

Likes
1
Downloads
40
Comments
0

3 Embeds 23

http://www.linkedin.com 10
http://www.slideshare.net 8
https://www.linkedin.com 5

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • Why OSGi? Because of Java&#x2019;s limitations on modularity. <br /> Nowadays an application is normally constructed by multiple modules. Modules are appeared as JAR files in Java. Here is an abstraction hierarchy of Java: application is composed of JARs; JARs are composed of packages; packages are composed of types; and types are composed of methods <br /> But...somehow JARs are just simply a delivery mechanism with no runtime semantics. <br /> First of all, why are JARs just a delivery mechanism? Probably you already can tell from the abstraction hierarchy: methods, types and packages all have visibility controls, but there is no such thing in JARs! At the application level, all JARs are public! <br /> As we all know, visibility control is important in decoupling dependencies. Think about information hiding. Since there is no such thing in JAR files, they are easily coupled to each other. <br />
  • The 2nd problem with JAR files is, it simply go on a flat classpath and it fight for position on the classpath. The classpath pays no attention to code versions, it simply adopts a first-come first-serve algorithm, whichever comes first wins! Let&#x2019;s take a look at the picture, classes are merged at runtime. This is the so-called class overlaying. It makes supporting different versions of classes at runtime impossible. Just to remind you, maven is kind of special, if two JARs have the same group id and artifact id, the one with the higher version always wins. <br /> To summarize... <br /> The consequence is... <br />
  • OSGi (Open Service Gateway initiative) is a dynamic module system for Java <br /> It adds a few key elements, in particular, it talks about bundles instead of JARs <br /> A bundle is a self-describing JAR. It adds identity and dependency information on top of the JAR file. This simple idea has two effects, producers and consumers both have an opportunity to express their side of the contract, and the runtime has the information it needs to enforce these expectations. <br />
  • Now we need to slightly modify the abstraction hierarchy. Under the OSGi framework, bundles replace JARs as modules. <br />
  • So what exactly is a bundle? <br /> First of all, it has identity information, it requires to have an unique id and version combination <br /> And it also has dependency information, it requires that packages containing... <br /> The producers tell the customers what they have, and the customers ask for what they need from the producers. Fair enough. <br />
  • with these visibility... <br /> each bundle has its... <br /> Now the Spring problem is fixed, right? The Symantec code can has its own Spring dependency without being affected by the Spring from the elasticpath OFTB code. <br />
  • Another key concept that OSGi introduces is service. <br /> while importing and exporting of packages are only static contracts, OSGi uses service to facilitate dynamic collaboration. A service is simply an object that implements a contract, that is registered with the OSGi service registry, and with its package visible to the world. The consumer bundle only need to query the service implementation from the service registry. We will have an example in the end. <br /> The latest OSGi implementation also supports dynamically registering and injecting these services. <br />
  • <br />
  • 1. nasa uses it to control space missions <br />
  • <br />
  • <br />
  • <br />
  • <br />

First Touch with OSGi First Touch with OSGi Presentation Transcript

  • First Touch with OSGi Owen Ou @JingwenOwenOu http://owenou.com
  • Why OSGi? • Java’s limitations on modularity • Application > JAR > Package > Type > Method • JARs are simply a delivery mechanism with no runtime semantics • JARs have no visibility control
  • Why OSGi? (cont.) • JARs fight for position on the classpath, FCFS algorithm, e.g., class overlay, maven is higher versioned JAR wins • To summarize, Java has no support for defining or enforcing dependencies • The consequence is tightly coupled JARs with multidirectional and even cyclical dependencies
  • What’s OSGi? • OSGi is a dynamic module system for Java • It talks about bundles instead of JARs • Bundle = identity & dependency info + JAR
  • What’s OSGi? (cont.) • OSGi is a dynamic module system for Java • It talks about bundles instead of JARs • Bundle = identity & dependency info + JAR Application > Bundle > Package > Type > Method
  • OSGi bundle • Identity: unique id + version combination • Dependency: packages containing API must be explicitly export; bundles including code that uses this API must have a matching import
  • OSGi bundle (cont.) • with these visibility constraints, a strong basis of loosely coupled module system is achieved • each bundle has its own class loader, making it possible for two bundles to depend on the same bundle with different versions
  • OSGi service • importing and exporting of packages are static contracts • services are used to facilitate dynamic collaboration
  • OSGi lifecycle
  • OSGi implementations • Equinox, Felix, Knopflerfish, Snippets • Equinox: OSGi standard + extension/ extension point + fragment • Usages: Eclipse, Spring DM Server, NASA, embedded system
  • Benefits of OSGi • Example: a hello world example
  • Questions?
  • Discussions • Why can OSGi decouple dependencies? • What’s the difference between OSGi’s dependency control and Maven’s dependency management? Can they replace each other? Or can they combine together to be a powerful match? • What’s the difference between OSGi’s service injection and Spring’s dependency injection? Can they replace each other? Or can they combine together to be a powerful match?
  • Reference • OSGi and Equinox: Creating Highly Modular Java™ Systems • Modular Java: Creating Flexible Applications with Osgi and Spring • Getting Started with OSGi: Declarative Services and Dependencies