SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Downloaden Sie, um offline zu lesen
Introduction in OSGi



                2009




     www.bejug.org
Speaker’s qualifications

   Lead architect & project manager @ Ebit
   10 years experience in JSE/JEE
    development
   Steering member of the Devoxx conference
    and BeJUG
   Talks at Bejug & SpringOne
   Prince2 and Scrum certified



                    www.bejug.org
Imtech ICT Belgium




      www.bejug.org
3 Companies – 1 Mindset



                  Developmen          Data
 Infrastruct          t of          Warehousi
     ure           Software            ng
  Solutions        Solutions
     and                             Business
  Services           Java           Intelligenc
                  Open Source            e



   ICT Solutions and Services - Since 1996
    Specific and in-depth knowledge – 78
                  employees
                   www.bejug.org
Agenda

   Modularity in Java
   OSGi Basics
   OSGi Best Practices
   Conclusion




                    www.bejug.org
Modularity in Java

   Modularity Matters
    –   Component reuse
    –   Consistency
    –   Efficiency
    –   Robustness
    –   Maintainability
    –   Scalability




                      www.bejug.org
Modularity in Java

   Different approaches:
    –   OSGi
    –   HK2 (Apache Harmony)
    –   JSR 277/294
    –   JSR 232/291
    –   Spar
    –   Jigsaw project (only JDK)
    –   …



                         www.bejug.org
Modularity in Java

   Common problems in Java
    –   JAR HELL
    –   No versioning
    –   The Classpath
    –   Class visibility
    –   Hot deployment
    –   Write once, run anywhere




                        www.bejug.org
Agenda

   Modularity in Java
   OSGi Basics
   OSGi Best Practices
   Conclusion




                    www.bejug.org
OSGi Basics
   What is OSGi
   Classloading in OSGi
   The Bundle Lifecycle
   OSGi Services
   Demo




                       www.bejug.org
What is OSGi

   OSGi is a service oriented platform
   On top of a unique classloading mechanism
   Enabling features like:
    –   Versioning
    –   Encapsulation
    –   Runtime Dynamics




                       www.bejug.org
What is OSGi




               www.bejug.org
OSGi Basics
   What is OSGi
   Classloading in OSGi
                Welcome to the World of
             ClassNotFoundExceptions and
                 ClassDefNotFoundErrors

   The Bundle Lifecycle
   OSGi Services
   Demo

                       www.bejug.org
Classloading in OSGi

   Classloading 1 O 1
    –   What is a class?
            Compile time
            Runtime

    –   A classloader defines an isolated class space.




                            www.bejug.org
Classloading in OSGi

   How can a classloader share it’s class space
    with other classloaders?
     Classloader     hierarchy
       •   Linear hierarchy
       •   Tree hierarchy
     Classloader     delegation model
       •   Parent first delegation model
       •   Child first delegation model




                              www.bejug.org
Classloading in OSGi
   Default linear parent first delegation model




                         www.bejug.org
Classloading in OSGi

   Linear parent first delegation model
     no versioning
   Breaking the linear structure to allow
    versioning
    public static void main(String[] args) throws Exception {
         URL[] urls = ((URLClassLoader)TestApp.class.getClassLoader()).getURLs();
         URLClassLoader urlCL = new URLClassLoader(urls, null);
         Class personClass = urlCL.loadClass("be.ebit.bejug.model.Person");
         Object personInstance =
         personClass.newInstance();
         Person p = (Person)
         personInstance;
     }
                                      www.bejug.org
Classloading in OSGi
   Tree parent delegation model:




                        www.bejug.org
Classloading in OSGi

   Moving towards OSGi:
    public static void main(String[] args) throws Exception {
        //Path to model.jar version 1
        URL[] urls = new URL[]{new URL(“<path>/modelv1.jar”)}
        //Path to model.jar version 2
        URL[] urls = new URL[]{new URL(“<path>/modelv2.jar”)}
        URLClassLoader urlCL1 = new URLClassLoader(urls,null);
        URLClassLoader urlCL2 = new URLClassLoader(urls,null);
        Class personClassV1 =
        urlCL1.loadClass("be.ebit.springone.model.Person");
        Class personClassV2 =
        urlCL2.loadClass("be.ebit.springone.model.Person");
    }
                                 www.bejug.org
