SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
Demystifying OSGi
             Colombo Java Meetup
                 24-01-2013



Sameera Jayasoma          Pradeep Fernando
WSO2 Inc.                 WSO2 Inc.
Modular Systems...
Image courtsy of: http://www.thefeltsource.com/Human-Anatomy.html
Down the Memory Lane...
Functions




Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
Modules




Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
Classes/Objects




 Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
Packages




Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
Modularity with Java




Can we build a pure modular system with Java?
Modularity with Java
● Yes we can...
  ○ Various Java libraries and Plugin systems.
  ○ Eclipse IDE plugins
  ○ IntelliJIDEA plugins.

● But...
Modularity with Java
What are the limitations?
 ●   No standard way of building a modular system.
      ○   Class loader based techniques.
 ●   Runtime Vs Compile time difference.
      ○ Flat, single classpath.
 ●   No model for sharing of resource at runtime.
Runtime vs Compile time.


   log4j-2.1.0.jar
                      axis2-kernel-1
                                     .6.0.jar axiom
                                                    -3.3.0.ja   r       jdom.1.0.jar
                                                                                         spring-core.1
                                                                                                          .0.jar




 saxon-8.9.0.ja
                r        poi-3.5.0.jar
                                            wss4j-1.5.11.
                                                         jar         quart-1.1.0.ja
                                                                                     r   woden-1.0.0.ja
                                                                                                           r



cindy-5.7.0.ja
              r      rampart-2.3.0
                                  .ja  r   derby-10.3.0.ja
                                                            r       bcel-5.2.0.jar
                                                                                         jaxb-2.2.5.jar




                                           Java application. Compile time view
Runtime vs Compile time




                      log4j-2.1.0.jar
                                                 wss4j-1.5.11.jar
                     axis2-kernel-1.6.0
                                            .jar quart-1.1.0.ja
                                                                r
                     axiom-3.3.0.jar
                                                 woden-1.0.0.jar
                     jdom.1.0.jar
                                                 cindy-5.7.0.jar
                    spring-core.1.0.ja
                                        r       rampart-2.3.0.jar
                    saxon-8.9.0.jar
                                                derby-10.3.0.jar
Single linear       poi-3.5.0.jar
                                                bcel-5.2.0.jar
 classpath.         jaxb-2.2.5.jar




                              Runtime classloading architecture.
Multiple Library Versions




                     log4j-2.1.0.jar
                                                    wss4j-1.5.11.jar
                     axis2-kernel-1.6.0
                                           .jar    quart-1.1.0.jar
                     axiom-3.3.0.jar
                                                   woden-1.0.0.jar
                     jdom.1.0.jar
                                                  cindy-5.7.0.jar
                    spring-core.1.0.ja
                                       r          rampart-2.3.0.jar
                    saxon-8.9.0.jar
                                                  derby-10.3.0.jar
                    poi-3.5.0.jar
Single linear                                     bcel-5.2.0.jar
                    jaxb-2.2.5.jar
 classpath.                                       log4j-3.0.0.jar




                                              Can we achieve this in Java?
Tight Coupling among modules




               Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
What Next?
● How do we overcome those limitations in Java?
● We were discussing functions, module, objects and
  packages.
● What next???
What Next???
● How about an abstraction where you can work at the
   package level as opposed to class/object level?
   ○ Importing packages.
   ○ Exporting packages.
   ○ A way to have private packages.
● Can we achieve the limitations that we discussed in
   Java from this model?
Next Level of Modularity


?     What next?




            Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
Next Level of Modularity...




            Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
Next Level of Modularity...
● Separate class loader per module.
   ○ creating a class-space per module.
   ○ delegate class loading to other modules when necessary.
● Solves the single class path problem.
● Now you have a class loader network formed from
  classloader delegation.
● This network is formed with import/export package
  restrictions.
● Now we have modularity at runtime as well as compile
  time.
Next Level of Modularity...




 Classloader
   Network.
Delegate each
   other for
classloading
  requests.




                           Java application. Runtime view
What is OSGi?


 "The OSGi 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
What is OSGi?
● Widely accepted specification which introduces a
  standard way of building dynamic, modular systems
  with Java.
● OSGi framework implementations.(Open source)
  ○ Eclipse Equinox.
  ○ Apache Felix.
  ○ Knopflerfish.
