SlideShare une entreprise Scribd logo
1  sur  108
Télécharger pour lire hors ligne
OSGi Service Platform:
Java Modularity and Beyond

       Richard S. Hall

       Sun Microsystems
         Santa Clara
       August 20th, 2008
Agenda


OSGi Service Platform Overview
OSGi as a Java Modularity Layer
  Majority of the presentation
OSGi as a Service-Oriented Application Framework
Apache Felix Advertisement
Conclusion
OSGi Service Platform
      Overview
OSGi Alliance
Formerly the Open Services Gateway Initiative
Industry consortium
Defines OSGi Service Platform specification
  Two parts
     Framework specification for hosting dynamically downloadable
     services
     Standard service specifications
Several expert groups define the specifications
  Core Platform Expert Group (CPEG) – framework
  Mobile Expert Group (MEG) – mobile telephony
  Vehicle Expert Group (VEG) – automobile
  Enterprise Expert Group (EEG) – enterprise issues
  Residential Expert Group (REG) – gateway devices
OSGi Architectural Overview




                   Bundle




                                                       k
                                                   or
                                                  ew
                                             am
                                             Fr
                                    OSGi

                             Java

               Operating System

      Driver        Driver          Driver

                Hardware
OSGi Framework
Module-oriented framework
  Bundles (i.e., modules)
  Package sharing and version management
     Separate class loader per bundle
        Class loader graph, independent namespaces
  Life-cycle management and notification
Service-oriented development model
  Single JVM instance
  Publish/find/bind intra-VM service model
Open remote management architecture
  No prescribed policy or protocol
Explicit support for run-time dynamism
Java Permissions used to secure framework
OSGi Framework Layering




    Execution    L0 -
                 •OSGi Minimum Execution Environment
   Environment
         CDC     •CDC/Foundation
         CDC     •JavaSE
OSGi Framework Layering




                 L1 - Creates the concept of modules
                 (aka. bundles) that use classes from
     MODULE      each other in a controlled way
                 according to system and bundle
                 constraints


    Execution    L0 -
                 •OSGi Minimum Execution Environment
   Environment
         CDC     •CDC/Foundation
         CDC     •JavaSE
OSGi Framework Layering




                 L2 - Manages the life cycle of bundle in
     LIFECYCLE   a bundle repository without requiring
                 the VM be restarted


                 L1 - Creates the concept of modules
                 (aka. bundles) that use classes from
     MODULE      each other in a controlled way
                 according to system and bundle
                 constraints


    Execution    L0 -
                 •OSGi Minimum Execution Environment
   Environment
         CDC     •CDC/Foundation
         CDC     •JavaSE
OSGi Framework Layering


                   L3 – Provides a publish/find/bind
   SERVICE MODEL   service model to decouple bundles


                   L2 - Manages the life cycle of bundle in
     LIFECYCLE     a bundle repository without requiring
                   the VM be restarted


                   L1 - Creates the concept of modules
                   (aka. bundles) that use classes from
      MODULE       each other in a controlled way
                   according to system and bundle
                   constraints


    Execution      L0 -
                   •OSGi Minimum Execution Environment
   Environment
         CDC       •CDC/Foundation
         CDC       •JavaSE
OSGi Momentum
OSGi technology has moved beyond original target
domain
Initial success story was Eclipse RCP
More recent success stories in enterprise scenarios
  IBM
  Spring Dynamic Modules
  BEA
  Oracle
  JBoss
  JOnAS
  GlassFish
OSGi as a Java
Modularity Layer
Standard Java Modularity Limitations (1/2)
Limited scoping mechanisms
  No module access modifier
Simplistic version handling
  Class path is first version found
Implicit dependencies
  Dependencies are implicit in class path ordering
Split packages by default
  Class path approach searches until if finds, which can
  lead to shadowing or mixing of versions
Standard Java Modularity Limitations (1/2)
Limited scoping mechanisms
  No module access modifier
Simplistic version handling
  Class path is first version found
Implicit dependencies
  Dependencies are implicit in class path ordering
Split packages by default
  Class path approach searches until if finds, which can
  lead to shadowing or mixing of versions

JAR files do have some mechanisms in these
areas, but they are insufficient
Standard Java Modularity Limitations (2/2)
Low-level support for dynamics
  Class loaders are complicated to use
Unsophisticated consistency model
  Cuts across previous issues, it is difficult to ensure class
  space consistency
Missing module concept
  Classes are too fine grained, packages are too simplistic,
  class loaders are too low level
  JAR file is best candidates, but still inadequate
  Modularity is a second-class concept
Standard Java Modularity Limitations (2/2)
Low-level support for dynamics
  Class loaders are complicated to use
Unsophisticated consistency model
  Cuts across previous issues, it is difficult to ensure class
  space consistency
Missing module concept
  Classes are too fine grained, packages are too simplistic,
  class loaders are too low level
  JAR file is best candidates, but still inadequate
  Modularity is a second-class concept

To be fair, Java never intended to provide a
module layer, yet...
OSGi Framework Modularity Support
However, OSGi resolves these modularity-related
deficiencies now (and for a few years)
  OSGi bundle defines an explicit boundary for a module
  Bundle metadata explicitly declares versioned
  dependencies on other code
  Framework automatically manages bundle code
  dependencies
  Framework enforces sophisticated consistency rules for
  class loading within and among bundles
  Framework supports dynamic module life-cycle
  management
Bundle
Again, a bundle is a module in OSGi terminology
What is a bundle?
Bundle
Again, a bundle is a module in OSGi terminology
What is a bundle?
  Simply a JAR file plus module metadata
     Module metadata is stored in META-INF/MANIFEST.MF
       Defines what the module provides and requires
  What does a bundle JAR contain?
Bundle
Again, a bundle is a module in OSGi terminology
What is a bundle?
  Simply a JAR file plus module metadata
     Module metadata is stored in META-INF/MANIFEST.MF
        Defines what the module provides and requires
  What does a bundle JAR contain?
     Java classes (i.e., standard JAR file content)
     Resources (e.g., configuration files, images, etc.)
     Native code
     Embedded JAR files
        Bundles have their own class path
Bundle
Again, a bundle is a module in OSGi terminology
What is a bundle?
  Simply a JAR file plus module metadata
     Module metadata is stored in META-INF/MANIFEST.MF
        Defines what the module provides and requires
  What does a bundle JAR contain?
     Java classes (i.e., standard JAR file content)
     Resources (e.g., configuration files, images, etc.)
     Native code
     Embedded JAR files
        Bundles have their own class path
  If a bundle JAR file doesn't use advanced features, then
  it can be both a standard JAR file and a bundle at the
  same time
Bundle Life Cycle

                  install


                 INSTALLED

    uninstall                          resolve            update

                   uninstall
 UNINSTALLED                           RESOLVED

                               start


                   STARTING                        STOPPING


     explicit                                      stop

     automatic
                                          ACTIVE
Bundle Life Cycle

                  install


                 INSTALLED

    uninstall                          resolve            update

                   uninstall
 UNINSTALLED                           RESOLVED

                               start
      Resolving a bundle,
           resolves
             STARTING                              STOPPING

    its code dependencies
     explicit                                      stop

     automatic
                                          ACTIVE
Bundle Dependency Resolution
The framework automatically resolves
dependencies before a bundle is used
  Matches bundle’s requirements to providers of those
  requirements
     Package imports/exports
     Explicit bundle dependencies
     Bundle fragment dependencies
  Ensures consistency of requirements with respect to
  versions and other constraints
If a bundle cannot be successfully resolved, then it
cannot be used
Dependency Resolution Illustration
A bundle is a module contained in a JAR file




                           Provided package

                                              existing
                                              bundle


                    OSGi framework
Dependency Resolution Illustration
A bundle is a module contained in a JAR file




                                           existing
                                           bundle
   install
 bundle.jar
                    OSGi framework
