SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
Delving deeper into Modularity
Pubudu Dissanayake
Recap
Agenda
● OSGI Classloading
● Processing Import packages and Export Packages
● Processing OSGI core classes and Java core Classes
● Optional Imports and Dynamic Imports
● Requiring bundles
● Fragment bundles
● Extension Bundles
OSGi Classloading
● Bundle-SymbolicName
● Bundle-Version
● Import-Package
● Export-Package
● Require-Bundle
● Fragment Bundle
OSGI Classloading
Class Loader Delegation model
● The parent class loader (normally java.* packages from the boot class path)
● Imported packages
● Required bundles
● The bundle's class path (private packages)
● Attached fragments
A class space for a given bundle can contain classes from
Class-search Order
OSGi framework to perform sophisticated searching on behalf of bundles for
their contained and needed classes
● If the class is from a package starting with java, the parent class loader is asked for the class. If the
class is found, it’s used. If there is no such class, the search ends with an exception.
● If the class is from a package imported by the bundle, the framework asks the exporting bundle for
the class. If the class is found, it’s used. If there is no such class, the search ends with an exception.
● The bundle class path is searched for the class. If it’s found, it’s used. If there is no such class, the
search ends with an exception.
The classloader hierarchy
Bundle Registry
● The framework maintains a “bundle registry” consisting of a Bundle instance
representing each loaded jarfile.
● The bundle instance in turn contains a custom Classloader instance which is
used to load classes from its jar file.
● The bundle instance holds information extracted from the MANIFEST.MF file
within the jar file, in particular the bundle version and list of imported and
exported packages
Processing Import-Package declarations
Import-Package: org.osgi.framework; version="1.3.0"
● Locates a suitably matching entry exported by a bundle in the
bundle registry
○ If this fails, then processing stops and the bundle is marked
as “installed but not resolved”
● Adds an entry to a local map of (packagename=>classloader)
If all imports can be resolved,
then the classloader marks itself as being in RESOLVED state
Processing Export-Package declarations
Unlike “import-package” declarations, these are more passive; they
simply tell other bundles that they can use this bundle’s classloader as a
source of the specified package.
Export-Package: org.foo.shape; org.foo.other; version="2.0.0"
Resolving OSGi core classes
● The OSGi core jar file is on the normal classpath
And so can see both the JDK and potentially any other
jar files on the normal classpath.
When an API from this jar file is used to create an OSGi
“environment”, it automatically creates a dummy “system” bundle
whose classloader can see the OSGi standard classes.
Resolving classes from the Java standard libraries
For other packages that are in the $JRE_HOME/lib/*.jar files
Bundles can then use normal Import-Package statements which causes
lookups of such classes to be delegated to the OSGi system bundle’s
classloader which is able to resolve them.
● The OSGi startup code simply makes them “exports” of the
OSGi system bundle.
Loosening your imports
To import a package, you must know the name of a package in advance,
but this isn’t always possible !!
● Optional Imports
● Dynamic Imports
Optional Imports
Dynamic Imports
Optional Imports Vs Dynamic Imports
● Optional/dynamic imports never cause a bundle to be unable to resolve
● Your bundle code must be prepared to catch ClassNotFoundException
s for the optionally/dynamically imported packages.
Similarities
Differences
● The framework attempts to resolve an Optional import package once
when the associated bundle is resolved. Dynamic import package, the
framework attempts to resolve it at execution time
● Fwk trying to resolve the Dynamic-imports each time it executes
Require-bundle
The OSGi specification also supports a module-level dependency concept
called a Require-Bundle
Require-Bundle is just a brittle way to import packages,because it specifies who instead of what.
Bundle Fragments
Fragment-Host: org.foo.hostbundle; bundle-version="[1.0.0,1.1.0)"
● Fragments are not bundles themselves, but instead “additional resources” for
the bundle specified by {bundle-name}
● The fragment is “merged into” the specified bundle at runtime.
● A host bundle is technically usable without fragments, but the fragments aren’t
usable without a host
● Fragment bundles must be installed before their host bundles.
Extension Bundles
● Extension bundles can deliver optional parts of the Framework
implementation or provide functionality that must reside on the boot class path.
● These packages cannot be provided by the normal import/export mechanisms
● Framework extensions are necessary to provide implementation aspects of the
Framework.
Fragment-Host: com.acme.impl.framework; extension:=framework
Specific Framework implementation.
Boot class path extension bundle
Fragment-Host: system.bundle; extension:=bootclasspath
Thank you :)
References
● http://moi.vonos.net/java/osgi-classloaders/
● http://blog.osgi.org/2011/05/what-you-should-know-about-class.html
● OSGi in Action: Creating Modular Applications in Java by: Richard Hall,
Karl Pauls, Stuart McCulloch, David Savage (01 May 2011)

Contenu connexe

Similaire à Delving Deeper Into OSGI Modularity

Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 
7.Packages and Interfaces(MB).ppt .
7.Packages and Interfaces(MB).ppt             .7.Packages and Interfaces(MB).ppt             .
7.Packages and Interfaces(MB).ppt .happycocoman
 
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
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The FactLuciano Resende
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyRaymond Feng
 
Deep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerDeep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerAruna Karunarathna
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutesSerge Huber
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access ModifiersOOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access ModifiersRatnaJava
 
Lecture-12 Java Packages and GUI Basics.ppt
Lecture-12 Java Packages and GUI Basics.pptLecture-12 Java Packages and GUI Basics.ppt
Lecture-12 Java Packages and GUI Basics.pptlirogal422
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers Hitesh-Java
 

Similaire à Delving Deeper Into OSGI Modularity (20)

Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
7.Packages and Interfaces(MB).ppt .
7.Packages and Interfaces(MB).ppt             .7.Packages and Interfaces(MB).ppt             .
7.Packages and Interfaces(MB).ppt .
 
Packages
PackagesPackages
Packages
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
Packages
PackagesPackages
Packages
 
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 -
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache Tuscany
 
Deep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerDeep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle Layer
 
Package in Java
Package in JavaPackage in Java
Package in Java
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
packages.ppt
packages.pptpackages.ppt
packages.ppt
 
javapackage
javapackagejavapackage
javapackage
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access ModifiersOOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers
 
Chapter 1 :
Chapter 1 : Chapter 1 :
Chapter 1 :
 
Lecture-12 Java Packages and GUI Basics.ppt
Lecture-12 Java Packages and GUI Basics.pptLecture-12 Java Packages and GUI Basics.ppt
Lecture-12 Java Packages and GUI Basics.ppt
 
OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers OOPs with Java - Packaging and Access Modifiers
OOPs with Java - Packaging and Access Modifiers
 

Dernier

WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 

Dernier (20)

WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 

Delving Deeper Into OSGI Modularity

  • 1. Delving deeper into Modularity Pubudu Dissanayake
  • 3. Agenda ● OSGI Classloading ● Processing Import packages and Export Packages ● Processing OSGI core classes and Java core Classes ● Optional Imports and Dynamic Imports ● Requiring bundles ● Fragment bundles ● Extension Bundles
  • 4. OSGi Classloading ● Bundle-SymbolicName ● Bundle-Version ● Import-Package ● Export-Package ● Require-Bundle ● Fragment Bundle
  • 6. ● The parent class loader (normally java.* packages from the boot class path) ● Imported packages ● Required bundles ● The bundle's class path (private packages) ● Attached fragments A class space for a given bundle can contain classes from
  • 7. Class-search Order OSGi framework to perform sophisticated searching on behalf of bundles for their contained and needed classes ● If the class is from a package starting with java, the parent class loader is asked for the class. If the class is found, it’s used. If there is no such class, the search ends with an exception. ● If the class is from a package imported by the bundle, the framework asks the exporting bundle for the class. If the class is found, it’s used. If there is no such class, the search ends with an exception. ● The bundle class path is searched for the class. If it’s found, it’s used. If there is no such class, the search ends with an exception.
  • 9. Bundle Registry ● The framework maintains a “bundle registry” consisting of a Bundle instance representing each loaded jarfile. ● The bundle instance in turn contains a custom Classloader instance which is used to load classes from its jar file. ● The bundle instance holds information extracted from the MANIFEST.MF file within the jar file, in particular the bundle version and list of imported and exported packages
  • 10. Processing Import-Package declarations Import-Package: org.osgi.framework; version="1.3.0" ● Locates a suitably matching entry exported by a bundle in the bundle registry ○ If this fails, then processing stops and the bundle is marked as “installed but not resolved” ● Adds an entry to a local map of (packagename=>classloader) If all imports can be resolved, then the classloader marks itself as being in RESOLVED state
  • 11. Processing Export-Package declarations Unlike “import-package” declarations, these are more passive; they simply tell other bundles that they can use this bundle’s classloader as a source of the specified package. Export-Package: org.foo.shape; org.foo.other; version="2.0.0"
  • 12. Resolving OSGi core classes ● The OSGi core jar file is on the normal classpath And so can see both the JDK and potentially any other jar files on the normal classpath. When an API from this jar file is used to create an OSGi “environment”, it automatically creates a dummy “system” bundle whose classloader can see the OSGi standard classes.
  • 13. Resolving classes from the Java standard libraries For other packages that are in the $JRE_HOME/lib/*.jar files Bundles can then use normal Import-Package statements which causes lookups of such classes to be delegated to the OSGi system bundle’s classloader which is able to resolve them. ● The OSGi startup code simply makes them “exports” of the OSGi system bundle.
  • 14. Loosening your imports To import a package, you must know the name of a package in advance, but this isn’t always possible !! ● Optional Imports ● Dynamic Imports
  • 17. Optional Imports Vs Dynamic Imports ● Optional/dynamic imports never cause a bundle to be unable to resolve ● Your bundle code must be prepared to catch ClassNotFoundException s for the optionally/dynamically imported packages. Similarities Differences ● The framework attempts to resolve an Optional import package once when the associated bundle is resolved. Dynamic import package, the framework attempts to resolve it at execution time ● Fwk trying to resolve the Dynamic-imports each time it executes
  • 18. Require-bundle The OSGi specification also supports a module-level dependency concept called a Require-Bundle Require-Bundle is just a brittle way to import packages,because it specifies who instead of what.
  • 19.
  • 20. Bundle Fragments Fragment-Host: org.foo.hostbundle; bundle-version="[1.0.0,1.1.0)" ● Fragments are not bundles themselves, but instead “additional resources” for the bundle specified by {bundle-name} ● The fragment is “merged into” the specified bundle at runtime. ● A host bundle is technically usable without fragments, but the fragments aren’t usable without a host ● Fragment bundles must be installed before their host bundles.
  • 21. Extension Bundles ● Extension bundles can deliver optional parts of the Framework implementation or provide functionality that must reside on the boot class path. ● These packages cannot be provided by the normal import/export mechanisms ● Framework extensions are necessary to provide implementation aspects of the Framework. Fragment-Host: com.acme.impl.framework; extension:=framework Specific Framework implementation. Boot class path extension bundle Fragment-Host: system.bundle; extension:=bootclasspath
  • 23. References ● http://moi.vonos.net/java/osgi-classloaders/ ● http://blog.osgi.org/2011/05/what-you-should-know-about-class.html ● OSGi in Action: Creating Modular Applications in Java by: Richard Hall, Karl Pauls, Stuart McCulloch, David Savage (01 May 2011)