SlideShare una empresa de Scribd logo
1 de 52
Descargar para leer sin conexión
OSGi
Create *real* modular
   Java applications
- a brief introduction -
     By Jeffrey Groneberg
                @inkvine
     jeffrey.groneberg@gmail.com
Table of Contents

•    About me
•    What is OSGi?
•    Class Loader – Problems with “Twins”
•    It’s all about bundles
•    OSGi architecture and layers
•    Services, Services, Services – Micro-SOA
•    Building components with OSGi
      –  SCR
      –  SpringDM
•  Tools
•  How to learn?
About
 me
About me

•  Working at SAP AG as a developer for mobile healthcare solutions
   (Android & iOS)
•  MSc Computer Science
•  Java enthusiast
•  API creator ;)
•  Reading and interested in everything related to technology

•  Twitter: @Inkvine
•  Mail: jeffrey.groneberg@gmail.com
What is
 OSGi?
What is it!?

•  Actually OSGi is not a framework
•  Open Service Gateway initiative
•  OSGi is a specification (http://www.osgi.org/Main/HomePage)
•  Originally intended to be used within the Embedded-Device-Section
   (Cars, Facility, Home-Environment)
•  Extremely lose coupled and highly extendable (Communication via
   services)
•  Replace modules during runtime or extend (hard- & software)
•  Extremely lightweight (limited resources on embedded devices)
Car example




             Uses      ABS-
Brakes
                      System
(Front)
                        (v1)


           Fallback




             Uses      ABS-
Brakes
                      System
(BAck)
                        (v2)
Ever used ECLIPSE?

•  Eclipse is completely build on OSGi
•  Eclipse is running within an OSGi container
•  Every time you install a plugin via “Update/Install”
   an OSGi bundle is downloaded and installed
•  OSGi is a specification therefore Eclipse uses a special implementation
•  Container = Implementation running within the JVM
•  OSGi = Java !
•  Different implementations available (for different requirements)
Different Implementations

 •  A spec needs to be implemented. Therefore different implementations
    are available on the market

Name                     Open Source             Description
Equinox                  Yes                     Most spread OSGi container. Used in
                                                 Eclipse and so called “reference
                                                 implementation”
Felix                    Yes                     Apache implementation, formerly known
                                                 as “Oscar”
Knoplerfish              Yes                     Originally used within embedded systems
                                                 now ported to “every day” usage.

mBedded Server           No                      Commercial implementation with official
                                                 support and maintainance
Classloader
And Problems
 with twins
The Java Classloader approach (1/2)


                         Bootstrap
                        classloader


  Delegates to parent
                               Parent



                         Extension
                        classloader




  Delegates to parent          Parent



                        Application
                        Classloader
The Java Classloader approach (2/2)

•  Bootstrap classloader:
   all the java core libs that are located in $JAVA_HOME
•  Extensions classloader:
   lib/ext directory
•  Application classloader:
   all libs within the started application
•  Every classloader asks his parent if he has already loaded the needed
   class. If he receives a “no” he has to take care of it by himself.
•  No twins possible!
JA A is stupid to identify twins
              V


                                                   Load order




  A                                                                 D                                  F
                        B                  C                                           E
          Jar 1                                         Jar 2                                  Jar 3


Classes:
                                                                    First loaded – first seated!!
                                                       Merged
-  Different shape means different class
-  Same shape means similar class
    (but different implementations)



                                   A                            D
                                                                               F
                                               B
OSGi CLASSLOADER (1/2)

•  “Non hierarchical” classloader
•  Every component in OSGi is a bundle (JAR-file that contains
   metadata)
•  Every bundle has its own classloader (sandbox – no sight to outer
   world)
•  Classloader asks OSGi container for references
•  If restrictions (given by the metadata) are fine the class will be
   provided by another component and its classloader
•  --> classloader chaining
OSGi CLASSLOADER (2/2)



                                            Class not found

                  Component                                         Component
                 classloader                                       classloader

                                           Classloader chaining
                                           (if allowed)
Class loading           Class resolution                                  Class loading




                OSGi component                                    OSGI component




                                              Classloader
                                               isolation
It’S all
about bundles
AN osgi Bundle

•  Physically it’s a JAR-File that contains:
   Implementations & metadata
•  Metadata (the MANIFEST.mf-File within the JAR) allows fine granularly
   definitions of (just the most important definitions):
    –  What packages (classes) are needed that the bundle is able to run
    –  What packages (classes) are visible (and therefore exposed) to other
       bundles within the OSGi container
    –  Which version of packages the bundle exposes
    –  Which version of packages the bundle needs to import
•  Every bundle has to be installed within the OSGi container
EXAMPLE MANIFEST.MF



Bundle-Name: Toast Emergency
Bundle-SymbolicName:
org.equinoxosgi.toast.client.emergency
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Bundle-Activator:
org.equinoxosgi.toast.client.emergency.Activator
Import-Package: org.equinoxosgi.toast.dev.airbag,
org.equinoxosgi.toast.dev.gps, org.osgi.framework;
Visibility

•  Information Hiding
    –  Hide classes used internally and expose classes for reusability
    –  Encapsulate functionalities by interfaces, but hide implementations
•  Best practice
    –  One bundle for the public API that exposes the package containing the
       interfaces
    –  One bundle for the implementation

Export-Package: org.equinoxosgi.toast.dev.airbag
Dependencies

•  Declare dependencies (What is needed for the bundle to be executed)
•  Versions can be added easily (“I am running on legacy code”)

Import-Package: org.equinoxosgi.toast.dev.airbag,
org.equinoxosgi.toast.dev.gps, org.osgi.framework;
LIFE CYCLE AND STATES

•  Every bundle has to be installed within the container
•  It passes different states:
    –  Validating dependencies
    –  Exposing packages
    –  Checking versions
•  States are:
    –  installed
    –  resolved
    –  Uninstalled
•  A bundle has callback methods to react to the loss of dependencies
    –  Programmer has to take care of it
OSGi
Architecture
  & Layers
Layers (1/2)

                                Services


                            Service
                            Registry
                                           Security
Bundles                   Lifecycle


                        Modules


                                JVM


             Operating System
Layers (2/2)

•  Security
    –  Adopts the Java Security Standard (optional)
•  JVM
    –  Different JREs can be supported therefore a kind of representation needs to be provided
       within the OSGi container
•  Modules
    –  All the bundles that are added to OSGi container
•  Services Registry
    –  Functionalities can be provided within the OSGi container as services. The registry takes
       care of registering and exposing those services and notifies bundles that consumes those
•  Services
    –  OSGi provides (based on the implementation) services out of the box (HTTP e.g.).
•  Life Cycle Management
Services,
  services,
  services


Micro SOA
What is a service?




“A service is a normal Java object that is registered under one or more
Java interfaces with the service registry. Bundles can register services,
 search for them, or receive notifications when their registration state
                               changes.”
SOA
OSGi SOA

•  Create a bundle with the interface (the public API) of your service
•  Export the package containing the interface

•  Create a bundle with the implementation of the interface (import the public API
   package)
•  Reference the OSGi Service Registry and deliver your implementation for the given
   interface

•  Reference the Service Registry and ask for an implementation for a given interface

•  The implementation is always hidden to the consumer (lose coupling)
Two WAYS of service implementations

•  Program the whole registration/referencing and state change listeners
   by your own
    –  Think about it: Services can come and go or are never there. What shall your
       bundle do if this happens?
    –  A lot of code to write
•  Use Inversion of Code and Dependency Injection
    –  SpringDM or Declarative Services
       (formerly known as SCR) (will be shown later)
Doing it the hard way
the service implementation
Doing it the hard way
    The consumer
DOING it the hard way THE Service Tracker (1/2)
DOING it the hard way THE Service Tracker (2/2)
Downsides of the hard way

•  Starting time is extended due to a lot of “management” code within the activator
     –  Think about a lot of bundles where each bundle runs a lot of initializing code
     –  The application takes a lot of time to start
•  Allocations during runtime
     –  Trackers or other “flags” needs to be initialized to handle services even though the service
        is never there
•  Complexity

•  As a programmer I do not want to take of all this stuff:
     –  Give me a service if it is there
     –  Take a service if I provide you one
     –  Declarations > Programming
Building
components
 witH OSGI
CHOOSE WISELY

     OSGi Alliance
         with

        SCR


      “YOU SHALL NOT PASS! UAAH!!”
                 and btw:                               SpringSource
“One does not simple build an iOS framework”                 with

                                                       SpringDM
THE SCR

•    By the OSGi Alliance
•    A component consumes and/or provides services
•    Using the Service Component Runtime
•    SCR = Declarative Services
•    SCR is a bundle that is installed within the OSGi container
      –  Extender Pattern
      –  Scans all bundles for metadata containing the component definition
         (declaration)
      –  Registers provided services from bundles in the OSGi Service Registry
      –  Automatically binds services to consumers
What is an OSGI SERVICE component?



            Bundle                              Bundle
         Component                           Component

        Component instance                 Component instance



       Component declaration              Component declaration




   Provides                                             Consumes
                               Services
SCR by example THE provider

•  A component implementing a given API (interface) and registering
   itself as service




        Bundle structure                             Public API




                             component.xml
SCR BY Example THE CONSUMER

•  A component consuming a service by a Public API (interface)




The consumer




                                                        component.xml
SPRING DM

•  From SpringSource
•  A lot more than just a component declaration
    –  SpringMVC
    –  Spring Security
    –  AOP
    –  Spring WS/RS
    –  Dependency Injection with Beans (most powerful feature)
•  Not „component“, it is called „Bean“
•  Using Extender Pattern
•  Bundle within the OSGi container
Spring DM


                    Bundle with Spring config

           Bean                                      beans1.xml                         Searches for
                                                        beans2.xml
             Bean                         uses

           Bean                                  Spring container
                                creates



Provides             Consumes
                                                                                                 Spring DM Extender
                                                               Configures and creates


                           Services
Spring DM Example The Provider




       Bundle structure
                                                               Public API (interface)




Implementation


                                                     Beans declaration file




                          OSGi service declaration
SPRING DM EXAMPLE THE CONSUMER




                Consumer




          OSGi services declaration




             Beans declaration
Tools
What do i need (not all)?

•    Eclipse (all out of the box)
•    SpringSource ToolSuite (my favorite Eclipse distribution)
•    Maven (bundles with bundles need other bundles, that need bundles)
•    SpringSource Enterprise Repository
•    Virgo
      –  OSGi based application server
•  Tomcat
      –  You need an OSGi Servlet Bridge to launch the OSGi Container within a web
         application
•  LeanDI? !
How to
learn OSGi?
I want to OSGI“

•    Buy the book „OSGi & Equinox“
•    Install SpringSource ToolSuite
•    Install the book‘s plugin
•    Work through the examples
•    Buy „OSGi in Action“ as a great reference
•    Buy „SpringDM in Action“
      –  Pure hardcore geek food
      –  If you understand everything you can call yourself „the shiat“
Great and what do I get from osgi
              when programming non-java“?

•    Think OSGi!
•    Divide API and implementation
•    Hide implementations behind registries and services
•    Highly reusable components (technical)
•    Seperate domain from the rest of the application
•    A LOT of OSGi paradigms are adopted to our EMR Android app and will
     „travel“ to iOS soon !
Thanks!

ANY QUESTIONS?
Disclaimer

•  All photos/pictures within this slides are provided from flickr.com and
   licenced under CC for commercial use.
•  The code samples can be found in the books „OSGi & Equinox“ and
   „SpringDM in Action“
•  If you want to use these slides in any lecture do contact me before, pls.

Más contenido relacionado

La actualidad más candente

Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming languagemasud33bd
 
Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingAnton Keks
 
Java compilation
Java compilationJava compilation
Java compilationMike Kucera
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...mfrancis
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machineLaxman Puri
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 MinutesCharles Nutter
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011njbartlett
 
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...mfrancis
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: BasicsAnton Keks
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsAnton Keks
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsAnton Keks
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Peter R. Egli
 
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011Arun Gupta
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |ShubhamAthawane
 
Java Course 6: Introduction to Agile
Java Course 6: Introduction to AgileJava Course 6: Introduction to Agile
Java Course 6: Introduction to AgileAnton Keks
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOPAnton Keks
 

La actualidad más candente (20)

Basics of java programming language
Basics of java programming languageBasics of java programming language
Basics of java programming language
 
Java Course 13: JDBC & Logging
Java Course 13: JDBC & LoggingJava Course 13: JDBC & Logging
Java Course 13: JDBC & Logging
 
Java compilation
Java compilationJava compilation
Java compilation
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Intro to OSGi
Intro to OSGiIntro to OSGi
Intro to OSGi
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
OSGi-friendly bytecode weaving – enhance your classes, not your dependency gr...
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: Basics
 
JAVA BYTE CODE
JAVA BYTE CODEJAVA BYTE CODE
JAVA BYTE CODE
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
 
Java Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & ServletsJava Course 12: XML & XSL, Web & Servlets
Java Course 12: XML & XSL, Web & Servlets
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)
 
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |
 