Dependency Resolution Illustration
A bundle is a module contained in a JAR file




                                           existing
            resolve                        bundle
            bundle


                      OSGi framework
Dependency Resolution Illustration
A bundle is a module contained in a JAR file




                          automatic package
                        dependency resolution   existing
                                                bundle


                    OSGi framework
Package Dependencies
Be aware, bundles express dependencies in terms
of packages (typically)
  This is a somewhat novel approach
Why?
Package Dependencies
Be aware, bundles express dependencies in terms
of packages (typically)
  This is a somewhat novel approach
Why?
  Mimics import package model already known to
  developers
Package Dependencies
Be aware, bundles express dependencies in terms
of packages (typically)
  This is a somewhat novel approach
Why?
  Mimics import package model already known to
  developers
  Specifies what instead of who
     More flexible
        Can be resolved from different providers
        Providers can be refactored
Package Dependencies
Be aware, bundles express dependencies in terms
of packages (typically)
  This is a somewhat novel approach
Why?
  Mimics import package model already known to
  developers
  Specifies what instead of who
     More flexible
        Can be resolved from different providers
        Providers can be refactored
  Amenable to metadata generation
OSGi Modularity Functionality (1/7)
Multi-version support (i.e., side-by-side versions)
  Possible to have more than one version of a shared
  package in memory at the same time
  Allows multiple applications to run in the same VM or
  sub-components of a single application to depend on
  different versions of the same libraries
  Has impacts on the service-oriented aspects of the OSGi
  framework
     For a given bundle, the service registry is implicitly partitioned
     according to the package versions visible to it
OSGi Modularity Functionality (2/7)
Explicit code boundaries and dependencies
  Bundles explicitly expose internal packages (i.e., export)
     Exporters export precise package versions
  Bundles explicitly declare dependencies on external
  packages (i.e., import)
     Importers may specify an open or closed version range
OSGi Modularity Functionality (2/7)
Explicit code boundaries and dependencies
  Bundles explicitly expose internal packages (i.e., export)
     Exporters export precise package versions
  Bundles explicitly declare dependencies on external
  packages (i.e., import)
     Importers may specify an open or closed version range
  Export-Package: bar; version=quot;1.0.0quot;
  Import-Package: foo; version=quot;[1.0.0,1.5.0)quot;
OSGi Modularity Functionality (2/7)
Explicit code boundaries and dependencies
  Bundles explicitly expose internal packages (i.e., export)
     Exporters export precise package versions
  Bundles explicitly declare dependencies on external
  packages (i.e., import)
     Importers may specify an open or closed version range
   Export-Package: bar; version=quot;1.0.0quot;
   Import-Package: foo; version=quot;[1.0.0,1.5.0)quot;


Support for various sharing policies, e.g,
  Implementation package with limited backwards
  compatibility
  Specification packages with defined backwards
  compatibility
OSGi Modularity Functionality (3/7)
Arbitrary export/import attributes for more control
  Exporters may attach arbitrary attributes to their exports,
  importers can match against these arbitrary attributes
     Exporters may declare attributes as mandatory
        Mandatory attributes provide simple means to limit package visibility
  Importers influence package selection using arbitrary
  attribute matching
OSGi Modularity Functionality (3/7)
Arbitrary export/import attributes for more control
   Exporters may attach arbitrary attributes to their exports,
   importers can match against these arbitrary attributes
       Exporters may declare attributes as mandatory
           Mandatory attributes provide simple means to limit package visibility
   Importers influence package selection using arbitrary
   attribute matching


Export-Package: foo;                                  Export-Package: foo;
 version=quot;1.0.0quot;;                                      version=quot;1.0.0quot;
 myattr=quot;myvaluequot;

            foo
       A    (myattr=“myvalue”)                              foo   B
OSGi Modularity Functionality (3/7)
Arbitrary export/import attributes for more control
  Exporters may attach arbitrary attributes to their exports,
  importers can match against these arbitrary attributes
     Exporters may declare attributes as mandatory
         Mandatory attributes provide simple means to limit package visibility
  Importers influence package selection using arbitrary
  attribute matching


                          Import-Package: foo;
                           version=quot;1.0.0quot;;
                           myattr=quot;myvaluequot;

          foo
     A    (myattr=“myvalue”)   foo   C                    foo   B
OSGi Modularity Functionality (3/7)
Arbitrary export/import attributes for more control
  Exporters may attach arbitrary attributes to their exports,
  importers can match against these arbitrary attributes
     Exporters may declare attributes as mandatory
         Mandatory attributes provide simple means to limit package visibility
  Importers influence package selection using arbitrary
  attribute matching


                          Import-Package: foo;
                           version=quot;1.0.0quot;;
                           myattr=quot;myvaluequot;

          foo
     A    (myattr=“myvalue”)   foo   C                    foo   B
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies
OSGi Modularity Functionality (4/7)
 Sophisticated class space consistency model
    In addition to dependency resolution
    Exporters may declare package “uses” dependencies
        Exported packages express dependencies on imported or
        other exported packages, which constrain the resolve process
    The framework must ensure that importers do not violate
    constraints implied by “uses” dependencies


Export-Package: foo                             Export-Package: foo


       A   foo                                        foo   D
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies


                          Import-Package: foo, bar


    A   foo                      bar   C   foo     foo   D
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies

              Import-Package: foo
              Export-Package: bar;
               uses:=quot;fooquot;


    A   foo     foo   B   bar    bar   C   foo     foo   D
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies

              Import-Package: foo
              Export-Package: bar;
               uses:=quot;fooquot;


    A   foo     foo   B   bar    bar   C   foo     foo   D
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies

              Import-Package: foo
              Export-Package: bar;
               uses:=quot;fooquot;


    A   foo     foo   B   bar    bar   C   foo     foo   D
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies

              Import-Package: foo
              Export-Package: bar;
               uses:=quot;fooquot;


    A   foo     foo   B   bar    bar   C   foo     foo   D
OSGi Modularity Functionality (4/7)
Sophisticated class space consistency model
  In addition to dependency resolution
  Exporters may declare package “uses” dependencies
     Exported packages express dependencies on imported or
     other exported packages, which constrain the resolve process
  The framework must ensure that importers do not violate
  constraints implied by “uses” dependencies

              Import-Package: foo
              Export-Package: bar;
               uses:=quot;fooquot;


    A   foo     foo   B   bar    bar   C   foo     foo   D
OSGi Modularity Functionality (5/7)
Package filtering for fine-grained class visibility
  Exporters may declare that certain classes are included/
  excluded from the exported package
OSGi Modularity Functionality (5/7)
Package filtering for fine-grained class visibility
  Exporters may declare that certain classes are included/
  excluded from the exported package




                     Export-Package: foo;
                      exclude:=quot;*Implquot;,
                      foo; friend=quot;yesquot;;
                      mandatory:=quot;friendquot;


                                   A

                            foo        foo
              (exclude:=”*Impl”)       friend=“yes”
                                       (include:=”*”)
OSGi Modularity Functionality (5/7)
Package filtering for fine-grained class visibility
  Exporters may declare that certain classes are included/
  excluded from the exported package




 Import-Package: foo                              Import-Package: foo;
                                                   friend=quot;yesquot;


         B   foo                    A                    foo   C


                             foo        foo
               (exclude:=“*Impl”)       friend=“yes”
                                        (include:=”*”)
OSGi Modularity Functionality (5/7)
Package filtering for fine-grained class visibility
  Exporters may declare that certain classes are included/
  excluded from the exported package




 Import-Package: foo                              Import-Package: foo;
                                                   friend=quot;yesquot;


         B   foo                    A                    foo   C


                             foo        foo
               (exclude:=”*Impl”)       friend=“yes”
                                        (include:=”*”)