Classloading in OSGi




             www.bejug.org
Classloading in OSGi
   How does OSGi fit in?
    – ModelV1.jar  Bundle A
    – ModelV2.jar  Bundle B

     Each bundle with its own ClassLoader (and thread)
   The non-linear classloader structure allows
    versioning within one JVM.
   Basic principle behind the versioning capabilities in
    OSGi.
   Cfr. Servlet containers


                          www.bejug.org
Classloading in OSGi




             www.bejug.org
Classloading in OSGi

   The parent first delegation model does NOT
    allow communication between bundle
    classloaders
    –   The FrontV1 bundle classloader cannot get a
        Person class
   Solution?
    –   Extending the classloading mechanism




                         www.bejug.org
Classloading in OSGi




             www.bejug.org
Classloading in OSGi

   Bundle classloaders can delegate
    classloading to:
    –   The parent classloader
             parent first delegation
    –   Other bundle classloaders
             bundle   delegation
   The problem is choice:
    –   Parent or bundle delegation?
    –   If bundle delegation: to which bundle classloader?


                              www.bejug.org
Classloading in OSGi
   OSGi Delegation Rules:
    –   Parent Delegation Model is used if:




    –   Otherwise Bundle Delegation Model is used



                             www.bejug.org
Classloading in OSGi

   The Bundle Delegation Model:
    –   To which bundle classloader to delegate?
    –   Metadata in the Bundle Manifest to the rescue:
            1 Import/export-packages
              – what packages are needed by the bundle.
              – what packages are provided by the bundle.
            2 Required bundles
            3 Bundle classpath
            4 Fragment bundles
            5 Dynamic imports


                              www.bejug.org
Classloading in OSGi

   How to wire the classloaders?
     Classloader infrastructure
   General wiring resolution rules:
    –   Ensures that only one version of a class is visible
        within a classloader:
         class space consistency
    –   Uses the highest version within the constraints
        specified
            Version ranges
            Custom qualifiers


                                 www.bejug.org
Classloading in OSGi




             www.bejug.org
Classloading in OSGi

   Constraint solving: an example




                     www.bejug.org
Classloading in OSGi

   For each imported package a wire exists to
    the providing bundle classloader
   The wires are calculated at bundle resolution
   This wiring is NOT static:
    –   Bundles can come and go
    –   Dynamic updates
   This wiring process is repeated (partially)
    with each refresh without a JVM restart.


                       www.bejug.org
Classloading in OSGi
   Bundle Delegation
    Model (Runtime)




                        www.bejug.org
Classloading in OSGi
   The total picture:




                         www.bejug.org
Classloading in OSGi
   Fine-tuning the choice of delegation model:
    –   Bootdelegation:
            Additional classes to be loaded by the parent classloader
            System property: org.osgi.framework.bootdelegation
            No versioning
    –   System packages:
            Exported by the system bundle (bundle 0)
            System property: org.osgi.framework.system.packages
            Versioning
            Takes part in the wiring process
   Last option is preferred

                                www.bejug.org
Classloading in OSGi




             www.bejug.org
Classloading in OSGi

   Parent first delegation model:
    –   No versioning
    –   Static ‘wiring’
    –   See-all approach
   Bundle delegation model:
    –   Versioning
    –   By default, only the exports are visible
    –   Support for dynamic updates/dynamic wiring


                           www.bejug.org
OSGi Basics
   What is OSGi
   Classloading in OSGi
   The Bundle Lifecycle
   OSGi Services
   Demo




                      www.bejug.org
The Bundle Lifecycle




              www.bejug.org
The Bundle Lifecycle
   The Bundle Activator
    –   Start() & Stop()
    –   Resource Mgnt, Thread Mgnt, Services Lifecycle Mgnt
   Events:
    –   Bundle events
    –   Framework events
   The Bundle Context
    –   Environment information
    –   Installing bundles
    –   Installing services


                            www.bejug.org
The Bundle Lifecycle
   Bundle updates, uninstalls & refreshes
    –   Update: migrate from one version to another
            New exported packages are made available
            Old exported packages remain when used
    –   Uninstall
            New exported packages are made avialable
            Old exported packages remain when used
    –   RefreshPackages: The effective update & removal
            A package dependency graph is created
            The exporting bundle & all dependent bundles are stopped
             and restarted.



                                www.bejug.org