Java Course 6: Introduction to Agile
Java Course 6: Introduction to AgileJava Course 6: Introduction to Agile
Java Course 6: Introduction to Agile
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
 
Introducing Java 7
Introducing Java 7Introducing Java 7
Introducing Java 7
 

Destacado

Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...
Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...
Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...de KLING
 
Technology and Education
Technology and EducationTechnology and Education
Technology and Educationstarlite3w
 
Fate of Ruby 1.8
Fate of Ruby 1.8Fate of Ruby 1.8
Fate of Ruby 1.8shyouhei
 
An introduction to Eclipse Mylyn
An introduction to Eclipse MylynAn introduction to Eclipse Mylyn
An introduction to Eclipse MylynJeffrey Groneberg
 
Buitenring Gelijkvloerse Kruising Merkelbekerstraat
Buitenring Gelijkvloerse Kruising MerkelbekerstraatBuitenring Gelijkvloerse Kruising Merkelbekerstraat
Buitenring Gelijkvloerse Kruising Merkelbekerstraatde KLING
 
BUITENRING Bottleneck de KLING
BUITENRING Bottleneck  de KLINGBUITENRING Bottleneck  de KLING
BUITENRING Bottleneck de KLINGde KLING
 
5 Jahre Lucky Trimmer Tanz Performance Serie
5 Jahre Lucky Trimmer Tanz Performance Serie5 Jahre Lucky Trimmer Tanz Performance Serie
5 Jahre Lucky Trimmer Tanz Performance SerieLucky Trimmer
 