OSGi Modularity Functionality (5/7)
Package filtering for fine-grained class visibility
  Exporters may declare that certain classes are included/
  excluded from the exported package




 Import-Package: foo                              Import-Package: foo;
                                                   friend=“yes”


         B   foo                    A                    foo   C


                             foo        foo
               (exclude:=”*Impl”)       friend=“yes”
                                        (include:=”*”)
OSGi Modularity Functionality (6/7)
Bundle fragments
  Allows bundle content to be extended
  A special bundle that attaches to a host bundle and uses
  the same class loader
     Conceptually becomes part of the host bundle, allowing a
     logical bundle to be delivered in multiple physical bundles
OSGi Modularity Functionality (6/7)
Bundle fragments
  Allows bundle content to be extended
  A special bundle that attaches to a host bundle and uses
  the same class loader
     Conceptually becomes part of the host bundle, allowing a
     logical bundle to be delivered in multiple physical bundles

     Fragment-Host: B            Bundle-SymbolicName: B
     Export-Package: foo         Export-Package: bar
     Import-Package: baz         Import-Package: woz


               baz   A   foo    woz   B   bar
OSGi Modularity Functionality (6/7)
Bundle fragments
  Allows bundle content to be extended
  A special bundle that attaches to a host bundle and uses
  the same class loader
     Conceptually becomes part of the host bundle, allowing a
     logical bundle to be delivered in multiple physical bundles




                                woz   B   bar
                baz   A   foo
OSGi Modularity Functionality (6/7)
Bundle fragments
  Allows bundle content to be extended
  A special bundle that attaches to a host bundle and uses
  the same class loader
     Conceptually becomes part of the host bundle, allowing a
     logical bundle to be delivered in multiple physical bundles




                                      woz   B   bar
                      baz   A   foo
OSGi Modularity Functionality (6/7)
Bundle fragments
  Allows bundle content to be extended
  A special bundle that attaches to a host bundle and uses
  the same class loader
     Conceptually becomes part of the host bundle, allowing a
     logical bundle to be delivered in multiple physical bundles




                                       woz   B   bar
                           baz   A   foo
OSGi Modularity Functionality (6/7)
Bundle fragments
  Allows bundle content to be extended
  A special bundle that attaches to a host bundle and uses
  the same class loader
     Conceptually becomes part of the host bundle, allowing a
     logical bundle to be delivered in multiple physical bundles



                                baz                   foo

                                woz         B         bar
                                      baz   A   foo
OSGi Modularity Functionality (7/7)
Bundle dependencies
  Allows for tight coupling of bundles when required
  Import everything that another, specific bundle exports
  Allows re-exporting and split packages
OSGi Modularity Functionality (7/7)
Bundle dependencies
  Allows for tight coupling of bundles when required
  Import everything that another, specific bundle exports
  Allows re-exporting and split packages


  Bundle-SymbolicName: A      Require-Bundle: A
  Export-Package: bar, foo    Export-Package: bar
                 bar

             A   foo                  B   bar
OSGi Modularity Functionality (7/7)
Bundle dependencies
  Allows for tight coupling of bundles when required
  Import everything that another, specific bundle exports
  Allows re-exporting and split packages


  Bundle-SymbolicName: A      Require-Bundle: A
  Export-Package: bar, foo    Export-Package: bar
                 bar

             A   foo                  B   bar
OSGi Run-time Class Search Order

                      load class
                   or find resource




 belongs to a java.*        no          belongs to an           no    belongs to a package    no
                                                                          exported by a
     package?                         imported package?                 required bundle?



            yes                                yes                               yes

   delegate to                        delegate to                    delegate to exporters’              search local
parent class loader              exporter’s class loader                 class loaders                    class path



                       no        no                       yes                            no
      found?                               found?                           found?                         found?
                                                                                                   yes

     yes                                                                        yes                       no


                             lookup                                         lookup
                              failed                                      succeeded
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.foo:quot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
                 Indicates R4
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode: and syntax
              semantics
 libfoo.so; osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; osname=Linux; R4 ID
                      Indicates processor=x86,
                   Globally unique
                   semantics and syntax
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; Life cycle entry point
             osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
         Internal bundle class path
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
              Native code dependencies
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
                Optional dependency on a
 libfoo.so; osname=Linux; processor=x86,
                 package version range
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
                Provided package with
Import-Package: arbitrary attribute and
                  excluded classes
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
   resolution:=quot;optionalquot;
Export-Package:
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Bundle Manifest Example

Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.foo.simplebundle
Bundle-Version: 1.0.0
Bundle-Activator: org.foo.Activator
Bundle-ClassPath: .,org/foo/embedded.jar
Bundle-NativeCode:
 libfoo.so; osname=Linux; processor=x86,
 foo.dll; osname=Windows 98; processor=x86
Import-Package:
 osgi.service.log; version=quot;[1.0.0,1.1.0)quot;;
                      Provided package with
   resolution:=quot;optionalquot;
                     dependency on exported
Export-Package:              package
 org.foo.service; version=1.1;
   vendor=quot;org.fooquot;; exclude:=quot;*Implquot;,
 org.foo.service.bar; version=1.1;
   uses:=quot;org.foo.servicequot;
OSGi Modularity Best Practices
Partition public and non-public classes into separate
packages
  Packages with public classes can be exported
  Non-public classes are not exported
Use package imports rather than bundle
dependencies
  Allows substitutability of package providers
Limit fragment use
Avoid use of dynamic imports
  Special type of optional import that is resolved at run
  time, instead of resolve time
  Intended for Class.forName() or SPI-like use cases
OSGi Modularity Tool Support
Leveraging OSGi modularity
  Text editor + jar
     Just add metadata to your JAR file's manifest
  Eclipse
     Plug-in Development Environment directly supports bundles
  Bundle packaging tools
     BND from Peter Kriens
     Apache Felix Maven Bundle Plugin based on BND
OSGi as a Service-
Oriented Application
    Framework
Service Orientation
The OSGi framework promotes a service-oriented
interaction pattern among bundles



                    Service
                    Registry

         Publish                 Find
                    Service
                   Description


        Service                   Service
        Provider     Interact    Requester
OSGi Applications
A collection of bundles that interact via service
interfaces
  Bundles may be independently developed and deployed
  Bundles and their associated services may appear or
  disappear at any time

Resulting application follows a Service-Oriented
Component Model approach
  Combines ideas from both component and service
  orientation
Bundle Life Cycle (Revisited)

                  install


                 INSTALLED

    uninstall                          resolve            update

                   uninstall
 UNINSTALLED                           RESOLVED

                               start


                   STARTING                        STOPPING


     explicit                                      stop

     automatic
                                          ACTIVE
Bundle Life Cycle (Revisited)

                 install


     Activating a bundle allows it
           INSTALLED
     to provide and use services
    uninstall                         resolve            update

                  uninstall
 UNINSTALLED                          RESOLVED

                              start


                  STARTING                        STOPPING


     explicit                                     stop

     automatic
                                         ACTIVE
Bundle Activation
Bundles can hook into their life cycle by
implementing a bundle activator
  Notifies them when they are started/stopped
  Gives them access to their bundle context
     Which is how they access framework capabilities, e.g.,
        Bundle life cycle management
        Publishing or looking up services
Bundle Activation
Bundles can hook into their life cycle by
implementing a bundle activator
  Notifies them when they are started/stopped
  Gives them access to their bundle context
      Which is how they access framework capabilities. e.g.,
         Bundle life cycle management
         Publishing or looking up services
  Just a simple Java interface
public interface BundleActivator
{
  public void start(BundleContext context) throws Exception;
  public void stop(BundleContext context) throws Exception;
}
Service Provision Illustration
Conceptually, a bundle contains a single component
which is the bundle activator




                           Provided service


                          Provided package

                                                existing
                                                bundle
                                              component

                   OSGi framework
