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

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

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

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

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