The Bundle Lifecycle




   Uninstall Model V1 Bundle



                       www.bejug.org
The Bundle Lifecycle




   Model V1 Bundle is marked for deleting



                        www.bejug.org
The Bundle Lifecycle




   Install & Start SecondFrontV1 Bundle
    –   (imports be.ebit.bejug.model)


                             www.bejug.org
The Bundle Lifecycle




   RefreshPackages (or restart framework)
    –   Resolution (wiring) process is redone


                             www.bejug.org
OSGi Basics
   What is OSGi
   Classloading in OSGi
   The Bundle Lifecycle
   OSGi Services
   Demo




                       www.bejug.org
OSGi Services




                www.bejug.org
OSGi Services

   Services
          Service interface
          Service implementation
   ServiceFactories
   ServiceRegistry
          Registration/Unregistration
          ServiceReference: search base
   Service Events/Listeners


                           www.bejug.org
OSGi Services

   Service lookup is text-based
    –   Filter (interface + criteria)
   Services can come and go
     Stale references
   Services are fully loaded before registration
   Multi-threading

 OSGi development is NOT trivial!

                            www.bejug.org
OSGi Services

   Extension Points:
    –   Not part of the specification
    –   Extension points and extensions
    –   One-to-many
    –   Lazy loading
    –   Less support for service dynamics (restart of
        eclipse)
   Extension Points doesn’t solve all problems!


                          www.bejug.org
OSGi Services
   Easing OSGi Component Development:
    –   Declarative Services
    –   Spring DM
    –   iPOJO
   Seperation of responsibilities:
    –   Implementation of the service
    –   Publication of the service
   Two component models in the specification:
    –   Declarative Services
    –   RFC 124 (Spring DM-based).


                               www.bejug.org
OSGi Services

   Common characteristics:
    –   Declaration of services
    –   Creation of services externalized (outside the
        bundle)
    –   Lazy loading
    –   Service composition
    –   Service dependencies & lifecycle management
    –   Dynamic dependencies



                         www.bejug.org
OSGi Basics
   What is OSGi
   Classloading in OSGi
   The Bundle Lifecycle
   OSGi Services
   Demo




                       www.bejug.org
Demo




       www.bejug.org
Demo




       www.bejug.org
Agenda

   Modularity in Java
   OSGi Basics
   OSGi Best Practices
   Conclusion




                   www.bejug.org
OSGi Patterns & Best Practices

   OSGi Patterns
    –   Extender Pattern
    –   Configuration Fragment Bundles
    –   Whiteboard Pattern




                        www.bejug.org
Extender Pattern




              www.bejug.org
Configuration Fragment Bundles




   Examples:
    –   Log4J configuration,
    –   Custom configuration of the spring extender bundle


                            www.bejug.org
Whiteboard Pattern




             www.bejug.org
OSGi Patterns & Best Practices

   Best Practices:
    –   Use imports instead of the parent classloader
        (except java.*)
    –   Minimize dependencies
    –   Hide implementation details
    –   Start ordering dependencies
    –   Thread safety
    –   Framework Callbacks
    –   Classloader hierarchy dependencies
    –   OSGi Framework coupling

                         www.bejug.org
Conclusion

   OSGi is a platform full of potential:
    –   Enhances encapsulation
    –   Versioning
    –   Runtime dynamics
    –   Service-oriented
   A different mindset is needed!




                       www.bejug.org
Q&A




 –   http://belgium.osgiusers.org
 –   www.ouforum.be

                       www.bejug.org
Links

   http://www.osgi.org
   http://www.springsource.org/osgi
   http://www.dynamicjava.org
   http://belgium.osgiusers.org




                     www.bejug.org

Weitere ähnliche Inhalte

Was ist angesagt?

Modular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafModular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafIoan Eugen Stan
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentSanjeeb Sahoo
 
OSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worldsOSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worldsArun Gupta
 
OSGi & Java EE in GlassFish
OSGi & Java EE in GlassFishOSGi & Java EE in GlassFish
OSGi & Java EE in GlassFishSanjeeb Sahoo
 