LUCKY TRIMMER Tanz Performance Serie #12, 2008
LUCKY TRIMMER Tanz Performance Serie #12, 2008LUCKY TRIMMER Tanz Performance Serie #12, 2008
LUCKY TRIMMER Tanz Performance Serie #12, 2008Lucky Trimmer
 
Buitenring Brunssum de Kling
Buitenring Brunssum de KlingBuitenring Brunssum de Kling
Buitenring Brunssum de Klingde KLING
 
deetman Parkstadkrimp rapport.pdf
deetman Parkstadkrimp rapport.pdfdeetman Parkstadkrimp rapport.pdf
deetman Parkstadkrimp rapport.pdfde KLING
 
Symposium LUCKY THINKING June 2009 in Berlin
Symposium LUCKY THINKING June 2009 in BerlinSymposium LUCKY THINKING June 2009 in Berlin
Symposium LUCKY THINKING June 2009 in BerlinLucky Trimmer
 
Scrum in a nutshell for SEP HS Mannheim
Scrum in a nutshell for SEP HS MannheimScrum in a nutshell for SEP HS Mannheim
Scrum in a nutshell for SEP HS MannheimJeffrey Groneberg
 
Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276
Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276
Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276de KLING
 
Green Technology Lighting Presentation
Green Technology Lighting PresentationGreen Technology Lighting Presentation
Green Technology Lighting Presentationedanddebsmith
 
