Modular Java
An Introduction to OSGi

        Craig Walls
Who Am I?




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Who Am I?
                  Java, Spring, and OSGi fanatic
           Principal Consultant with                                                                          .
                                                   Author
                                        XDoclet in Action (Manning)

                                         Spring in Action (Manning)

                                  Modular Java (Pragmatic Bookshelf)




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
What is OSGi?
OSGi is...



             A modularity specification for Java



                                     An intra-VM SOA




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
OSGi is NOT...

                                                       New
                                           Heavyweight
                                                 Difficult
                                      Only for Eclipse
                                    EJB all over again
                                            An acronym
                                     Named very cool

  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity is...
• High cohesion
 • Modules are focused in purpose
• Low coupling
 • Modules have minimal/no direct dependency on
     each other
• Not a new idea...
  “A well-defined segmentation of the project effort ensures system modularity.
  Each task forms a separate, distinct program module. At implementation time
  each module and its inputs and outputs are well-defined, there is no confusion
  in the intended interface with other system modules. At checkout time the integrity
  of the module is tested independently; there are few scheduling problems in
  synchronizing the completion of several tasks before checkout can begin. Finally,
  the system is maintained in modular fashion; system errors and deficiencies can
  be traced to specific system modules, thus limiting the scope of detailed error
  searching.”
         Designing Systems Programs, Richard Gauthier and Stephen Pont, 1970.

    E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility
• Flexibility



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility
• Flexibility



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility
• Flexibility
• Reusability

   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility
• Flexibility
• Reusability

   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity promotes...
• Testability
• Comprehensibility
• Flexibility
• Reusability
• Plugability
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?


• Java lacks some essential features to
  support modular development




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?


• Java lacks some essential features to
  support modular development
 • Classes encapsulate data and functionality




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?


• Java lacks some essential features to
  support modular development
 • Classes encapsulate data and functionality
   •    They’re too fine-grained for practical modularity




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?


• Java lacks some essential features to
  support modular development
 • Classes encapsulate data and functionality
   •    They’re too fine-grained for practical modularity


 • Packages only contain classes



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?


• Java lacks some essential features to
  support modular development
 • Classes encapsulate data and functionality
   •    They’re too fine-grained for practical modularity


 • Packages only contain classes
   •    They’re only an organizational mechanism




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Modularity in Java?


• Java lacks some essential features to
  support modular development
 • Classes encapsulate data and functionality
   •    They’re too fine-grained for practical modularity


 • Packages only contain classes
   •    They’re only an organizational mechanism


 • JAR files only contain packages/classes

   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
JAR Files: A false sense of modularity




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Where’s the modularity?




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Where’s the modularity?
public class MyAwesomeClass {
  public void doSomething() {
    FooInternal foo = new FooInternal();
    // ...
  }
}




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Where’s the modularity?
public class MyAwesomeClass {
  public void doSomething() {
    FooInternal foo = new FooInternal();
    // ...
  }
}




  /**
   * Intended for INTERNAL USE ONLY!!!
   * Do not use directly!!!
   */
  class FooInternal { ... }
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
JAR Hell




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
JAR Hell




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
JAR/Classpath Hell




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
No boundaries




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Building walls around JARs




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Delegating classloading




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Add a service registry




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Publish services




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Consume services




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Only import service API




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Only import service API




 OSGi!
  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
The solution...OSGi


• Dynamic Runtime
 • Modules can be installed, started, stopped,
   updated, and uninstalled...in a live program

• Ends JAR Hell
 • Multiple versions of a class can reside in OSGi
   simultaneously



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
OSGi Basics
OSGi implementations




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
OSGi implementations