Use Case: Building OSGi Enterprise Applications (QCon 14)
Use Case: Building OSGi Enterprise Applications (QCon 14)Use Case: Building OSGi Enterprise Applications (QCon 14)
Use Case: Building OSGi Enterprise Applications (QCon 14)Carsten Ziegeler
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishArun Gupta
 
Maximize the power of OSGi
Maximize the power of OSGiMaximize the power of OSGi
Maximize the power of OSGiDavid Bosschaert
 
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
 
Scala and Play with Gradle
Scala and Play with GradleScala and Play with Gradle
Scala and Play with GradleWei Chen
 
Managing Change
Managing ChangeManaging Change
Managing ChangeMirko Jahn
 
Java 9 Modularity and Project Jigsaw
Java 9 Modularity and Project JigsawJava 9 Modularity and Project Jigsaw
Java 9 Modularity and Project JigsawComsysto Reply GmbH
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionStephen Colebourne
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVMRyan Cuprak
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New FeaturesAli BAKAN
 

Was ist angesagt? (20)

Modular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafModular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache Karaf
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
 
Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012Karaf ee-apachecon eu-2012
Karaf ee-apachecon eu-2012
 
OSGi Blueprint Services
OSGi Blueprint ServicesOSGi Blueprint Services
OSGi Blueprint Services
 
OSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worldsOSGi & Java EE in GlassFish - Best of both worlds
OSGi & Java EE in GlassFish - Best of both worlds
 
OSGi & Java EE in GlassFish
OSGi & Java EE in GlassFishOSGi & Java EE in GlassFish
OSGi & Java EE in GlassFish
 
Use Case: Building OSGi Enterprise Applications (QCon 14)
Use Case: Building OSGi Enterprise Applications (QCon 14)Use Case: Building OSGi Enterprise Applications (QCon 14)
Use Case: Building OSGi Enterprise Applications (QCon 14)
 
OSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFishOSGi-enabled Java EE applications in GlassFish
OSGi-enabled Java EE applications in GlassFish
 
Maximize the power of OSGi
Maximize the power of OSGiMaximize the power of OSGi
Maximize the power of OSGi
 
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)
 
Java 9 preview
Java 9 previewJava 9 preview
Java 9 preview
 
Scala and Play with Gradle
Scala and Play with GradleScala and Play with Gradle
Scala and Play with Gradle
 
Managing Change
Managing ChangeManaging Change
Managing Change
 
Java 9 Modularity and Project Jigsaw
Java 9 Modularity and Project JigsawJava 9 Modularity and Project Jigsaw
Java 9 Modularity and Project Jigsaw
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New Features
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
 
JDK-9: Modules and Java Linker
JDK-9: Modules and Java LinkerJDK-9: Modules and Java Linker
JDK-9: Modules and Java Linker
 

Andere mochten auch

Introduction To OSGi
Introduction To OSGiIntroduction To OSGi
Introduction To OSGiccustine
 
CakeDC Git Workflow extension
CakeDC Git Workflow extensionCakeDC Git Workflow extension
CakeDC Git Workflow extensionLubomír Štork
 
Intro to OSGi – the Microservices kernel - P Kriens & T Ward
Intro to OSGi – the Microservices kernel - P Kriens & T WardIntro to OSGi – the Microservices kernel - P Kriens & T Ward
Intro to OSGi – the Microservices kernel - P Kriens & T Wardmfrancis
 
Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...mfrancis
 
Security in OSGi applications: Robust OSGi Platforms, secure Bundles
Security in OSGi applications: Robust OSGi Platforms, secure BundlesSecurity in OSGi applications: Robust OSGi Platforms, secure Bundles
Security in OSGi applications: Robust OSGi Platforms, secure BundlesKai Hackbarth
 
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Phú Phùng
 
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructuresMaster Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructuresFrançois Le Droff
 
Meetup#6: AWS-AI & Lambda Serverless
Meetup#6: AWS-AI & Lambda Serverless Meetup#6: AWS-AI & Lambda Serverless
Meetup#6: AWS-AI & Lambda Serverless AWS Vietnam Community
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentGabriel Walt
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web ArchitectureChamnap Chhorn
 

Andere mochten auch (12)

Condor
CondorCondor
Condor
 
Introduction To OSGi
Introduction To OSGiIntroduction To OSGi
Introduction To OSGi
 