Service Provision Illustration
Conceptually, a bundle contains a single component
which is the bundle activator




                                          existing
                                          bundle
   install                              component
 bundle.jar
                   OSGi framework
Service Provision Illustration
Conceptually, a bundle contains a single component
which is the bundle activator




                                          existing
            activate                      bundle
            bundle                      component

                       OSGi framework
Service Provision Illustration
Conceptually, a bundle contains a single component
which is the bundle activator




                         automatic package
                       dependency resolution     existing
                                                 bundle
                                               component

                   OSGi framework
Service Provision Illustration
Conceptually, a bundle contains a single component
which is the bundle activator




                          manual service
                       dependency resolution


                                                 existing
                                                 bundle
                                               component

                   OSGi framework
Service-Oriented Applications
Moving beyond the bundle activator as a
component...
Bundles can be seen as deployment units for
component types
  These component types can be automatically
  instantiated, resolved, and managed dynamically at run
  time
Service-Oriented Applications
Moving beyond the bundle activator as a
component...
Bundles can be seen as deployment units for
component types
  These component types can be automatically
  instantiated, resolved, and managed dynamically at run
  time
This view adopts a more general service-oriented
component model approach
  Not directly supported by OSGi, but is enabled by it
  Goal is to enable a more POJO-based approach to
  creating OSGi applications
     i.e., the application code does not directly depend on OSGi
     API
Service-Oriented Application Illustration
Bundles contained component types to be
instantiated and managed




                                        existing
                                        bundle
   install                            component
 bundle.jar
                  OSGi framework
Service-Oriented Application Illustration
Bundles contained component types to be
instantiated and managed




                                         existing
           activate                      bundle
           bundle                      component

                      OSGi framework
Service-Oriented Application Illustration
Bundles contained component types to be
instantiated and managed




                                                   existing
                                                   bundle
                           automatic package     component
                         dependency resolution
                  OSGi framework
Service-Oriented Application Illustration
Bundles contained component types to be
instantiated and managed




                 instantiate
                components



                                        existing
                                        bundle
                                      component

                   OSGi framework
Service-Oriented Application Illustration
Bundles contained component types to be
instantiated and managed

        automatic service
      dependency resolution
      and maintenance with
        DS, Spring-DM, or
             iPOJO




                                           existing
                                           bundle
                                         component

                        OSGi framework
Service-Oriented Application Advantages

Lightweight services
  Direct method invocation
Structured code
  Promotes separation of interface from implementation
  Enables reuse, substitutability, loose coupling, and late
  binding
Dynamics
  Loose coupling and late binding make it possible to
  support run-time management of modules
Application's architectural configuration is defined by
the set of deployed bundles
  Just deploy the bundles that you need
Service-Oriented Application Issues
Complicated
  Requires a different way of thinking
     Things you need might not be there or go away at any moment
  Must manually resolve service dependencies
  Must track and manage service dynamics
There is help
  Service Tracker
     Still somewhat of a manual approach
     Old-fashioned approach
  Declarative Services (DS), Spring-OSGi, iPOJO
     Sophisticated service-oriented component frameworks
     Automated dependency injection
     More modern, POJO-oriented approaches
Declarative Services Example (1/2)
Declarative Services provides a minimally intrusive
way to
  Define components that provide and use services
  Automate dependency resolution and maintenance
 package foo.impl;
 public class HelloImpl implements foo.HelloService {
     LogService log;
     protected void setLog(LogService l) {
         log = l;
     }
     protected void unsetLog(LogService l) {
         log = null;
     }
     public void sayHello(String s) {
         log.log(LogService.LOG_INFO, quot;Hello quot; + s);
     }
 }
Declarative Services Example (2/2)
Declarative Services component metadata

 <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
 <component name=quot;example.helloquot;>
    <implementation class=quot;foo.impl.HelloImplquot;/>
    <service>
       <provide interface=quot;foo.HelloServicequot;/>
    </service>
    <reference name=quot;LOGquot;
     interface=quot;org.osgi.service.log.LogServicequot;
     bind=quot;setLogquot;
     unbind=quot;unsetLogquot;
    />
 </component>
iPOJO Example (1/2)
iPOJO provides an extensible POJO-based way to
  An Apache Felix sub-project
  Defines components that provide and use services
  Automates dependency resolution and maintenance
  Defines composite components with sub-service visibility
  scoping
  Uses byte-code manipulation to simplify OSGi
  programming model
iPOJO Example (2/2)
iPOJO simplifies metadata via byte-code reflection


 package foo.impl;

 @Component
 @Provides
 public class HelloImpl implements foo.HelloService {
     @Requires
     LogService log;
     public void sayHello(String s) {
         log.log(LogService.LOG_INFO, quot;Hello quot; + s);
     }
 }
OSGi Application Development Approach
Modules vs. “Modules + Services”
  It is possible to use only the modularity aspects of the
  OSGi framework and not use services as a way of
  structuring your application
  May be necessary if another component model is already
  in use or application interaction is structured differently
OSGi Application Development Approach
Modules vs. “Modules + Services”
  It is possible to use only the modularity aspects of the
  OSGi framework and not use services as a way of
  structuring your application
  May be necessary if another component model is already
  in use or application interaction is structured differently
Bundled vs. Hosted
  An application can be a set of collaborating bundles that
  can be deployed on any framework or
  An application can host an embedded instance of the
  framework to create an extensibility/plugin mechanism
     Often ties the application to a specific framework
     implementation
Apache Felix
Advertisement
Apache Felix (1/3)
Top-level Apache project
Apache licensed OSGi implementation
  Framework
    Version 1.0.4 currently available
    Completely stable and functional, but not all specification
    features implemented yet
       New 1.2.0 version expected soon
  Services
    Package Admin, Start Level, URL Handlers, Declarative
    Services, UPnP Device, HTTP Service, Configuration Admin,
    Preferences, User Admin, Wire Admin, Event Admin, Meta
    Type, and Log
    OSGi Bundle Repository (OBR), Dependency Manager,
    Service Binder, Shell (TUI and GUI), iPOJO, Mangen
Apache Felix (2/3)
Strong community
  Several regular committers and many regular
  contributors
     Very responsive community
  Code granted and contributed from several organizations
  and communities
     Grenoble University, ObjectWeb, CNR-ISTI, Ascert, Luminis,
     Apache Directory, INSA, DIT UPM, Day Management AG,
     Jayway
     Several community member contributions
Apache Felix (3/3)
Apache Maven Bundle Plugin
  Merges OSGi bundle manifest with Maven2 POM file
  Automatically generates metadata, such as Bundle-
  ClassPath, Import-Package, and Export-Package
     Greatly simplifies bundle development by eliminating error-
     prone manual header creation process
  Automatically creates final bundle JAR file
     Also supports embed required packages, instead of importing
     them
Conclusions
Conclusions
Java needs improved modularity support
  Lagging behind .NET in this area for years
  The OSGi framework provides it now
     And has a proven track record for many years
Importance and relevance of OSGi is growing
  Industry support for mobile applications
  Significant uptake in the enterprise space
     Work underway on R4.2 specification that will show the fruit of
     Java EE focus
Questions?

Contenu connexe

En vedette

developing-highly-available-dynamic-hybrid-cloud-environment
developing-highly-available-dynamic-hybrid-cloud-environmentdeveloping-highly-available-dynamic-hybrid-cloud-environment
developing-highly-available-dynamic-hybrid-cloud-environment
Tom Fieldhouse
 
Microsoft Dynamics 365 and why you need it NOW!
Microsoft Dynamics 365 and why you need it NOW!Microsoft Dynamics 365 and why you need it NOW!
Microsoft Dynamics 365 and why you need it NOW!
David Blumentals
 

En vedette (6)

Dynamic Hybrid Cloud Applications
Dynamic Hybrid Cloud ApplicationsDynamic Hybrid Cloud Applications
Dynamic Hybrid Cloud Applications
 