OSGi Layered Model




     Image courtsy of: http://www.osgi.org/Technology/WhatIsOSGi
OSGi Layered Model
● Bundles
  ○ Bundles are the OSGi components made by the developers.

● Services
  ○ The services layer connects bundles in a dynamic way by offering a
        publish-find-bind model for plain old Java objects.


● Life-Cycle
  ○ The API to install, start, stop, update, and uninstall bundles.
OSGi Layered Model
● Modules
  ○ The layer that defines how a bundle can import and export code.

● Security
  ○ The layer that handles the security aspects.

● Execution Environment
  ○ Defines what methods and classes are available in a specific platform.
Bundles
● Bundle is the unit of modularization in OSGi

● OSGi based application can be considered as a
  collection of Bundle

● Bundles can share packages with other bundles and
  hide packages from otherbundles

● How does a bundle differs from a normal jar file ?
Bundles...




How does a bundle differs from a normal jar file?
MANIFEST.MF

Bundle-ManifestVersion : 2
Bundle-Name: My First OSGi Bundle
Bundle-SymbolicName: HelloWorldBundle
Bundle-Version: 1.0.0
Export-Package: org.helloworld
Import-package: org.osgi.framework



                                               Bundle

                                                  Exported Package

                                          Imported Package

                                           Private Package
Bundle States




Image courtsy of: http://static.springsource.org/s2-dmserver/2.0.
x/getting-started/html/ch01.html
Demo
Dynamism




Modularity achieved.. but what about dynamism?
Dynamism...
● The moment your instantiate a new object tight coupling
  among modules occurs.


● What if I want to update the platform or part of the
  platform during runtime.


● What we need is a ...
OSGi Services
● In-VM SOA model.
● OSGi Service registry.
● Bundles can publish/lookup services using interface
  names
OSGi Services

public void start(BundleContext bc) {
   Hashtable props = new Hashtable();
   props.put("language", "en");
   //Registering the HelloWorld service
   bc.registerService(HelloService.class.
   getName(),
   new HelloServiceImpl(), props);
}
Acquiring Services

public void start(BundleContext bc) {
    //Get the service reference for HelloService
    serviceRef = bc.getServiceReference(HelloService.class.
    getName());
    //service reference can be null, if the service is not
    registered.
    if(serviceRef != null) {
        helloService = (HelloService)bc.getService(serviceRef);
    } else {
        System.err.println("service reference not found.");
    }
}
Listeners
● Bundle Listeners
● Service Listeners
● Service Trackers
● Declarative Services
Declarative Services

<?xml version="1.0" encoding="UTF-8"?>
<component name="helloservice.listen">
<implementation class="org.sample.HelloComponent"/>
<reference name="HS"
    interface="org.sample.HelloService"
    cardinality="0..n"
    policy="dynamic"
    target="(language=en)"
    bind="setHelloService"
    unbind="setHelloService" />
</component>
Demo
Questions
Thank you.

Contenu connexe

En vedette

Apache Stratos Hangout VI
Apache Stratos Hangout VIApache Stratos Hangout VI
Apache Stratos Hangout VIpradeepfn
 
Article research
Article researchArticle research
Article researchorlabraiden
 
khalid saeed profile
khalid saeed profilekhalid saeed profile
khalid saeed profilekashiflucknow
 
We don’t look like that!
We don’t look like that!We don’t look like that!
We don’t look like that!skmcdaniel88
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 

En vedette (6)

Smabhsind0304e
Smabhsind0304eSmabhsind0304e
Smabhsind0304e
 
Apache Stratos Hangout VI
Apache Stratos Hangout VIApache Stratos Hangout VI
Apache Stratos Hangout VI
 
Article research
Article researchArticle research
Article research
 
khalid saeed profile
khalid saeed profilekhalid saeed profile
khalid saeed profile
 
We don’t look like that!
We don’t look like that!We don’t look like that!
We don’t look like that!
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 

Similaire à Demistifying OSGi

Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta ThoughtWorks
 
GlassFish can support multiple Ruby frameworks ... really ?
GlassFish can support multiple Ruby frameworks ... really ?GlassFish can support multiple Ruby frameworks ... really ?
GlassFish can support multiple Ruby frameworks ... really ?Arun Gupta
 
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
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011njbartlett
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)David Bosschaert
 
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
 