CakeDC Git Workflow extension
CakeDC Git Workflow extensionCakeDC Git Workflow extension
CakeDC Git Workflow extension
 
Intro to OSGi – the Microservices kernel - P Kriens & T Ward
Intro to OSGi – the Microservices kernel - P Kriens & T WardIntro to OSGi – the Microservices kernel - P Kriens & T Ward
Intro to OSGi – the Microservices kernel - P Kriens & T Ward
 
Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...
 
Security in OSGi applications: Robust OSGi Platforms, secure Bundles
Security in OSGi applications: Robust OSGi Platforms, secure BundlesSecurity in OSGi applications: Robust OSGi Platforms, secure Bundles
Security in OSGi applications: Robust OSGi Platforms, secure Bundles
 
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
 
Why OSGi?
Why OSGi?Why OSGi?
Why OSGi?
 
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructuresMaster Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
 
Meetup#6: AWS-AI & Lambda Serverless
Meetup#6: AWS-AI & Lambda Serverless Meetup#6: AWS-AI & Lambda Serverless
Meetup#6: AWS-AI & Lambda Serverless
 
AEM Best Practices for Component Development
AEM Best Practices for Component DevelopmentAEM Best Practices for Component Development
AEM Best Practices for Component Development
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
 

Ähnlich wie Intro To OSGi

Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
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
 
Introduction to OSGGi
Introduction to OSGGiIntroduction to OSGGi
Introduction to OSGGiMarek Koniew
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Jeffrey Groneberg
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 
CodeCamp Iasi 10 march 2012 - SolvingThePuzzle
CodeCamp Iasi 10 march 2012 - SolvingThePuzzleCodeCamp Iasi 10 march 2012 - SolvingThePuzzle
CodeCamp Iasi 10 march 2012 - SolvingThePuzzleCodecamp Romania
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The FactLuciano Resende
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeNikita Lipsky
 
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
 
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
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi WebinarWSO2
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OpenBlend society
 

Ähnlich wie Intro To OSGi (20)

Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Modular Java
Modular JavaModular Java
Modular Java
 
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/)
 
Introduction to OSGGi
Introduction to OSGGiIntroduction to OSGGi
Introduction to OSGGi
 
OSGI Modularity
OSGI ModularityOSGI Modularity
OSGI Modularity
 
Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -Create *real* modular Java applications - a brief introduction -
Create *real* modular Java applications - a brief introduction -
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
CodeCamp Iasi 10 march 2012 - SolvingThePuzzle
CodeCamp Iasi 10 march 2012 - SolvingThePuzzleCodeCamp Iasi 10 march 2012 - SolvingThePuzzle
CodeCamp Iasi 10 march 2012 - SolvingThePuzzle
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
 
OSGi & Blueprint
OSGi & BlueprintOSGi & Blueprint
OSGi & Blueprint
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
 
Osgi Sun 20080820
Osgi Sun 20080820Osgi Sun 20080820
Osgi Sun 20080820
 
OSGi overview
OSGi overviewOSGi overview
OSGi overview
 
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...
 
Osgi
OsgiOsgi
Osgi
 
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)
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
 
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
 

Mehr von Stephan Janssen

Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)Stephan Janssen
 
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new DeVoxxEd websites with JHipster, Angular & KubernetesThe new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new DeVoxxEd websites with JHipster, Angular & KubernetesStephan Janssen
 
The new Voxxed websites with JHipster, Angular and GitLab
The new Voxxed websites  with JHipster, Angular and GitLabThe new Voxxed websites  with JHipster, Angular and GitLab
The new Voxxed websites with JHipster, Angular and GitLabStephan Janssen
 
Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5Stephan Janssen
 
Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2Stephan Janssen
 

Mehr von Stephan Janssen (17)

Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)Devoxx speaker training (June 27th, 2018)
Devoxx speaker training (June 27th, 2018)
 
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new DeVoxxEd websites with JHipster, Angular & KubernetesThe new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
 
The new Voxxed websites with JHipster, Angular and GitLab
The new Voxxed websites  with JHipster, Angular and GitLabThe new Voxxed websites  with JHipster, Angular and GitLab
The new Voxxed websites with JHipster, Angular and GitLab
 
Java, what's next?
Java, what's next?Java, what's next?
Java, what's next?
 