developing-highly-available-dynamic-hybrid-cloud-environment
developing-highly-available-dynamic-hybrid-cloud-environmentdeveloping-highly-available-dynamic-hybrid-cloud-environment
developing-highly-available-dynamic-hybrid-cloud-environment
 
Hybrid Integration with Dynamics CRM Online, Microsoft Azure Service Bus and ...
Hybrid Integration with Dynamics CRM Online, Microsoft Azure Service Bus and ...Hybrid Integration with Dynamics CRM Online, Microsoft Azure Service Bus and ...
Hybrid Integration with Dynamics CRM Online, Microsoft Azure Service Bus and ...
 
Microsoft Dynamics 365 and why you need it NOW!
Microsoft Dynamics 365 and why you need it NOW!Microsoft Dynamics 365 and why you need it NOW!
Microsoft Dynamics 365 and why you need it NOW!
 
Dynamics Day 2016 - Microsoft Dynamics 365 the future of Dynamics
Dynamics Day 2016  - Microsoft Dynamics 365 the future of DynamicsDynamics Day 2016  - Microsoft Dynamics 365 the future of Dynamics
Dynamics Day 2016 - Microsoft Dynamics 365 the future of Dynamics
 
Microsoft Dynamics CRM 2015 Pre-sales Presentation Material
Microsoft Dynamics CRM 2015 Pre-sales Presentation MaterialMicrosoft Dynamics CRM 2015 Pre-sales Presentation Material
Microsoft Dynamics CRM 2015 Pre-sales Presentation Material
 

Similaire à Osgi Sun 20080820

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
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
njbartlett
 
Enabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMEnabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDM
mukulobject
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
WSO2
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
mfrancis
 
Java 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the GalleryJava 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the Gallery
njbartlett
 

Similaire à Osgi Sun 20080820 (20)

Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGi
 
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
 
OSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE Applications using GlassFishOSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE Applications using GlassFish
 
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
 
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
 
OSGi tech session
OSGi tech sessionOSGi tech session
OSGi tech session
 
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/)
 
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil BartlettJava Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
 
Jax london 2011
Jax london 2011Jax london 2011
Jax london 2011
 
Modular Java
Modular JavaModular Java
Modular Java
 
OSGi overview
OSGi overviewOSGi overview
OSGi overview
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Part 8 - Enforcing modularity of JasForge using OSGI and Futures Evolutions
Part 8 - Enforcing modularity of JasForge using OSGI and Futures EvolutionsPart 8 - Enforcing modularity of JasForge using OSGI and Futures Evolutions
Part 8 - Enforcing modularity of JasForge using OSGI and Futures Evolutions
 
Intro To OSGi
Intro To OSGiIntro To OSGi
Intro To OSGi
 
Enabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDMEnabling modularization through OSGi and SpringDM
Enabling modularization through OSGi and SpringDM
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
Osgi Webinar
Osgi WebinarOsgi Webinar
Osgi Webinar
 
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)
 
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
Using the OSGi Application Model on Mobile Devices with CLDC JVM - Dimitar Va...
 
Java 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the GalleryJava 7 Modularity: a View from the Gallery
Java 7 Modularity: a View from the Gallery
 

Plus de Eduardo Pelegri-Llopart

Plus de Eduardo Pelegri-Llopart (20)

Juggling at freenome
Juggling   at freenomeJuggling   at freenome
Juggling at freenome
 
Csumb capstone-fall2016
Csumb capstone-fall2016Csumb capstone-fall2016
Csumb capstone-fall2016
 
Digital activitymanagement
Digital activitymanagementDigital activitymanagement
Digital activitymanagement
 
Progress next iot_pelegri
Progress next iot_pelegriProgress next iot_pelegri
Progress next iot_pelegri
 
Pelegri Desarrollando en una nueva era de software
Pelegri   Desarrollando en una nueva era de software Pelegri   Desarrollando en una nueva era de software
Pelegri Desarrollando en una nueva era de software
 
Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015
 
The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015
 
IOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ ProgressIOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ Progress
 
Node.js as an IOT Bridge
Node.js as an IOT BridgeNode.js as an IOT Bridge
Node.js as an IOT Bridge
 
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
 
What is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouWhat is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts You
 
Community Update 25 Mar2010 - English
Community Update 25 Mar2010 - EnglishCommunity Update 25 Mar2010 - English
Community Update 25 Mar2010 - English
 
GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010
 
Glass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.MiniGlass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.Mini
 
Virtual Box Aquarium May09
Virtual Box Aquarium May09Virtual Box Aquarium May09
Virtual Box Aquarium May09
 
Introduction To Web Beans
Introduction To Web BeansIntroduction To Web Beans
Introduction To Web Beans
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage Patterns
 
OpenDS Primer Aquarium
OpenDS Primer AquariumOpenDS Primer Aquarium
OpenDS Primer Aquarium
 
Fuji Overview
Fuji OverviewFuji Overview
Fuji Overview
 