Sap Overview pdf
Sap Overview pdfSap Overview pdf
Sap Overview pdfpimporn
 

Destacado (15)

Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...
Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...
Inpassingvoorstel Buitenring Parkstad T.O..V. Wijken Klingbemden De Kling Bru...
 
Technology and Education
Technology and EducationTechnology and Education
Technology and Education
 
Fate of Ruby 1.8
Fate of Ruby 1.8Fate of Ruby 1.8
Fate of Ruby 1.8
 
An introduction to Eclipse Mylyn
An introduction to Eclipse MylynAn introduction to Eclipse Mylyn
An introduction to Eclipse Mylyn
 
Buitenring Gelijkvloerse Kruising Merkelbekerstraat
Buitenring Gelijkvloerse Kruising MerkelbekerstraatBuitenring Gelijkvloerse Kruising Merkelbekerstraat
Buitenring Gelijkvloerse Kruising Merkelbekerstraat
 
BUITENRING Bottleneck de KLING
BUITENRING Bottleneck  de KLINGBUITENRING Bottleneck  de KLING
BUITENRING Bottleneck de KLING
 
5 Jahre Lucky Trimmer Tanz Performance Serie
5 Jahre Lucky Trimmer Tanz Performance Serie5 Jahre Lucky Trimmer Tanz Performance Serie
5 Jahre Lucky Trimmer Tanz Performance Serie
 