Programming 4 kids
Programming 4 kidsProgramming 4 kids
Programming 4 kids
 
Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day3-4-5
 
Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2Devoxx2011 timesheet day1-2
Devoxx2011 timesheet day1-2
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
BeJUG JAX-RS Event
BeJUG JAX-RS EventBeJUG JAX-RS Event
BeJUG JAX-RS Event
 
Whats New In Java Ee 6
Whats New In Java Ee 6Whats New In Java Ee 6
Whats New In Java Ee 6
 
Glass Fishv3 March2010
Glass Fishv3 March2010Glass Fishv3 March2010
Glass Fishv3 March2010
 
Advanced Scrum
Advanced ScrumAdvanced Scrum
Advanced Scrum
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Kick Start Jpa
Kick Start JpaKick Start Jpa
Kick Start Jpa
 
BeJUG - Di With Spring
BeJUG - Di With SpringBeJUG - Di With Spring
BeJUG - Di With Spring
 
BeJUG - Spring 3 talk
BeJUG - Spring 3 talkBeJUG - Spring 3 talk
BeJUG - Spring 3 talk
 
BeJug.Org Java Generics
BeJug.Org   Java GenericsBeJug.Org   Java Generics
BeJug.Org Java Generics
 

Kürzlich hochgeladen

Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfAdmir Softic
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Centuryrwgiffor
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...Any kyc Account
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...rajveerescorts2022
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxpriyanshujha201
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
 

Kürzlich hochgeladen (20)

Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
Mifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pills
Mifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pillsMifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pills
Mifty kit IN Salmiya (+918133066128) Abortion pills IN Salmiyah Cytotec pills
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
 