Nuxeo 5.2 Glassfish
Nuxeo 5.2 GlassfishNuxeo 5.2 Glassfish
Nuxeo 5.2 Glassfish
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Osgi Sun 20080820

  • 1. OSGi Service Platform: Java Modularity and Beyond Richard S. Hall Sun Microsystems Santa Clara August 20th, 2008
  • 2. Agenda OSGi Service Platform Overview OSGi as a Java Modularity Layer Majority of the presentation OSGi as a Service-Oriented Application Framework Apache Felix Advertisement Conclusion
  • 4. OSGi Alliance Formerly the Open Services Gateway Initiative Industry consortium Defines OSGi Service Platform specification Two parts Framework specification for hosting dynamically downloadable services Standard service specifications Several expert groups define the specifications Core Platform Expert Group (CPEG) – framework Mobile Expert Group (MEG) – mobile telephony Vehicle Expert Group (VEG) – automobile Enterprise Expert Group (EEG) – enterprise issues Residential Expert Group (REG) – gateway devices
  • 5. OSGi Architectural Overview Bundle k or ew am Fr OSGi Java Operating System Driver Driver Driver Hardware
  • 6. OSGi Framework Module-oriented framework Bundles (i.e., modules) Package sharing and version management Separate class loader per bundle Class loader graph, independent namespaces Life-cycle management and notification Service-oriented development model Single JVM instance Publish/find/bind intra-VM service model Open remote management architecture No prescribed policy or protocol Explicit support for run-time dynamism Java Permissions used to secure framework
  • 7. OSGi Framework Layering Execution L0 - •OSGi Minimum Execution Environment Environment CDC •CDC/Foundation CDC •JavaSE
  • 8. OSGi Framework Layering L1 - Creates the concept of modules (aka. bundles) that use classes from MODULE each other in a controlled way according to system and bundle constraints Execution L0 - •OSGi Minimum Execution Environment Environment CDC •CDC/Foundation CDC •JavaSE
  • 9. OSGi Framework Layering L2 - Manages the life cycle of bundle in LIFECYCLE a bundle repository without requiring the VM be restarted L1 - Creates the concept of modules (aka. bundles) that use classes from MODULE each other in a controlled way according to system and bundle constraints Execution L0 - •OSGi Minimum Execution Environment Environment CDC •CDC/Foundation CDC •JavaSE
  • 10. OSGi Framework Layering L3 – Provides a publish/find/bind SERVICE MODEL service model to decouple bundles L2 - Manages the life cycle of bundle in LIFECYCLE a bundle repository without requiring the VM be restarted L1 - Creates the concept of modules (aka. bundles) that use classes from MODULE each other in a controlled way according to system and bundle constraints Execution L0 - •OSGi Minimum Execution Environment Environment CDC •CDC/Foundation CDC •JavaSE
  • 11. OSGi Momentum OSGi technology has moved beyond original target domain Initial success story was Eclipse RCP More recent success stories in enterprise scenarios IBM Spring Dynamic Modules BEA Oracle JBoss JOnAS GlassFish
  • 12. OSGi as a Java Modularity Layer
  • 13. Standard Java Modularity Limitations (1/2) Limited scoping mechanisms No module access modifier Simplistic version handling Class path is first version found Implicit dependencies Dependencies are implicit in class path ordering Split packages by default Class path approach searches until if finds, which can lead to shadowing or mixing of versions
  • 14. Standard Java Modularity Limitations (1/2) Limited scoping mechanisms No module access modifier Simplistic version handling Class path is first version found Implicit dependencies Dependencies are implicit in class path ordering Split packages by default Class path approach searches until if finds, which can lead to shadowing or mixing of versions JAR files do have some mechanisms in these areas, but they are insufficient
  • 15. Standard Java Modularity Limitations (2/2) Low-level support for dynamics Class loaders are complicated to use Unsophisticated consistency model Cuts across previous issues, it is difficult to ensure class space consistency Missing module concept Classes are too fine grained, packages are too simplistic, class loaders are too low level JAR file is best candidates, but still inadequate Modularity is a second-class concept
  • 16. Standard Java Modularity Limitations (2/2) Low-level support for dynamics Class loaders are complicated to use Unsophisticated consistency model Cuts across previous issues, it is difficult to ensure class space consistency Missing module concept Classes are too fine grained, packages are too simplistic, class loaders are too low level JAR file is best candidates, but still inadequate Modularity is a second-class concept To be fair, Java never intended to provide a module layer, yet...
  • 17. OSGi Framework Modularity Support However, OSGi resolves these modularity-related deficiencies now (and for a few years) OSGi bundle defines an explicit boundary for a module Bundle metadata explicitly declares versioned dependencies on other code Framework automatically manages bundle code dependencies Framework enforces sophisticated consistency rules for class loading within and among bundles Framework supports dynamic module life-cycle management
  • 18. Bundle Again, a bundle is a module in OSGi terminology What is a bundle?
  • 19. Bundle Again, a bundle is a module in OSGi terminology What is a bundle? Simply a JAR file plus module metadata Module metadata is stored in META-INF/MANIFEST.MF Defines what the module provides and requires What does a bundle JAR contain?
  • 20. Bundle Again, a bundle is a module in OSGi terminology What is a bundle? Simply a JAR file plus module metadata Module metadata is stored in META-INF/MANIFEST.MF Defines what the module provides and requires What does a bundle JAR contain? Java classes (i.e., standard JAR file content) Resources (e.g., configuration files, images, etc.) Native code Embedded JAR files Bundles have their own class path
  • 21. Bundle Again, a bundle is a module in OSGi terminology What is a bundle? Simply a JAR file plus module metadata Module metadata is stored in META-INF/MANIFEST.MF Defines what the module provides and requires What does a bundle JAR contain? Java classes (i.e., standard JAR file content) Resources (e.g., configuration files, images, etc.) Native code Embedded JAR files Bundles have their own class path If a bundle JAR file doesn't use advanced features, then it can be both a standard JAR file and a bundle at the same time
  • 22. Bundle Life Cycle install INSTALLED uninstall resolve update uninstall UNINSTALLED RESOLVED start STARTING STOPPING explicit stop automatic ACTIVE
  • 23. Bundle Life Cycle install INSTALLED uninstall resolve update uninstall UNINSTALLED RESOLVED start Resolving a bundle, resolves STARTING STOPPING its code dependencies explicit stop automatic ACTIVE
  • 24. Bundle Dependency Resolution The framework automatically resolves dependencies before a bundle is used Matches bundle’s requirements to providers of those requirements Package imports/exports Explicit bundle dependencies Bundle fragment dependencies Ensures consistency of requirements with respect to versions and other constraints If a bundle cannot be successfully resolved, then it cannot be used
  • 25. Dependency Resolution Illustration A bundle is a module contained in a JAR file Provided package existing bundle OSGi framework
  • 26. Dependency Resolution Illustration A bundle is a module contained in a JAR file existing bundle install bundle.jar OSGi framework
  • 27. Dependency Resolution Illustration A bundle is a module contained in a JAR file existing resolve bundle bundle OSGi framework
  • 28. Dependency Resolution Illustration A bundle is a module contained in a JAR file automatic package dependency resolution existing bundle OSGi framework
  • 29. Package Dependencies Be aware, bundles express dependencies in terms of packages (typically) This is a somewhat novel approach Why?
  • 30. Package Dependencies Be aware, bundles express dependencies in terms of packages (typically) This is a somewhat novel approach Why? Mimics import package model already known to developers
  • 31. Package Dependencies Be aware, bundles express dependencies in terms of packages (typically) This is a somewhat novel approach Why? Mimics import package model already known to developers Specifies what instead of who More flexible Can be resolved from different providers Providers can be refactored
  • 32. Package Dependencies Be aware, bundles express dependencies in terms of packages (typically) This is a somewhat novel approach Why? Mimics import package model already known to developers Specifies what instead of who More flexible Can be resolved from different providers Providers can be refactored Amenable to metadata generation
  • 33. OSGi Modularity Functionality (1/7) Multi-version support (i.e., side-by-side versions) Possible to have more than one version of a shared package in memory at the same time Allows multiple applications to run in the same VM or sub-components of a single application to depend on different versions of the same libraries Has impacts on the service-oriented aspects of the OSGi framework For a given bundle, the service registry is implicitly partitioned according to the package versions visible to it
  • 34. OSGi Modularity Functionality (2/7) Explicit code boundaries and dependencies Bundles explicitly expose internal packages (i.e., export) Exporters export precise package versions Bundles explicitly declare dependencies on external packages (i.e., import) Importers may specify an open or closed version range
  • 35. OSGi Modularity Functionality (2/7) Explicit code boundaries and dependencies Bundles explicitly expose internal packages (i.e., export) Exporters export precise package versions Bundles explicitly declare dependencies on external packages (i.e., import) Importers may specify an open or closed version range Export-Package: bar; version=quot;1.0.0quot; Import-Package: foo; version=quot;[1.0.0,1.5.0)quot;
  • 36. OSGi Modularity Functionality (2/7) Explicit code boundaries and dependencies Bundles explicitly expose internal packages (i.e., export) Exporters export precise package versions Bundles explicitly declare dependencies on external packages (i.e., import) Importers may specify an open or closed version range Export-Package: bar; version=quot;1.0.0quot; Import-Package: foo; version=quot;[1.0.0,1.5.0)quot; Support for various sharing policies, e.g, Implementation package with limited backwards compatibility Specification packages with defined backwards compatibility
  • 37. OSGi Modularity Functionality (3/7) Arbitrary export/import attributes for more control Exporters may attach arbitrary attributes to their exports, importers can match against these arbitrary attributes Exporters may declare attributes as mandatory Mandatory attributes provide simple means to limit package visibility Importers influence package selection using arbitrary attribute matching
  • 38. OSGi Modularity Functionality (3/7) Arbitrary export/import attributes for more control Exporters may attach arbitrary attributes to their exports, importers can match against these arbitrary attributes Exporters may declare attributes as mandatory Mandatory attributes provide simple means to limit package visibility Importers influence package selection using arbitrary attribute matching Export-Package: foo; Export-Package: foo; version=quot;1.0.0quot;; version=quot;1.0.0quot; myattr=quot;myvaluequot; foo A (myattr=“myvalue”) foo B
  • 39. OSGi Modularity Functionality (3/7) Arbitrary export/import attributes for more control Exporters may attach arbitrary attributes to their exports, importers can match against these arbitrary attributes Exporters may declare attributes as mandatory Mandatory attributes provide simple means to limit package visibility Importers influence package selection using arbitrary attribute matching Import-Package: foo; version=quot;1.0.0quot;; myattr=quot;myvaluequot; foo A (myattr=“myvalue”) foo C foo B
  • 40. OSGi Modularity Functionality (3/7) Arbitrary export/import attributes for more control Exporters may attach arbitrary attributes to their exports, importers can match against these arbitrary attributes Exporters may declare attributes as mandatory Mandatory attributes provide simple means to limit package visibility Importers influence package selection using arbitrary attribute matching Import-Package: foo; version=quot;1.0.0quot;; myattr=quot;myvaluequot; foo A (myattr=“myvalue”) foo C foo B
  • 41. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies
  • 42. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Export-Package: foo Export-Package: foo A foo foo D
  • 43. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Import-Package: foo, bar A foo bar C foo foo D
  • 44. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Import-Package: foo Export-Package: bar; uses:=quot;fooquot; A foo foo B bar bar C foo foo D
  • 45. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Import-Package: foo Export-Package: bar; uses:=quot;fooquot; A foo foo B bar bar C foo foo D
  • 46. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Import-Package: foo Export-Package: bar; uses:=quot;fooquot; A foo foo B bar bar C foo foo D
  • 47. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Import-Package: foo Export-Package: bar; uses:=quot;fooquot; A foo foo B bar bar C foo foo D
  • 48. OSGi Modularity Functionality (4/7) Sophisticated class space consistency model In addition to dependency resolution Exporters may declare package “uses” dependencies Exported packages express dependencies on imported or other exported packages, which constrain the resolve process The framework must ensure that importers do not violate constraints implied by “uses” dependencies Import-Package: foo Export-Package: bar; uses:=quot;fooquot; A foo foo B bar bar C foo foo D
  • 49. OSGi Modularity Functionality (5/7) Package filtering for fine-grained class visibility Exporters may declare that certain classes are included/ excluded from the exported package
  • 50. OSGi Modularity Functionality (5/7) Package filtering for fine-grained class visibility Exporters may declare that certain classes are included/ excluded from the exported package Export-Package: foo; exclude:=quot;*Implquot;, foo; friend=quot;yesquot;; mandatory:=quot;friendquot; A foo foo (exclude:=”*Impl”) friend=“yes” (include:=”*”)
  • 51. OSGi Modularity Functionality (5/7) Package filtering for fine-grained class visibility Exporters may declare that certain classes are included/ excluded from the exported package Import-Package: foo Import-Package: foo; friend=quot;yesquot; B foo A foo C foo foo (exclude:=“*Impl”) friend=“yes” (include:=”*”)
  • 52. OSGi Modularity Functionality (5/7) Package filtering for fine-grained class visibility Exporters may declare that certain classes are included/ excluded from the exported package Import-Package: foo Import-Package: foo; friend=quot;yesquot; B foo A foo C foo foo (exclude:=”*Impl”) friend=“yes” (include:=”*”)
  • 53. OSGi Modularity Functionality (5/7) Package filtering for fine-grained class visibility Exporters may declare that certain classes are included/ excluded from the exported package Import-Package: foo Import-Package: foo; friend=“yes” B foo A foo C foo foo (exclude:=”*Impl”) friend=“yes” (include:=”*”)
  • 54. OSGi Modularity Functionality (6/7) Bundle fragments Allows bundle content to be extended A special bundle that attaches to a host bundle and uses the same class loader Conceptually becomes part of the host bundle, allowing a logical bundle to be delivered in multiple physical bundles
  • 55. OSGi Modularity Functionality (6/7) Bundle fragments Allows bundle content to be extended A special bundle that attaches to a host bundle and uses the same class loader Conceptually becomes part of the host bundle, allowing a logical bundle to be delivered in multiple physical bundles Fragment-Host: B Bundle-SymbolicName: B Export-Package: foo Export-Package: bar Import-Package: baz Import-Package: woz baz A foo woz B bar
  • 56. OSGi Modularity Functionality (6/7) Bundle fragments Allows bundle content to be extended A special bundle that attaches to a host bundle and uses the same class loader Conceptually becomes part of the host bundle, allowing a logical bundle to be delivered in multiple physical bundles woz B bar baz A foo
  • 57. OSGi Modularity Functionality (6/7) Bundle fragments Allows bundle content to be extended A special bundle that attaches to a host bundle and uses the same class loader Conceptually becomes part of the host bundle, allowing a logical bundle to be delivered in multiple physical bundles woz B bar baz A foo
  • 58. OSGi Modularity Functionality (6/7) Bundle fragments Allows bundle content to be extended A special bundle that attaches to a host bundle and uses the same class loader Conceptually becomes part of the host bundle, allowing a logical bundle to be delivered in multiple physical bundles woz B bar baz A foo
  • 59. OSGi Modularity Functionality (6/7) Bundle fragments Allows bundle content to be extended A special bundle that attaches to a host bundle and uses the same class loader Conceptually becomes part of the host bundle, allowing a logical bundle to be delivered in multiple physical bundles baz foo woz B bar baz A foo
  • 60. OSGi Modularity Functionality (7/7) Bundle dependencies Allows for tight coupling of bundles when required Import everything that another, specific bundle exports Allows re-exporting and split packages
  • 61. OSGi Modularity Functionality (7/7) Bundle dependencies Allows for tight coupling of bundles when required Import everything that another, specific bundle exports Allows re-exporting and split packages Bundle-SymbolicName: A Require-Bundle: A Export-Package: bar, foo Export-Package: bar bar A foo B bar
  • 62. OSGi Modularity Functionality (7/7) Bundle dependencies Allows for tight coupling of bundles when required Import everything that another, specific bundle exports Allows re-exporting and split packages Bundle-SymbolicName: A Require-Bundle: A Export-Package: bar, foo Export-Package: bar bar A foo B bar
  • 63. OSGi Run-time Class Search Order load class or find resource belongs to a java.* no belongs to an no belongs to a package no exported by a package? imported package? required bundle? yes yes yes delegate to delegate to delegate to exporters’ search local parent class loader exporter’s class loader class loaders class path no no yes no found? found? found? found? yes yes yes no lookup lookup failed succeeded
  • 64. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.foo:quot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 65. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Indicates R4 Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: and syntax semantics libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 66. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; osname=Linux; R4 ID Indicates processor=x86, Globally unique semantics and syntax foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 67. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; Life cycle entry point osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 68. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Internal bundle class path Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 69. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Native code dependencies Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 70. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: Optional dependency on a libfoo.so; osname=Linux; processor=x86, package version range foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 71. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Provided package with Import-Package: arbitrary attribute and excluded classes osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; resolution:=quot;optionalquot; Export-Package: org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 72. OSGi Bundle Manifest Example Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.foo.simplebundle Bundle-Version: 1.0.0 Bundle-Activator: org.foo.Activator Bundle-ClassPath: .,org/foo/embedded.jar Bundle-NativeCode: libfoo.so; osname=Linux; processor=x86, foo.dll; osname=Windows 98; processor=x86 Import-Package: osgi.service.log; version=quot;[1.0.0,1.1.0)quot;; Provided package with resolution:=quot;optionalquot; dependency on exported Export-Package: package org.foo.service; version=1.1; vendor=quot;org.fooquot;; exclude:=quot;*Implquot;, org.foo.service.bar; version=1.1; uses:=quot;org.foo.servicequot;
  • 73. OSGi Modularity Best Practices Partition public and non-public classes into separate packages Packages with public classes can be exported Non-public classes are not exported Use package imports rather than bundle dependencies Allows substitutability of package providers Limit fragment use Avoid use of dynamic imports Special type of optional import that is resolved at run time, instead of resolve time Intended for Class.forName() or SPI-like use cases
  • 74. OSGi Modularity Tool Support Leveraging OSGi modularity Text editor + jar Just add metadata to your JAR file's manifest Eclipse Plug-in Development Environment directly supports bundles Bundle packaging tools BND from Peter Kriens Apache Felix Maven Bundle Plugin based on BND
  • 75. OSGi as a Service- Oriented Application Framework
  • 76. Service Orientation The OSGi framework promotes a service-oriented interaction pattern among bundles Service Registry Publish Find Service Description Service Service Provider Interact Requester
  • 77. OSGi Applications A collection of bundles that interact via service interfaces Bundles may be independently developed and deployed Bundles and their associated services may appear or disappear at any time Resulting application follows a Service-Oriented Component Model approach Combines ideas from both component and service orientation
  • 78. Bundle Life Cycle (Revisited) install INSTALLED uninstall resolve update uninstall UNINSTALLED RESOLVED start STARTING STOPPING explicit stop automatic ACTIVE
  • 79. Bundle Life Cycle (Revisited) install Activating a bundle allows it INSTALLED to provide and use services uninstall resolve update uninstall UNINSTALLED RESOLVED start STARTING STOPPING explicit stop automatic ACTIVE
  • 80. Bundle Activation Bundles can hook into their life cycle by implementing a bundle activator Notifies them when they are started/stopped Gives them access to their bundle context Which is how they access framework capabilities, e.g., Bundle life cycle management Publishing or looking up services
  • 81. Bundle Activation Bundles can hook into their life cycle by implementing a bundle activator Notifies them when they are started/stopped Gives them access to their bundle context Which is how they access framework capabilities. e.g., Bundle life cycle management Publishing or looking up services Just a simple Java interface public interface BundleActivator { public void start(BundleContext context) throws Exception; public void stop(BundleContext context) throws Exception; }
  • 82. Service Provision Illustration Conceptually, a bundle contains a single component which is the bundle activator Provided service Provided package existing bundle component OSGi framework
  • 83. Service Provision Illustration Conceptually, a bundle contains a single component which is the bundle activator existing bundle install component bundle.jar OSGi framework
  • 84. Service Provision Illustration Conceptually, a bundle contains a single component which is the bundle activator existing activate bundle bundle component OSGi framework
  • 85. Service Provision Illustration Conceptually, a bundle contains a single component which is the bundle activator automatic package dependency resolution existing bundle component OSGi framework
  • 86. Service Provision Illustration Conceptually, a bundle contains a single component which is the bundle activator manual service dependency resolution existing bundle component OSGi framework
  • 87. Service-Oriented Applications Moving beyond the bundle activator as a component... Bundles can be seen as deployment units for component types These component types can be automatically instantiated, resolved, and managed dynamically at run time
  • 88. Service-Oriented Applications Moving beyond the bundle activator as a component... Bundles can be seen as deployment units for component types These component types can be automatically instantiated, resolved, and managed dynamically at run time This view adopts a more general service-oriented component model approach Not directly supported by OSGi, but is enabled by it Goal is to enable a more POJO-based approach to creating OSGi applications i.e., the application code does not directly depend on OSGi API
  • 89. Service-Oriented Application Illustration Bundles contained component types to be instantiated and managed existing bundle install component bundle.jar OSGi framework
  • 90. Service-Oriented Application Illustration Bundles contained component types to be instantiated and managed existing activate bundle bundle component OSGi framework
  • 91. Service-Oriented Application Illustration Bundles contained component types to be instantiated and managed existing bundle automatic package component dependency resolution OSGi framework
  • 92. Service-Oriented Application Illustration Bundles contained component types to be instantiated and managed instantiate components existing bundle component OSGi framework
  • 93. Service-Oriented Application Illustration Bundles contained component types to be instantiated and managed automatic service dependency resolution and maintenance with DS, Spring-DM, or iPOJO existing bundle component OSGi framework
  • 94. Service-Oriented Application Advantages Lightweight services Direct method invocation Structured code Promotes separation of interface from implementation Enables reuse, substitutability, loose coupling, and late binding Dynamics Loose coupling and late binding make it possible to support run-time management of modules Application's architectural configuration is defined by the set of deployed bundles Just deploy the bundles that you need
  • 95. Service-Oriented Application Issues Complicated Requires a different way of thinking Things you need might not be there or go away at any moment Must manually resolve service dependencies Must track and manage service dynamics There is help Service Tracker Still somewhat of a manual approach Old-fashioned approach Declarative Services (DS), Spring-OSGi, iPOJO Sophisticated service-oriented component frameworks Automated dependency injection More modern, POJO-oriented approaches
  • 96. Declarative Services Example (1/2) Declarative Services provides a minimally intrusive way to Define components that provide and use services Automate dependency resolution and maintenance package foo.impl; public class HelloImpl implements foo.HelloService { LogService log; protected void setLog(LogService l) { log = l; } protected void unsetLog(LogService l) { log = null; } public void sayHello(String s) { log.log(LogService.LOG_INFO, quot;Hello quot; + s); } }
  • 97. Declarative Services Example (2/2) Declarative Services component metadata <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> <component name=quot;example.helloquot;> <implementation class=quot;foo.impl.HelloImplquot;/> <service> <provide interface=quot;foo.HelloServicequot;/> </service> <reference name=quot;LOGquot; interface=quot;org.osgi.service.log.LogServicequot; bind=quot;setLogquot; unbind=quot;unsetLogquot; /> </component>
  • 98. iPOJO Example (1/2) iPOJO provides an extensible POJO-based way to An Apache Felix sub-project Defines components that provide and use services Automates dependency resolution and maintenance Defines composite components with sub-service visibility scoping Uses byte-code manipulation to simplify OSGi programming model
  • 99. iPOJO Example (2/2) iPOJO simplifies metadata via byte-code reflection package foo.impl; @Component @Provides public class HelloImpl implements foo.HelloService { @Requires LogService log; public void sayHello(String s) { log.log(LogService.LOG_INFO, quot;Hello quot; + s); } }
  • 100. OSGi Application Development Approach Modules vs. “Modules + Services” It is possible to use only the modularity aspects of the OSGi framework and not use services as a way of structuring your application May be necessary if another component model is already in use or application interaction is structured differently
  • 101. OSGi Application Development Approach Modules vs. “Modules + Services” It is possible to use only the modularity aspects of the OSGi framework and not use services as a way of structuring your application May be necessary if another component model is already in use or application interaction is structured differently Bundled vs. Hosted An application can be a set of collaborating bundles that can be deployed on any framework or An application can host an embedded instance of the framework to create an extensibility/plugin mechanism Often ties the application to a specific framework implementation
  • 103. Apache Felix (1/3) Top-level Apache project Apache licensed OSGi implementation Framework Version 1.0.4 currently available Completely stable and functional, but not all specification features implemented yet New 1.2.0 version expected soon Services Package Admin, Start Level, URL Handlers, Declarative Services, UPnP Device, HTTP Service, Configuration Admin, Preferences, User Admin, Wire Admin, Event Admin, Meta Type, and Log OSGi Bundle Repository (OBR), Dependency Manager, Service Binder, Shell (TUI and GUI), iPOJO, Mangen
  • 104. Apache Felix (2/3) Strong community Several regular committers and many regular contributors Very responsive community Code granted and contributed from several organizations and communities Grenoble University, ObjectWeb, CNR-ISTI, Ascert, Luminis, Apache Directory, INSA, DIT UPM, Day Management AG, Jayway Several community member contributions
  • 105. Apache Felix (3/3) Apache Maven Bundle Plugin Merges OSGi bundle manifest with Maven2 POM file Automatically generates metadata, such as Bundle- ClassPath, Import-Package, and Export-Package Greatly simplifies bundle development by eliminating error- prone manual header creation process Automatically creates final bundle JAR file Also supports embed required packages, instead of importing them
  • 107. Conclusions Java needs improved modularity support Lagging behind .NET in this area for years The OSGi framework provides it now And has a proven track record for many years Importance and relevance of OSGi is growing Industry support for mobile applications Significant uptake in the enterprise space Work underway on R4.2 specification that will show the fruit of Java EE focus