LUCKY TRIMMER Tanz Performance Serie #12, 2008
LUCKY TRIMMER Tanz Performance Serie #12, 2008LUCKY TRIMMER Tanz Performance Serie #12, 2008
LUCKY TRIMMER Tanz Performance Serie #12, 2008
 
Buitenring Brunssum de Kling
Buitenring Brunssum de KlingBuitenring Brunssum de Kling
Buitenring Brunssum de Kling
 
deetman Parkstadkrimp rapport.pdf
deetman Parkstadkrimp rapport.pdfdeetman Parkstadkrimp rapport.pdf
deetman Parkstadkrimp rapport.pdf
 
Symposium LUCKY THINKING June 2009 in Berlin
Symposium LUCKY THINKING June 2009 in BerlinSymposium LUCKY THINKING June 2009 in Berlin
Symposium LUCKY THINKING June 2009 in Berlin
 
Scrum in a nutshell for SEP HS Mannheim
Scrum in a nutshell for SEP HS MannheimScrum in a nutshell for SEP HS Mannheim
Scrum in a nutshell for SEP HS Mannheim
 
Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276
Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276
Presentatie Inpassingsvoorstel Buitenring Parkstad Tussen N274 N276
 
Green Technology Lighting Presentation
Green Technology Lighting PresentationGreen Technology Lighting Presentation
Green Technology Lighting Presentation
 
Sap Overview pdf
Sap Overview pdfSap Overview pdf
Sap Overview pdf
 

Similar a Create *real* modular Java applications - a brief introduction -

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
 
Enterprise OSGi at eBay
Enterprise OSGi at eBayEnterprise OSGi at eBay
Enterprise OSGi at eBayTony Ng
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
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 @ Silicon Valley Code Camp 2010
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010Arun Gupta
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)David Bosschaert
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)mfrancis
 
OSGi and Java 9+
OSGi and Java 9+OSGi and Java 9+
OSGi and Java 9+bjhargrave
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutesSerge Huber
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The FactLuciano Resende
 
OSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and AndroidOSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and Androidmfrancis
 
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
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxMurugesh33
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxMurugesh33
 
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
 