OSGi Training for Carbon Developers
OSGi Training for Carbon DevelopersOSGi Training for Carbon Developers
OSGi Training for Carbon DevelopersAruna Karunarathna
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Martin Toshev
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Martin Toshev
 
Migrating to java 9 modules
Migrating to java 9 modulesMigrating to java 9 modules
Migrating to java 9 modulesPaul Bakker
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...mfrancis
 
Java 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the GalleryJava 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the Gallerynjbartlett
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous TaskErin Dees
 
Dynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishDynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishIndicThreads
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby.toster
 

Similaire à Demistifying OSGi (20)

Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta
 
GlassFish can support multiple Ruby frameworks ... really ?
GlassFish can support multiple Ruby frameworks ... really ?GlassFish can support multiple Ruby frameworks ... really ?
GlassFish can support multiple Ruby frameworks ... really ?
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
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
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)
 
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 -
 
OSGi Training for Carbon Developers
OSGi Training for Carbon DevelopersOSGi Training for Carbon Developers
OSGi Training for Carbon Developers
 
Osgi Sun 20080820
Osgi Sun 20080820Osgi Sun 20080820
Osgi Sun 20080820
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 
JavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI MigratJavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI Migrat
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Modular Java
Modular JavaModular Java
Modular Java
 
Migrating to java 9 modules
Migrating to java 9 modulesMigrating to java 9 modules
Migrating to java 9 modules
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
 
Java 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the GalleryJava 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the Gallery
 
OSGI Modularity
OSGI ModularityOSGI Modularity
OSGI Modularity
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous Task
 
Dynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFishDynamic Languages & Web Frameworks in GlassFish
Dynamic Languages & Web Frameworks in GlassFish
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 

