SlideShare a Scribd company logo
1 of 42
Download to read offline
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.

More Related Content

Similar to Demistifying OSGi - Colombo Java Meetup 2013

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
 
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
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 

Similar to Demistifying OSGi - Colombo Java Meetup 2013 (20)

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
 
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
 
Java On Speed
Java On SpeedJava On Speed
Java On Speed
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 

More from Sameera Jayasoma

Building Multi-tenant SaaS Applications using WSO2 Private PaaS
Building Multi-tenant SaaS Applications using WSO2 Private PaaSBuilding Multi-tenant SaaS Applications using WSO2 Private PaaS
Building Multi-tenant SaaS Applications using WSO2 Private PaaSSameera Jayasoma
 
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014Sameera Jayasoma
 
Using the Carbon Architecture to Build a Fit-for-Purpose Platform
Using the Carbon Architecture to Build a Fit-for-Purpose PlatformUsing the Carbon Architecture to Build a Fit-for-Purpose Platform
Using the Carbon Architecture to Build a Fit-for-Purpose PlatformSameera Jayasoma
 
WSO2 Carbon Kernel Design and Architecture
WSO2 Carbon Kernel Design and ArchitectureWSO2 Carbon Kernel Design and Architecture
WSO2 Carbon Kernel Design and ArchitectureSameera Jayasoma
 

More from Sameera Jayasoma (6)

Carbon 5 : A Preview
Carbon 5 : A PreviewCarbon 5 : A Preview
Carbon 5 : A Preview
 
Carbon and OSGi Deep Dive
Carbon and OSGi Deep DiveCarbon and OSGi Deep Dive
Carbon and OSGi Deep Dive
 
Building Multi-tenant SaaS Applications using WSO2 Private PaaS
Building Multi-tenant SaaS Applications using WSO2 Private PaaSBuilding Multi-tenant SaaS Applications using WSO2 Private PaaS
Building Multi-tenant SaaS Applications using WSO2 Private PaaS
 
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
 
Using the Carbon Architecture to Build a Fit-for-Purpose Platform
Using the Carbon Architecture to Build a Fit-for-Purpose PlatformUsing the Carbon Architecture to Build a Fit-for-Purpose Platform
Using the Carbon Architecture to Build a Fit-for-Purpose Platform
 
WSO2 Carbon Kernel Design and Architecture
WSO2 Carbon Kernel Design and ArchitectureWSO2 Carbon Kernel Design and Architecture
WSO2 Carbon Kernel Design and Architecture
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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 MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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 MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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 MenDelhi Call girls
 
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 AutomationSafe Software
 
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 organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Demistifying OSGi - Colombo Java Meetup 2013

  • 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