Similar a Create *real* modular Java applications - a brief introduction - (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
 
Osgi Sun 20080820
Osgi Sun 20080820Osgi Sun 20080820
Osgi Sun 20080820
 
Enterprise OSGi at eBay
Enterprise OSGi at eBayEnterprise OSGi at eBay
Enterprise OSGi at eBay
 
OSGi & Blueprint
OSGi & BlueprintOSGi & Blueprint
OSGi & Blueprint
 
Osgi
OsgiOsgi
Osgi
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
OSGi introduction
OSGi introductionOSGi introduction
OSGi introduction
 
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 @ Silicon Valley Code Camp 2010
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
 
OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)OpenJDK Penrose Presentation (JavaOne 2012)
OpenJDK Penrose Presentation (JavaOne 2012)
 
OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)OSGi and Java 9+ - BJ Hargrave (IBM)
OSGi and Java 9+ - BJ Hargrave (IBM)
 
OSGi and Java 9+
OSGi and Java 9+OSGi and Java 9+
OSGi and Java 9+
 
OSGi in 5 minutes
OSGi in 5 minutesOSGi in 5 minutes
OSGi in 5 minutes
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
 
OSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and AndroidOSGi Community Event 2010 - OSGi and Android
OSGi Community Event 2010 - OSGi and Android
 
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
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
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/)
 

Último

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 