Dernier

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Dernier (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Demistifying OSGi

  • 1. Demystifying OSGi Colombo Java Meetup 24-01-2013 Sameera Jayasoma Pradeep Fernando WSO2 Inc. WSO2 Inc.
  • 3. Image courtsy of: http://www.thefeltsource.com/Human-Anatomy.html
  • 4. Down the Memory Lane...
  • 5. Functions Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 6. Modules Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 7. Classes/Objects Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 8. Packages Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 9. Modularity with Java Can we build a pure modular system with Java?
  • 10. Modularity with Java ● Yes we can... ○ Various Java libraries and Plugin systems. ○ Eclipse IDE plugins ○ IntelliJIDEA plugins. ● But...
  • 11. Modularity with Java What are the limitations? ● No standard way of building a modular system. ○ Class loader based techniques. ● Runtime Vs Compile time difference. ○ Flat, single classpath. ● No model for sharing of resource at runtime.
  • 12. Runtime vs Compile time. log4j-2.1.0.jar axis2-kernel-1 .6.0.jar axiom -3.3.0.ja r jdom.1.0.jar spring-core.1 .0.jar saxon-8.9.0.ja r poi-3.5.0.jar wss4j-1.5.11. jar quart-1.1.0.ja r woden-1.0.0.ja r cindy-5.7.0.ja r rampart-2.3.0 .ja r derby-10.3.0.ja r bcel-5.2.0.jar jaxb-2.2.5.jar Java application. Compile time view
  • 13. Runtime vs Compile time log4j-2.1.0.jar wss4j-1.5.11.jar axis2-kernel-1.6.0 .jar quart-1.1.0.ja r axiom-3.3.0.jar woden-1.0.0.jar jdom.1.0.jar cindy-5.7.0.jar spring-core.1.0.ja r rampart-2.3.0.jar saxon-8.9.0.jar derby-10.3.0.jar Single linear poi-3.5.0.jar bcel-5.2.0.jar classpath. jaxb-2.2.5.jar Runtime classloading architecture.
  • 14. Multiple Library Versions log4j-2.1.0.jar wss4j-1.5.11.jar axis2-kernel-1.6.0 .jar quart-1.1.0.jar axiom-3.3.0.jar woden-1.0.0.jar jdom.1.0.jar cindy-5.7.0.jar spring-core.1.0.ja r rampart-2.3.0.jar saxon-8.9.0.jar derby-10.3.0.jar poi-3.5.0.jar Single linear bcel-5.2.0.jar jaxb-2.2.5.jar classpath. log4j-3.0.0.jar Can we achieve this in Java?
  • 15. Tight Coupling among modules Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 16. What Next? ● How do we overcome those limitations in Java? ● We were discussing functions, module, objects and packages. ● What next???
  • 17. What Next??? ● How about an abstraction where you can work at the package level as opposed to class/object level? ○ Importing packages. ○ Exporting packages. ○ A way to have private packages. ● Can we achieve the limitations that we discussed in Java from this model?
  • 18. Next Level of Modularity ? What next? Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 19. Next Level of Modularity... Image courtsy of: http://www.slideshare.net/bjhargrave/why-osgi
  • 20. Next Level of Modularity... ● Separate class loader per module. ○ creating a class-space per module. ○ delegate class loading to other modules when necessary. ● Solves the single class path problem. ● Now you have a class loader network formed from classloader delegation. ● This network is formed with import/export package restrictions. ● Now we have modularity at runtime as well as compile time.
  • 21. Next Level of Modularity... Classloader Network. Delegate each other for classloading requests. Java application. Runtime view
  • 22.
  • 23. What is OSGi? "The OSGi 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
  • 24. What is OSGi? ● Widely accepted specification which introduces a standard way of building dynamic, modular systems with Java. ● OSGi framework implementations.(Open source) ○ Eclipse Equinox. ○ Apache Felix. ○ Knopflerfish.
  • 25. OSGi Layered Model Image courtsy of: http://www.osgi.org/Technology/WhatIsOSGi
  • 26. OSGi Layered Model ● Bundles ○ Bundles are the OSGi components made by the developers. ● Services ○ The services layer connects bundles in a dynamic way by offering a publish-find-bind model for plain old Java objects. ● Life-Cycle ○ The API to install, start, stop, update, and uninstall bundles.
  • 27. OSGi Layered Model ● Modules ○ The layer that defines how a bundle can import and export code. ● Security ○ The layer that handles the security aspects. ● Execution Environment ○ Defines what methods and classes are available in a specific platform.
  • 28. Bundles ● Bundle is the unit of modularization in OSGi ● OSGi based application can be considered as a collection of Bundle ● Bundles can share packages with other bundles and hide packages from otherbundles ● How does a bundle differs from a normal jar file ?
  • 29. Bundles... How does a bundle differs from a normal jar file?
  • 30. MANIFEST.MF Bundle-ManifestVersion : 2 Bundle-Name: My First OSGi Bundle Bundle-SymbolicName: HelloWorldBundle Bundle-Version: 1.0.0 Export-Package: org.helloworld Import-package: org.osgi.framework Bundle Exported Package Imported Package Private Package
  • 31. Bundle States Image courtsy of: http://static.springsource.org/s2-dmserver/2.0. x/getting-started/html/ch01.html
  • 32. Demo
  • 33. Dynamism Modularity achieved.. but what about dynamism?
  • 34. Dynamism... ● The moment your instantiate a new object tight coupling among modules occurs. ● What if I want to update the platform or part of the platform during runtime. ● What we need is a ...
  • 35. OSGi Services ● In-VM SOA model. ● OSGi Service registry. ● Bundles can publish/lookup services using interface names
  • 36. OSGi Services public void start(BundleContext bc) { Hashtable props = new Hashtable(); props.put("language", "en"); //Registering the HelloWorld service bc.registerService(HelloService.class. getName(), new HelloServiceImpl(), props); }
  • 37. Acquiring Services public void start(BundleContext bc) { //Get the service reference for HelloService serviceRef = bc.getServiceReference(HelloService.class. getName()); //service reference can be null, if the service is not registered. if(serviceRef != null) { helloService = (HelloService)bc.getService(serviceRef); } else { System.err.println("service reference not found."); } }
  • 38. Listeners ● Bundle Listeners ● Service Listeners ● Service Trackers ● Declarative Services
  • 39. Declarative Services <?xml version="1.0" encoding="UTF-8"?> <component name="helloservice.listen"> <implementation class="org.sample.HelloComponent"/> <reference name="HS" interface="org.sample.HelloService" cardinality="0..n" policy="dynamic" target="(language=en)" bind="setHelloService" unbind="setHelloService" /> </component>
  • 40. Demo