SlideShare una empresa de Scribd logo
1 de 14
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

Más contenido relacionado

Similar a First Touch with OSGi

Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
njbartlett
 
OSGi User Forum US DC Metro
OSGi User Forum US DC MetroOSGi User Forum US DC Metro
OSGi User Forum US DC Metro
pjhInovex
 
OSGi user forum dc metro v1
OSGi user forum dc metro v1OSGi user forum dc metro v1
OSGi user forum dc metro v1
pjhInovex
 
OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2
pjhInovex
 
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
IndicThreads
 

Similar a First Touch with OSGi (20)

OSGi & Blueprint
OSGi & BlueprintOSGi & Blueprint
OSGi & Blueprint
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Osgi Sun 20080820
Osgi Sun 20080820Osgi Sun 20080820
Osgi Sun 20080820
 
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil BartlettJava Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 India
 
Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGi
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
 
New Modularity Features of the OSGi R4 Service Platform - Richard Hall, Ph.D....
New Modularity Features of the OSGi R4 Service Platform - Richard Hall, Ph.D....New Modularity Features of the OSGi R4 Service Platform - Richard Hall, Ph.D....
New Modularity Features of the OSGi R4 Service Platform - Richard Hall, Ph.D....
 
OSGi User Forum US DC Metro
OSGi User Forum US DC MetroOSGi User Forum US DC Metro
OSGi User Forum US DC Metro
 
OSGi user forum dc metro v1
OSGi user forum dc metro v1OSGi user forum dc metro v1
OSGi user forum dc metro v1
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
 
OSGi and Java 9+
OSGi and Java 9+OSGi and Java 9+
OSGi and Java 9+
 
GlassFish OSGi - Java2days 2010
GlassFish OSGi - Java2days 2010GlassFish OSGi - Java2days 2010
GlassFish OSGi - Java2days 2010
 
OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2OSGi in Action Chapter 1 and 2
OSGi in Action Chapter 1 and 2
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
 
Osgi platform
Osgi platformOsgi platform
Osgi platform
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

First Touch with OSGi

  • 1. First Touch with OSGi Owen Ou @JingwenOwenOu http://owenou.com
  • 2. 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
  • 3. 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
  • 4. What’s OSGi? • OSGi is a dynamic module system for Java • It talks about bundles instead of JARs • Bundle = identity & dependency info + JAR
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. OSGi service • importing and exporting of packages are static contracts • services are used to facilitate dynamic collaboration
  • 10. OSGi implementations • Equinox, Felix, Knopflerfish, Snippets • Equinox: OSGi standard + extension/ extension point + fragment • Usages: Eclipse, Spring DM Server, NASA, embedded system
  • 11. Benefits of OSGi • Example: a hello world example
  • 13. 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?
  • 14. 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

Notas del editor

  1. Why OSGi? Because of Java’s limitations on modularity. 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 But...somehow JARs are just simply a delivery mechanism with no runtime semantics. 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! 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.
  2. 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’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. To summarize... The consequence is...
  3. OSGi (Open Service Gateway initiative) is a dynamic module system for Java It adds a few key elements, in particular, it talks about bundles instead of JARs 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.
  4. Now we need to slightly modify the abstraction hierarchy. Under the OSGi framework, bundles replace JARs as modules.
  5. So what exactly is a bundle? First of all, it has identity information, it requires to have an unique id and version combination And it also has dependency information, it requires that packages containing... The producers tell the customers what they have, and the customers ask for what they need from the producers. Fair enough.
  6. with these visibility... each bundle has its... 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.
  7. Another key concept that OSGi introduces is service. 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. The latest OSGi implementation also supports dynamically registering and injecting these services.
  8. 1. nasa uses it to control space missions