Último (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 

Create *real* modular Java applications - a brief introduction -

  • 1. OSGi Create *real* modular Java applications - a brief introduction - By Jeffrey Groneberg @inkvine jeffrey.groneberg@gmail.com
  • 2. Table of Contents •  About me •  What is OSGi? •  Class Loader – Problems with “Twins” •  It’s all about bundles •  OSGi architecture and layers •  Services, Services, Services – Micro-SOA •  Building components with OSGi –  SCR –  SpringDM •  Tools •  How to learn?
  • 4. About me •  Working at SAP AG as a developer for mobile healthcare solutions (Android & iOS) •  MSc Computer Science •  Java enthusiast •  API creator ;) •  Reading and interested in everything related to technology •  Twitter: @Inkvine •  Mail: jeffrey.groneberg@gmail.com
  • 6. What is it!? •  Actually OSGi is not a framework •  Open Service Gateway initiative •  OSGi is a specification (http://www.osgi.org/Main/HomePage) •  Originally intended to be used within the Embedded-Device-Section (Cars, Facility, Home-Environment) •  Extremely lose coupled and highly extendable (Communication via services) •  Replace modules during runtime or extend (hard- & software) •  Extremely lightweight (limited resources on embedded devices)
  • 7. Car example Uses ABS- Brakes System (Front) (v1) Fallback Uses ABS- Brakes System (BAck) (v2)
  • 8.
  • 9. Ever used ECLIPSE? •  Eclipse is completely build on OSGi •  Eclipse is running within an OSGi container •  Every time you install a plugin via “Update/Install” an OSGi bundle is downloaded and installed •  OSGi is a specification therefore Eclipse uses a special implementation •  Container = Implementation running within the JVM •  OSGi = Java ! •  Different implementations available (for different requirements)
  • 10. Different Implementations •  A spec needs to be implemented. Therefore different implementations are available on the market Name Open Source Description Equinox Yes Most spread OSGi container. Used in Eclipse and so called “reference implementation” Felix Yes Apache implementation, formerly known as “Oscar” Knoplerfish Yes Originally used within embedded systems now ported to “every day” usage. mBedded Server No Commercial implementation with official support and maintainance
  • 12. The Java Classloader approach (1/2) Bootstrap classloader Delegates to parent Parent Extension classloader Delegates to parent Parent Application Classloader
  • 13. The Java Classloader approach (2/2) •  Bootstrap classloader: all the java core libs that are located in $JAVA_HOME •  Extensions classloader: lib/ext directory •  Application classloader: all libs within the started application •  Every classloader asks his parent if he has already loaded the needed class. If he receives a “no” he has to take care of it by himself. •  No twins possible!
  • 14. JA A is stupid to identify twins V Load order A D F B C E Jar 1 Jar 2 Jar 3 Classes: First loaded – first seated!! Merged -  Different shape means different class -  Same shape means similar class (but different implementations) A D F B
  • 15. OSGi CLASSLOADER (1/2) •  “Non hierarchical” classloader •  Every component in OSGi is a bundle (JAR-file that contains metadata) •  Every bundle has its own classloader (sandbox – no sight to outer world) •  Classloader asks OSGi container for references •  If restrictions (given by the metadata) are fine the class will be provided by another component and its classloader •  --> classloader chaining
  • 16. OSGi CLASSLOADER (2/2) Class not found Component Component classloader classloader Classloader chaining (if allowed) Class loading Class resolution Class loading OSGi component OSGI component Classloader isolation
  • 18. AN osgi Bundle •  Physically it’s a JAR-File that contains: Implementations & metadata •  Metadata (the MANIFEST.mf-File within the JAR) allows fine granularly definitions of (just the most important definitions): –  What packages (classes) are needed that the bundle is able to run –  What packages (classes) are visible (and therefore exposed) to other bundles within the OSGi container –  Which version of packages the bundle exposes –  Which version of packages the bundle needs to import •  Every bundle has to be installed within the OSGi container
  • 19. EXAMPLE MANIFEST.MF Bundle-Name: Toast Emergency Bundle-SymbolicName: org.equinoxosgi.toast.client.emergency Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-Activator: org.equinoxosgi.toast.client.emergency.Activator Import-Package: org.equinoxosgi.toast.dev.airbag, org.equinoxosgi.toast.dev.gps, org.osgi.framework;
  • 20. Visibility •  Information Hiding –  Hide classes used internally and expose classes for reusability –  Encapsulate functionalities by interfaces, but hide implementations •  Best practice –  One bundle for the public API that exposes the package containing the interfaces –  One bundle for the implementation Export-Package: org.equinoxosgi.toast.dev.airbag
  • 21. Dependencies •  Declare dependencies (What is needed for the bundle to be executed) •  Versions can be added easily (“I am running on legacy code”) Import-Package: org.equinoxosgi.toast.dev.airbag, org.equinoxosgi.toast.dev.gps, org.osgi.framework;
  • 22. LIFE CYCLE AND STATES •  Every bundle has to be installed within the container •  It passes different states: –  Validating dependencies –  Exposing packages –  Checking versions •  States are: –  installed –  resolved –  Uninstalled •  A bundle has callback methods to react to the loss of dependencies –  Programmer has to take care of it
  • 24. Layers (1/2) Services Service Registry Security Bundles Lifecycle Modules JVM Operating System
  • 25. Layers (2/2) •  Security –  Adopts the Java Security Standard (optional) •  JVM –  Different JREs can be supported therefore a kind of representation needs to be provided within the OSGi container •  Modules –  All the bundles that are added to OSGi container •  Services Registry –  Functionalities can be provided within the OSGi container as services. The registry takes care of registering and exposing those services and notifies bundles that consumes those •  Services –  OSGi provides (based on the implementation) services out of the box (HTTP e.g.). •  Life Cycle Management
  • 26. Services, services, services Micro SOA
  • 27. What is a service? “A service is a normal Java object that is registered under one or more Java interfaces with the service registry. Bundles can register services, search for them, or receive notifications when their registration state changes.”
  • 28. SOA
  • 29. OSGi SOA •  Create a bundle with the interface (the public API) of your service •  Export the package containing the interface •  Create a bundle with the implementation of the interface (import the public API package) •  Reference the OSGi Service Registry and deliver your implementation for the given interface •  Reference the Service Registry and ask for an implementation for a given interface •  The implementation is always hidden to the consumer (lose coupling)
  • 30. Two WAYS of service implementations •  Program the whole registration/referencing and state change listeners by your own –  Think about it: Services can come and go or are never there. What shall your bundle do if this happens? –  A lot of code to write •  Use Inversion of Code and Dependency Injection –  SpringDM or Declarative Services (formerly known as SCR) (will be shown later)
  • 31. Doing it the hard way the service implementation
  • 32. Doing it the hard way The consumer
  • 33. DOING it the hard way THE Service Tracker (1/2)
  • 34. DOING it the hard way THE Service Tracker (2/2)
  • 35. Downsides of the hard way •  Starting time is extended due to a lot of “management” code within the activator –  Think about a lot of bundles where each bundle runs a lot of initializing code –  The application takes a lot of time to start •  Allocations during runtime –  Trackers or other “flags” needs to be initialized to handle services even though the service is never there •  Complexity •  As a programmer I do not want to take of all this stuff: –  Give me a service if it is there –  Take a service if I provide you one –  Declarations > Programming
  • 37. CHOOSE WISELY OSGi Alliance with SCR “YOU SHALL NOT PASS! UAAH!!” and btw: SpringSource “One does not simple build an iOS framework” with SpringDM
  • 38. THE SCR •  By the OSGi Alliance •  A component consumes and/or provides services •  Using the Service Component Runtime •  SCR = Declarative Services •  SCR is a bundle that is installed within the OSGi container –  Extender Pattern –  Scans all bundles for metadata containing the component definition (declaration) –  Registers provided services from bundles in the OSGi Service Registry –  Automatically binds services to consumers
  • 39. What is an OSGI SERVICE component? Bundle Bundle Component Component Component instance Component instance Component declaration Component declaration Provides Consumes Services
  • 40. SCR by example THE provider •  A component implementing a given API (interface) and registering itself as service Bundle structure Public API component.xml
  • 41. SCR BY Example THE CONSUMER •  A component consuming a service by a Public API (interface) The consumer component.xml
  • 42. SPRING DM •  From SpringSource •  A lot more than just a component declaration –  SpringMVC –  Spring Security –  AOP –  Spring WS/RS –  Dependency Injection with Beans (most powerful feature) •  Not „component“, it is called „Bean“ •  Using Extender Pattern •  Bundle within the OSGi container
  • 43. Spring DM Bundle with Spring config Bean beans1.xml Searches for beans2.xml Bean uses Bean Spring container creates Provides Consumes Spring DM Extender Configures and creates Services
  • 44. Spring DM Example The Provider Bundle structure Public API (interface) Implementation Beans declaration file OSGi service declaration
  • 45. SPRING DM EXAMPLE THE CONSUMER Consumer OSGi services declaration Beans declaration
  • 46. Tools
  • 47. What do i need (not all)? •  Eclipse (all out of the box) •  SpringSource ToolSuite (my favorite Eclipse distribution) •  Maven (bundles with bundles need other bundles, that need bundles) •  SpringSource Enterprise Repository •  Virgo –  OSGi based application server •  Tomcat –  You need an OSGi Servlet Bridge to launch the OSGi Container within a web application •  LeanDI? !
  • 49. I want to OSGI“ •  Buy the book „OSGi & Equinox“ •  Install SpringSource ToolSuite •  Install the book‘s plugin •  Work through the examples •  Buy „OSGi in Action“ as a great reference •  Buy „SpringDM in Action“ –  Pure hardcore geek food –  If you understand everything you can call yourself „the shiat“
  • 50. Great and what do I get from osgi when programming non-java“? •  Think OSGi! •  Divide API and implementation •  Hide implementations behind registries and services •  Highly reusable components (technical) •  Seperate domain from the rest of the application •  A LOT of OSGi paradigms are adopted to our EMR Android app and will „travel“ to iOS soon !
  • 52. Disclaimer •  All photos/pictures within this slides are provided from flickr.com and licenced under CC for commercial use. •  The code samples can be found in the books „OSGi & Equinox“ and „SpringDM in Action“ •  If you want to use these slides in any lecture do contact me before, pls.