SlideShare uma empresa 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

Mais conteúdo relacionado

Semelhante a First Touch with OSGi

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 -Jeffrey Groneberg
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011njbartlett
 
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 BartlettJAX London
 
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 IndiaArun Gupta
 
Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGiIlya Rybak
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)David Bosschaert
 
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 DevelopmentSanjeeb Sahoo
 
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....mfrancis
 
OSGi User Forum US DC Metro
OSGi User Forum US DC MetroOSGi User Forum US DC Metro
OSGi User Forum US DC MetropjhInovex
 
OSGi user forum dc metro v1
OSGi user forum dc metro v1OSGi user forum dc metro v1
OSGi user forum dc metro v1pjhInovex
 
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)mfrancis
 
OSGi and Java 9+
OSGi and Java 9+OSGi and Java 9+
OSGi and Java 9+bjhargrave
 
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 2pjhInovex
 
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
 

Semelhante 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
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
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
 
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

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Último (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

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 do 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