• Open Source
 • Eclipse Equinox                         (http://www.eclipse.org/equinox)


 • Apache Felix                     (http://felix.apache.org)


 • Knopflerfish                      (http://www.knopflerfish.org)


 • Concierge                  (http://concierge.sourceforge.net/)




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
OSGi implementations

• Open Source
 • Eclipse Equinox                         (http://www.eclipse.org/equinox)


 • Apache Felix                     (http://felix.apache.org)


 • Knopflerfish                      (http://www.knopflerfish.org)


 • Concierge                  (http://concierge.sourceforge.net/)


• Commercial
 • Makewave Knopflerfish Pro                                              (http://www.makewave.com)


 • ProSyst mBedded Server                                         (http://www.prosyst.com)


 • Samsung OSGi R4 Solution
 • HitachiSoft SuperJ Engine Framework
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundles




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundles

• Just JAR files




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundles

• Just JAR files
• Contain special metadata in MANIFEST.MF




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundles

• Just JAR files
• Contain special metadata in MANIFEST.MF
• All content is private by default
 • May export packages to be imported by other
   bundles

 • May publish services


   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundles

• Just JAR files
• Contain special metadata in MANIFEST.MF
• All content is private by default
 • May export packages to be imported by other
   bundles

 • May publish services
• May be versioned
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Lifecycle




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Fragments




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Fragments


• Just JAR files, like bundles, but...




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Fragments


• Just JAR files, like bundles, but...
• Must be hosted by another bundle




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Fragments


• Just JAR files, like bundles, but...
• Must be hosted by another bundle
• Physically separate, logically united



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Fragments


• Just JAR files, like bundles, but...
• Must be hosted by another bundle
• Physically separate, logically united
• Used to add content (classes, resources,
  etc) to a hosting bundle



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
OSGi Manifest

• Defines the content of a bundle
  Manifest-Version: 1.0
  Built-By: wallsc
  Created-By: Apache Maven Bundle Plugin
  Bundle-Activator: com.osgiknowhow.hello.consumer.internal.HelloConsumerActivator
  Import-Package: com.osgiknowhow.hello.service;version="1.0.0.SNAPSHOT",
   org.osgi.framework,org.osgi.util.tracker
  Bnd-LastModified: 1236686261405
  Bundle-Version: 1.0.0.SNAPSHOT
  Ignore-Package: com.osgiknowhow.hello.consumer.internal
  Bundle-Name: com.osgiknowhow.hello.consumer
  Bundle-Description: Generated using Pax-Construct
  Build-Jdk: 1.5.0_16
  Private-Package: com.osgiknowhow.hello.consumer.internal
  Bundle-ManifestVersion: 2
  Bundle-SymbolicName: com.osgiknowhow.hello.consumer
  Tool: Bnd-0.0.255


• Don’t ever write this file yourself
 • Generate it (see Bnd, Bundlor, etc)
    E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Manifest headers
                        Bundle-SymbolicName

                                 Bundle-Version

                                 Import-Package

                                 Export-Package

                             Bundle-Activator

  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Versioning




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Versioning

• Bundles and packages can be versioned
 • Can even be versioned independent from each
   other




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Versioning

• Bundles and packages can be versioned
 • Can even be versioned independent from each
   other

• Multiple versions can be available
  simultaneously




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Versioning

• Bundles and packages can be versioned
 • Can even be versioned independent from each
   other

• Multiple versions can be available
  simultaneously

• Packages can be imported by specifying a
  specific version, a version range, or no
  version at all (implying an infinite version
  range)

   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Services




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Services
• Bundle functionality encapsulated behind
  services




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Services
• Bundle functionality encapsulated behind
  services

• Bundles can publish/consume services
 • Identified by their interface(s) and optional
   parameters

 • Publish programatically using bundle context
 • Consume programatically using bundle context
   and service tracker




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Services
• Bundle functionality encapsulated behind
  services

• Bundles can publish/consume services
 • Identified by their interface(s) and optional
   parameters

 • Publish programatically using bundle context
 • Consume programatically using bundle context
   and service tracker

• Can be published/consumed declaratively
 • Declarative Services, iPOJO, Spring-DM
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Example Time
OSGi Tools Disclaimer

• My OSGi toolbox includes
 • Maven
 • Pax Construct
 • BND
 • TextMate (and Eclipse)
• You don’t have to use what I use
 • There are a lot of options to choose from
 • Ant with BND also works fine
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Just enough Maven...


• For the most part, you’ll only ever need...
 • mvn install
• Occasionally you may need...
 • mvn test
 • mvn clean

   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax Construct

• Rails/Grails/Roo-ish model
 • Scripts backed by Maven archetypes
• Key Pax Construct scripts:
 • pax-create-project
 • pax-create-bundle
 • pax-provision
 • pax-import-bundle
 • pax-add-repository
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
BND
• A giant in a small JAR
 • Can be used as an Ant task
 • Can be used as an Eclipse plugin
 • Can be used at the command line
• Automatically infers much of a manifest
 • Can be coerced, if necessary
 • BND instructions can take wildcards!
• It’s the magic underneath the Felix Maven
  Bundle Plugin
 • Which is some of the magic underneath Pax
   Construct
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Example 1

Simple Service/Consumer using a
       Bundle Activator
OSGi Blueprint
  Services
In the beginning (circa 2006)


                          OSGi Declarative Services


                          Spring Dynamic Modules


                                                      iPOJO



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Publishing a Service
                       In OSGI-INF/blueprint/*.xml:
<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/
blueprint-ext/v1.0.0"
    default-activation="lazy">

   <bean id="numberService" class=
       "com.habuma.numbers.internal.NumberToEnglishServiceImpl" />

   <service ref="numberService"
       interface="com.habuma.numbers.NumberToEnglishService" />

</blueprint>




      E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Consuming a Service
                       In OSGI-INF/blueprint/*.xml:
<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/
blueprint-ext/v1.0.0"
    default-activation="lazy">

   <bean id="numberService"
         class="com.habuma.numbers.ui.NumberConverterUI" />

   <reference id="numberService"
       interface="com.habuma.numbers.NumberToEnglishService" />

</blueprint>




      E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Blueprint vs. Spring-DM




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Blueprint vs. Spring-DM
 Spring-DM implements Blueprint Services




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Blueprint vs. Spring-DM
 Spring-DM implements Blueprint Services


  Spring-DM isn’t the only implementation




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Blueprint vs. Spring-DM
 Spring-DM implements Blueprint Services


  Spring-DM isn’t the only implementation


 If you want/need the power of Spring, then
               use Spring-DM




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Blueprint vs. Spring-DM
 Spring-DM implements Blueprint Services


  Spring-DM isn’t the only implementation


 If you want/need the power of Spring, then
               use Spring-DM


 Otherwise, any implementation of Blueprint
              Services will do
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Example 2

Service/Consumer using OSGi
     Blueprint Services
Testing OSGi
Levels of Testing



                                                    Unit
                                          Integration
                                  User Acceptance
                                           Functional




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Levels of Testing


                                                    Unit
                                          Integration
                                                Bundle
                                  User Acceptance
                                           Functional



  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing
• Does the bundle export what it’s supposed
  to?




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing
• Does the bundle export what it’s supposed
  to?

• Does the bundle publish the services that
  it’s supposed to?




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing
• Does the bundle export what it’s supposed
  to?

• Does the bundle publish the services that
  it’s supposed to?

• Does the bundle’s service(s) behave like
  they’re supposed to?




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing
• Does the bundle export what it’s supposed
  to?

• Does the bundle publish the services that
  it’s supposed to?

• Does the bundle’s service(s) behave like
  they’re supposed to?

• Does the bundle get along with other
  bundles?
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing Options




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing Options

                                          Spring-DM




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing Options

                                          Spring-DM


                                            Pax Exam




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Bundle Testing Options

                                          Spring-DM


                                            Pax Exam


                                         DA-Testing
                                           (dynamicjava.org)




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax-Exam/Spring-DM Testing




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax-Exam/Spring-DM Testing
                             Written as JUnit Test




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax-Exam/Spring-DM Testing
                             Written as JUnit Test

       JUnit 3 for Spring-DM; JUnit 4 for Pax Exam




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax-Exam/Spring-DM Testing
                              Written as JUnit Test

        JUnit 3 for Spring-DM; JUnit 4 for Pax Exam

Test setup identifies one or more bundles and
       an OSGi framework to deploy to




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax-Exam/Spring-DM Testing
                              Written as JUnit Test

        JUnit 3 for Spring-DM; JUnit 4 for Pax Exam

Test setup identifies one or more bundles and
       an OSGi framework to deploy to

    Test methods make assertions against
            bundles and services



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Pax-Exam/Spring-DM Testing
                              Written as JUnit Test

        JUnit 3 for Spring-DM; JUnit 4 for Pax Exam

Test setup identifies one or more bundles and
       an OSGi framework to deploy to

    Test methods make assertions against
            bundles and services

When run, test becomes an on-the-fly bundle
       running within the framework
   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Example 3

Testing OSGi Services with Pax Exam
Moving to OSGi
Strategy




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Strategy


1. Convert full app into one large bundle
 a. Embed JARs (Use Bundle-ClassPath)
 b. Add Bundle-SymbolicName




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Strategy


1. Convert full app into one large bundle
 a. Embed JARs (Use Bundle-ClassPath)
 b. Add Bundle-SymbolicName

2. Peel off dependencies one-by-one
 a. Start with 3rd party libraries
 b. Pull out proprietary modules



   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Converting Big Apps




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Converting Big Apps




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Converting Big Apps




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Converting Big Apps




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Converting Big Apps




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Dealing with Legacy JARs




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Dealing with Legacy JARs

• BND




  E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Dealing with Legacy JARs

• BND
• Pax Construct:
 • pax-wrap-jar or pax-embed-jar




   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Dealing with Legacy JARs

• BND
• Pax Construct:
 • pax-wrap-jar or pax-embed-jar
• Find them in a bundle repository
 • OBR
   •    http://www.osgi.org/Repository


 • SpringSource Enterprise Bundle Repository
   •    http://www.springsource.com/repository


   E-mail: craig@habuma.com Blog: http://www.springinaction.com   Twitter: @habuma Slides: http://www.slideshare.net/habuma
Thank You

Modular Java - OSGi

  • 1.
    Modular Java An Introductionto OSGi Craig Walls
  • 2.
    Who Am I? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 3.
    Who Am I? Java, Spring, and OSGi fanatic Principal Consultant with . Author XDoclet in Action (Manning) Spring in Action (Manning) Modular Java (Pragmatic Bookshelf) E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 4.
  • 5.
    OSGi is... A modularity specification for Java An intra-VM SOA E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 6.
    OSGi is NOT... New Heavyweight Difficult Only for Eclipse EJB all over again An acronym Named very cool E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 7.
    Modularity is... • Highcohesion • Modules are focused in purpose • Low coupling • Modules have minimal/no direct dependency on each other • Not a new idea... “A well-defined segmentation of the project effort ensures system modularity. Each task forms a separate, distinct program module. At implementation time each module and its inputs and outputs are well-defined, there is no confusion in the intended interface with other system modules. At checkout time the integrity of the module is tested independently; there are few scheduling problems in synchronizing the completion of several tasks before checkout can begin. Finally, the system is maintained in modular fashion; system errors and deficiencies can be traced to specific system modules, thus limiting the scope of detailed error searching.” Designing Systems Programs, Richard Gauthier and Stephen Pont, 1970. E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 8.
    Modularity promotes... E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 9.
    Modularity promotes... • Testability E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 10.
    Modularity promotes... • Testability E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 11.
    Modularity promotes... • Testability •Comprehensibility E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 12.
    Modularity promotes... • Testability •Comprehensibility E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 13.
    Modularity promotes... • Testability •Comprehensibility • Flexibility E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 14.
    Modularity promotes... • Testability •Comprehensibility • Flexibility E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 15.
    Modularity promotes... • Testability •Comprehensibility • Flexibility • Reusability E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 16.
    Modularity promotes... • Testability •Comprehensibility • Flexibility • Reusability E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 17.
    Modularity promotes... • Testability •Comprehensibility • Flexibility • Reusability • Plugability E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 18.
    Modularity in Java? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 19.
    Modularity in Java? •Java lacks some essential features to support modular development E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 20.
    Modularity in Java? •Java lacks some essential features to support modular development • Classes encapsulate data and functionality E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 21.
    Modularity in Java? •Java lacks some essential features to support modular development • Classes encapsulate data and functionality • They’re too fine-grained for practical modularity E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 22.
    Modularity in Java? •Java lacks some essential features to support modular development • Classes encapsulate data and functionality • They’re too fine-grained for practical modularity • Packages only contain classes E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 23.
    Modularity in Java? •Java lacks some essential features to support modular development • Classes encapsulate data and functionality • They’re too fine-grained for practical modularity • Packages only contain classes • They’re only an organizational mechanism E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 24.
    Modularity in Java? •Java lacks some essential features to support modular development • Classes encapsulate data and functionality • They’re too fine-grained for practical modularity • Packages only contain classes • They’re only an organizational mechanism • JAR files only contain packages/classes E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 25.
    JAR Files: Afalse sense of modularity E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 26.
    Where’s the modularity? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 27.
    Where’s the modularity? publicclass MyAwesomeClass { public void doSomething() { FooInternal foo = new FooInternal(); // ... } } E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 28.
    Where’s the modularity? publicclass MyAwesomeClass { public void doSomething() { FooInternal foo = new FooInternal(); // ... } } /** * Intended for INTERNAL USE ONLY!!! * Do not use directly!!! */ class FooInternal { ... } E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 29.
    JAR Hell E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 30.
    JAR Hell E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 31.
    JAR/Classpath Hell E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 32.
    No boundaries E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 33.
    Building walls aroundJARs E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 34.
    Delegating classloading E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 35.
    Add a serviceregistry E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 36.
    Publish services E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 37.
    Consume services E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 38.
    Only import serviceAPI E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 39.
    Only import serviceAPI OSGi! E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 40.
    The solution...OSGi • DynamicRuntime • Modules can be installed, started, stopped, updated, and uninstalled...in a live program • Ends JAR Hell • Multiple versions of a class can reside in OSGi simultaneously E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 41.
  • 42.
    OSGi implementations E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 43.
    OSGi implementations • OpenSource • Eclipse Equinox (http://www.eclipse.org/equinox) • Apache Felix (http://felix.apache.org) • Knopflerfish (http://www.knopflerfish.org) • Concierge (http://concierge.sourceforge.net/) E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 44.
    OSGi implementations • OpenSource • Eclipse Equinox (http://www.eclipse.org/equinox) • Apache Felix (http://felix.apache.org) • Knopflerfish (http://www.knopflerfish.org) • Concierge (http://concierge.sourceforge.net/) • Commercial • Makewave Knopflerfish Pro (http://www.makewave.com) • ProSyst mBedded Server (http://www.prosyst.com) • Samsung OSGi R4 Solution • HitachiSoft SuperJ Engine Framework E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 45.
    Bundles E-mail:[email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 46.
    Bundles • Just JARfiles E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 47.
    Bundles • Just JARfiles • Contain special metadata in MANIFEST.MF E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 48.
    Bundles • Just JARfiles • Contain special metadata in MANIFEST.MF • All content is private by default • May export packages to be imported by other bundles • May publish services E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 49.
    Bundles • Just JARfiles • Contain special metadata in MANIFEST.MF • All content is private by default • May export packages to be imported by other bundles • May publish services • May be versioned E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 50.
    Bundle Lifecycle E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 51.
    Fragments E-mail:[email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 52.
    Fragments • Just JARfiles, like bundles, but... E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 53.
    Fragments • Just JARfiles, like bundles, but... • Must be hosted by another bundle E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 54.
    Fragments • Just JARfiles, like bundles, but... • Must be hosted by another bundle • Physically separate, logically united E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 55.
    Fragments • Just JARfiles, like bundles, but... • Must be hosted by another bundle • Physically separate, logically united • Used to add content (classes, resources, etc) to a hosting bundle E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 56.
    OSGi Manifest • Definesthe content of a bundle Manifest-Version: 1.0 Built-By: wallsc Created-By: Apache Maven Bundle Plugin Bundle-Activator: com.osgiknowhow.hello.consumer.internal.HelloConsumerActivator Import-Package: com.osgiknowhow.hello.service;version="1.0.0.SNAPSHOT", org.osgi.framework,org.osgi.util.tracker Bnd-LastModified: 1236686261405 Bundle-Version: 1.0.0.SNAPSHOT Ignore-Package: com.osgiknowhow.hello.consumer.internal Bundle-Name: com.osgiknowhow.hello.consumer Bundle-Description: Generated using Pax-Construct Build-Jdk: 1.5.0_16 Private-Package: com.osgiknowhow.hello.consumer.internal Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.osgiknowhow.hello.consumer Tool: Bnd-0.0.255 • Don’t ever write this file yourself • Generate it (see Bnd, Bundlor, etc) E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 57.
    Manifest headers Bundle-SymbolicName Bundle-Version Import-Package Export-Package Bundle-Activator E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 58.
    Versioning E-mail:[email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 59.
    Versioning • Bundles andpackages can be versioned • Can even be versioned independent from each other E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 60.
    Versioning • Bundles andpackages can be versioned • Can even be versioned independent from each other • Multiple versions can be available simultaneously E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 61.
    Versioning • Bundles andpackages can be versioned • Can even be versioned independent from each other • Multiple versions can be available simultaneously • Packages can be imported by specifying a specific version, a version range, or no version at all (implying an infinite version range) E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 62.
    Services E-mail:[email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 63.
    Services • Bundle functionalityencapsulated behind services E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 64.
    Services • Bundle functionalityencapsulated behind services • Bundles can publish/consume services • Identified by their interface(s) and optional parameters • Publish programatically using bundle context • Consume programatically using bundle context and service tracker E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 65.
    Services • Bundle functionalityencapsulated behind services • Bundles can publish/consume services • Identified by their interface(s) and optional parameters • Publish programatically using bundle context • Consume programatically using bundle context and service tracker • Can be published/consumed declaratively • Declarative Services, iPOJO, Spring-DM E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 66.
  • 67.
    OSGi Tools Disclaimer •My OSGi toolbox includes • Maven • Pax Construct • BND • TextMate (and Eclipse) • You don’t have to use what I use • There are a lot of options to choose from • Ant with BND also works fine E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 68.
    Just enough Maven... •For the most part, you’ll only ever need... • mvn install • Occasionally you may need... • mvn test • mvn clean E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 69.
    Pax Construct • Rails/Grails/Roo-ishmodel • Scripts backed by Maven archetypes • Key Pax Construct scripts: • pax-create-project • pax-create-bundle • pax-provision • pax-import-bundle • pax-add-repository E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 70.
    BND • A giantin a small JAR • Can be used as an Ant task • Can be used as an Eclipse plugin • Can be used at the command line • Automatically infers much of a manifest • Can be coerced, if necessary • BND instructions can take wildcards! • It’s the magic underneath the Felix Maven Bundle Plugin • Which is some of the magic underneath Pax Construct E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 71.
    Example 1 Simple Service/Consumerusing a Bundle Activator
  • 72.
  • 73.
    In the beginning(circa 2006) OSGi Declarative Services Spring Dynamic Modules iPOJO E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 74.
    Publishing a Service In OSGI-INF/blueprint/*.xml: <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/ blueprint-ext/v1.0.0" default-activation="lazy"> <bean id="numberService" class= "com.habuma.numbers.internal.NumberToEnglishServiceImpl" /> <service ref="numberService" interface="com.habuma.numbers.NumberToEnglishService" /> </blueprint> E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 75.
    Consuming a Service In OSGI-INF/blueprint/*.xml: <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:ext="http://geronimo.apache.org/blueprint/xmlns/ blueprint-ext/v1.0.0" default-activation="lazy"> <bean id="numberService" class="com.habuma.numbers.ui.NumberConverterUI" /> <reference id="numberService" interface="com.habuma.numbers.NumberToEnglishService" /> </blueprint> E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 76.
    Blueprint vs. Spring-DM E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 77.
    Blueprint vs. Spring-DM Spring-DM implements Blueprint Services E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 78.
    Blueprint vs. Spring-DM Spring-DM implements Blueprint Services Spring-DM isn’t the only implementation E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 79.
    Blueprint vs. Spring-DM Spring-DM implements Blueprint Services Spring-DM isn’t the only implementation If you want/need the power of Spring, then use Spring-DM E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 80.
    Blueprint vs. Spring-DM Spring-DM implements Blueprint Services Spring-DM isn’t the only implementation If you want/need the power of Spring, then use Spring-DM Otherwise, any implementation of Blueprint Services will do E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 81.
    Example 2 Service/Consumer usingOSGi Blueprint Services
  • 82.
  • 83.
    Levels of Testing Unit Integration User Acceptance Functional E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 84.
    Levels of Testing Unit Integration Bundle User Acceptance Functional E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 85.
    Bundle Testing E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 86.
    Bundle Testing • Doesthe bundle export what it’s supposed to? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 87.
    Bundle Testing • Doesthe bundle export what it’s supposed to? • Does the bundle publish the services that it’s supposed to? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 88.
    Bundle Testing • Doesthe bundle export what it’s supposed to? • Does the bundle publish the services that it’s supposed to? • Does the bundle’s service(s) behave like they’re supposed to? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 89.
    Bundle Testing • Doesthe bundle export what it’s supposed to? • Does the bundle publish the services that it’s supposed to? • Does the bundle’s service(s) behave like they’re supposed to? • Does the bundle get along with other bundles? E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 90.
    Bundle Testing Options E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 91.
    Bundle Testing Options Spring-DM E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 92.
    Bundle Testing Options Spring-DM Pax Exam E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 93.
    Bundle Testing Options Spring-DM Pax Exam DA-Testing (dynamicjava.org) E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 94.
    Pax-Exam/Spring-DM Testing E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 95.
    Pax-Exam/Spring-DM Testing Written as JUnit Test E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 96.
    Pax-Exam/Spring-DM Testing Written as JUnit Test JUnit 3 for Spring-DM; JUnit 4 for Pax Exam E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 97.
    Pax-Exam/Spring-DM Testing Written as JUnit Test JUnit 3 for Spring-DM; JUnit 4 for Pax Exam Test setup identifies one or more bundles and an OSGi framework to deploy to E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 98.
    Pax-Exam/Spring-DM Testing Written as JUnit Test JUnit 3 for Spring-DM; JUnit 4 for Pax Exam Test setup identifies one or more bundles and an OSGi framework to deploy to Test methods make assertions against bundles and services E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 99.
    Pax-Exam/Spring-DM Testing Written as JUnit Test JUnit 3 for Spring-DM; JUnit 4 for Pax Exam Test setup identifies one or more bundles and an OSGi framework to deploy to Test methods make assertions against bundles and services When run, test becomes an on-the-fly bundle running within the framework E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 100.
    Example 3 Testing OSGiServices with Pax Exam
  • 101.
  • 102.
    Strategy E-mail:[email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 103.
    Strategy 1. Convert fullapp into one large bundle a. Embed JARs (Use Bundle-ClassPath) b. Add Bundle-SymbolicName E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 104.
    Strategy 1. Convert fullapp into one large bundle a. Embed JARs (Use Bundle-ClassPath) b. Add Bundle-SymbolicName 2. Peel off dependencies one-by-one a. Start with 3rd party libraries b. Pull out proprietary modules E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 105.
    E-mail: [email protected] Blog:http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 106.
    Converting Big Apps E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 107.
    Converting Big Apps E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 108.
    Converting Big Apps E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 109.
    Converting Big Apps E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 110.
    Converting Big Apps E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 111.
    Dealing with LegacyJARs E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 112.
    Dealing with LegacyJARs • BND E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 113.
    Dealing with LegacyJARs • BND • Pax Construct: • pax-wrap-jar or pax-embed-jar E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 114.
    Dealing with LegacyJARs • BND • Pax Construct: • pax-wrap-jar or pax-embed-jar • Find them in a bundle repository • OBR • http://www.osgi.org/Repository • SpringSource Enterprise Bundle Repository • http://www.springsource.com/repository E-mail: [email protected] Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 115.