Intro To OSGi

  • 1. Introduction in OSGi 2009 www.bejug.org
  • 2. Speaker’s qualifications  Lead architect & project manager @ Ebit  10 years experience in JSE/JEE development  Steering member of the Devoxx conference and BeJUG  Talks at Bejug & SpringOne  Prince2 and Scrum certified www.bejug.org
  • 3. Imtech ICT Belgium www.bejug.org
  • 4. 3 Companies – 1 Mindset Developmen Data Infrastruct t of Warehousi ure Software ng Solutions Solutions and Business Services Java Intelligenc Open Source e ICT Solutions and Services - Since 1996 Specific and in-depth knowledge – 78 employees www.bejug.org
  • 5. Agenda  Modularity in Java  OSGi Basics  OSGi Best Practices  Conclusion www.bejug.org
  • 6. Modularity in Java  Modularity Matters – Component reuse – Consistency – Efficiency – Robustness – Maintainability – Scalability www.bejug.org
  • 7. Modularity in Java  Different approaches: – OSGi – HK2 (Apache Harmony) – JSR 277/294 – JSR 232/291 – Spar – Jigsaw project (only JDK) – … www.bejug.org
  • 8. Modularity in Java  Common problems in Java – JAR HELL – No versioning – The Classpath – Class visibility – Hot deployment – Write once, run anywhere www.bejug.org
  • 9. Agenda  Modularity in Java  OSGi Basics  OSGi Best Practices  Conclusion www.bejug.org
  • 10. OSGi Basics  What is OSGi  Classloading in OSGi  The Bundle Lifecycle  OSGi Services  Demo www.bejug.org
  • 11. What is OSGi  OSGi is a service oriented platform  On top of a unique classloading mechanism  Enabling features like: – Versioning – Encapsulation – Runtime Dynamics www.bejug.org
  • 12. What is OSGi www.bejug.org
  • 13. OSGi Basics  What is OSGi  Classloading in OSGi Welcome to the World of ClassNotFoundExceptions and ClassDefNotFoundErrors  The Bundle Lifecycle  OSGi Services  Demo www.bejug.org
  • 14. Classloading in OSGi  Classloading 1 O 1 – What is a class?  Compile time  Runtime – A classloader defines an isolated class space. www.bejug.org
  • 15. Classloading in OSGi  How can a classloader share it’s class space with other classloaders?  Classloader hierarchy • Linear hierarchy • Tree hierarchy  Classloader delegation model • Parent first delegation model • Child first delegation model www.bejug.org
  • 16. Classloading in OSGi  Default linear parent first delegation model www.bejug.org
  • 17. Classloading in OSGi  Linear parent first delegation model  no versioning  Breaking the linear structure to allow versioning public static void main(String[] args) throws Exception { URL[] urls = ((URLClassLoader)TestApp.class.getClassLoader()).getURLs(); URLClassLoader urlCL = new URLClassLoader(urls, null); Class personClass = urlCL.loadClass("be.ebit.bejug.model.Person"); Object personInstance = personClass.newInstance(); Person p = (Person) personInstance; } www.bejug.org
  • 18. Classloading in OSGi  Tree parent delegation model: www.bejug.org
  • 19. Classloading in OSGi  Moving towards OSGi: public static void main(String[] args) throws Exception { //Path to model.jar version 1 URL[] urls = new URL[]{new URL(“<path>/modelv1.jar”)} //Path to model.jar version 2 URL[] urls = new URL[]{new URL(“<path>/modelv2.jar”)} URLClassLoader urlCL1 = new URLClassLoader(urls,null); URLClassLoader urlCL2 = new URLClassLoader(urls,null); Class personClassV1 = urlCL1.loadClass("be.ebit.springone.model.Person"); Class personClassV2 = urlCL2.loadClass("be.ebit.springone.model.Person"); } www.bejug.org
  • 20. Classloading in OSGi www.bejug.org
  • 21. Classloading in OSGi  How does OSGi fit in? – ModelV1.jar  Bundle A – ModelV2.jar  Bundle B  Each bundle with its own ClassLoader (and thread)  The non-linear classloader structure allows versioning within one JVM.  Basic principle behind the versioning capabilities in OSGi.  Cfr. Servlet containers www.bejug.org
  • 22. Classloading in OSGi www.bejug.org
  • 23. Classloading in OSGi  The parent first delegation model does NOT allow communication between bundle classloaders – The FrontV1 bundle classloader cannot get a Person class  Solution? – Extending the classloading mechanism www.bejug.org
  • 24. Classloading in OSGi www.bejug.org
  • 25. Classloading in OSGi  Bundle classloaders can delegate classloading to: – The parent classloader  parent first delegation – Other bundle classloaders  bundle delegation  The problem is choice: – Parent or bundle delegation? – If bundle delegation: to which bundle classloader? www.bejug.org
  • 26. Classloading in OSGi  OSGi Delegation Rules: – Parent Delegation Model is used if: – Otherwise Bundle Delegation Model is used www.bejug.org
  • 27. Classloading in OSGi  The Bundle Delegation Model: – To which bundle classloader to delegate? – Metadata in the Bundle Manifest to the rescue:  1 Import/export-packages – what packages are needed by the bundle. – what packages are provided by the bundle.  2 Required bundles  3 Bundle classpath  4 Fragment bundles  5 Dynamic imports www.bejug.org
  • 28. Classloading in OSGi  How to wire the classloaders?  Classloader infrastructure  General wiring resolution rules: – Ensures that only one version of a class is visible within a classloader:  class space consistency – Uses the highest version within the constraints specified  Version ranges  Custom qualifiers www.bejug.org
  • 29. Classloading in OSGi www.bejug.org
  • 30. Classloading in OSGi  Constraint solving: an example www.bejug.org
  • 31. Classloading in OSGi  For each imported package a wire exists to the providing bundle classloader  The wires are calculated at bundle resolution  This wiring is NOT static: – Bundles can come and go – Dynamic updates  This wiring process is repeated (partially) with each refresh without a JVM restart. www.bejug.org
  • 32. Classloading in OSGi  Bundle Delegation Model (Runtime) www.bejug.org
  • 33. Classloading in OSGi  The total picture: www.bejug.org
  • 34. Classloading in OSGi  Fine-tuning the choice of delegation model: – Bootdelegation:  Additional classes to be loaded by the parent classloader  System property: org.osgi.framework.bootdelegation  No versioning – System packages:  Exported by the system bundle (bundle 0)  System property: org.osgi.framework.system.packages  Versioning  Takes part in the wiring process  Last option is preferred www.bejug.org
  • 35. Classloading in OSGi www.bejug.org
  • 36. Classloading in OSGi  Parent first delegation model: – No versioning – Static ‘wiring’ – See-all approach  Bundle delegation model: – Versioning – By default, only the exports are visible – Support for dynamic updates/dynamic wiring www.bejug.org
  • 37. OSGi Basics  What is OSGi  Classloading in OSGi  The Bundle Lifecycle  OSGi Services  Demo www.bejug.org
  • 38. The Bundle Lifecycle www.bejug.org
  • 39. The Bundle Lifecycle  The Bundle Activator – Start() & Stop() – Resource Mgnt, Thread Mgnt, Services Lifecycle Mgnt  Events: – Bundle events – Framework events  The Bundle Context – Environment information – Installing bundles – Installing services www.bejug.org
  • 40. The Bundle Lifecycle  Bundle updates, uninstalls & refreshes – Update: migrate from one version to another  New exported packages are made available  Old exported packages remain when used – Uninstall  New exported packages are made avialable  Old exported packages remain when used – RefreshPackages: The effective update & removal  A package dependency graph is created  The exporting bundle & all dependent bundles are stopped and restarted. www.bejug.org
  • 41. The Bundle Lifecycle  Uninstall Model V1 Bundle www.bejug.org
  • 42. The Bundle Lifecycle  Model V1 Bundle is marked for deleting www.bejug.org
  • 43. The Bundle Lifecycle  Install & Start SecondFrontV1 Bundle – (imports be.ebit.bejug.model) www.bejug.org
  • 44. The Bundle Lifecycle  RefreshPackages (or restart framework) – Resolution (wiring) process is redone www.bejug.org
  • 45. OSGi Basics  What is OSGi  Classloading in OSGi  The Bundle Lifecycle  OSGi Services  Demo www.bejug.org
  • 46. OSGi Services www.bejug.org
  • 47. OSGi Services  Services  Service interface  Service implementation  ServiceFactories  ServiceRegistry  Registration/Unregistration  ServiceReference: search base  Service Events/Listeners www.bejug.org
  • 48. OSGi Services  Service lookup is text-based – Filter (interface + criteria)  Services can come and go  Stale references  Services are fully loaded before registration  Multi-threading  OSGi development is NOT trivial! www.bejug.org
  • 49. OSGi Services  Extension Points: – Not part of the specification – Extension points and extensions – One-to-many – Lazy loading – Less support for service dynamics (restart of eclipse)  Extension Points doesn’t solve all problems! www.bejug.org
  • 50. OSGi Services  Easing OSGi Component Development: – Declarative Services – Spring DM – iPOJO  Seperation of responsibilities: – Implementation of the service – Publication of the service  Two component models in the specification: – Declarative Services – RFC 124 (Spring DM-based). www.bejug.org
  • 51. OSGi Services  Common characteristics: – Declaration of services – Creation of services externalized (outside the bundle) – Lazy loading – Service composition – Service dependencies & lifecycle management – Dynamic dependencies www.bejug.org
  • 52. OSGi Basics  What is OSGi  Classloading in OSGi  The Bundle Lifecycle  OSGi Services  Demo www.bejug.org
  • 53. Demo www.bejug.org
  • 54. Demo www.bejug.org
  • 55. Agenda  Modularity in Java  OSGi Basics  OSGi Best Practices  Conclusion www.bejug.org
  • 56. OSGi Patterns & Best Practices  OSGi Patterns – Extender Pattern – Configuration Fragment Bundles – Whiteboard Pattern www.bejug.org
  • 57. Extender Pattern www.bejug.org
  • 58. Configuration Fragment Bundles  Examples: – Log4J configuration, – Custom configuration of the spring extender bundle www.bejug.org
  • 59. Whiteboard Pattern www.bejug.org
  • 60. OSGi Patterns & Best Practices  Best Practices: – Use imports instead of the parent classloader (except java.*) – Minimize dependencies – Hide implementation details – Start ordering dependencies – Thread safety – Framework Callbacks – Classloader hierarchy dependencies – OSGi Framework coupling www.bejug.org
  • 61. Conclusion  OSGi is a platform full of potential: – Enhances encapsulation – Versioning – Runtime dynamics – Service-oriented  A different mindset is needed! www.bejug.org
  • 62. Q&A – http://belgium.osgiusers.org – www.ouforum.be www.bejug.org
  • 63. Links  http://www.osgi.org  http://www.springsource.org/osgi  http://www.dynamicjava.org  http://belgium.osgiusers.org www.bejug.org