SlideShare una empresa de Scribd logo
1 de 115
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

Más contenido relacionado

La actualidad más candente

Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...Angela Meeker
 
Columbus and the WordPress Community
Columbus and the WordPress CommunityColumbus and the WordPress Community
Columbus and the WordPress CommunityAngela Meeker
 
What does the browser pre-loader do?
What does the browser pre-loader do?What does the browser pre-loader do?
What does the browser pre-loader do?Andy Davies
 
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital MarketersSearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital MarketersDistilled
 
Mobile Web Performance - Getting and Staying Fast
Mobile Web Performance -  Getting and Staying FastMobile Web Performance -  Getting and Staying Fast
Mobile Web Performance - Getting and Staying FastAndy Davies
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Nicholas Zakas
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5dynamis
 
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
The Case for HTTP/2  - Internetdagarna 2015 - StockholmThe Case for HTTP/2  - Internetdagarna 2015 - Stockholm
The Case for HTTP/2 - Internetdagarna 2015 - StockholmAndy Davies
 
The Case for HTTP/2 - EpicFEL Sept 2015
The Case for HTTP/2 - EpicFEL Sept 2015The Case for HTTP/2 - EpicFEL Sept 2015
The Case for HTTP/2 - EpicFEL Sept 2015Andy Davies
 
Extending spring
Extending springExtending spring
Extending springJoshua Long
 
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...Distilled
 
Web Standards: Fueling Innovation [Web Design World Boston '08]
Web Standards: Fueling Innovation [Web Design World Boston '08]Web Standards: Fueling Innovation [Web Design World Boston '08]
Web Standards: Fueling Innovation [Web Design World Boston '08]Aaron Gustafson
 
Footprints for backlinks - Find quality backlinks in minutes
Footprints for backlinks - Find quality backlinks in minutesFootprints for backlinks - Find quality backlinks in minutes
Footprints for backlinks - Find quality backlinks in minutesSeo 4 you 2
 
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)Christopher Schmitt
 
WordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie MeekerWordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie MeekerAngela Meeker
 
Hardening WordPress - Friends of Search 2014 (WordPress Security)
Hardening WordPress - Friends of Search 2014 (WordPress Security)Hardening WordPress - Friends of Search 2014 (WordPress Security)
Hardening WordPress - Friends of Search 2014 (WordPress Security)Bastian Grimm
 
Top 5 Web Trends Of 2009 The Real Time Web
Top 5 Web Trends Of 2009  The Real Time WebTop 5 Web Trends Of 2009  The Real Time Web
Top 5 Web Trends Of 2009 The Real Time Webchmingl
 
SearchLove Boston 2018 - Bartosz Goralewicz - JavaScript: Looking Past the ...
SearchLove Boston 2018 -  Bartosz Goralewicz -  JavaScript: Looking Past the ...SearchLove Boston 2018 -  Bartosz Goralewicz -  JavaScript: Looking Past the ...
SearchLove Boston 2018 - Bartosz Goralewicz - JavaScript: Looking Past the ...Distilled
 

La actualidad más candente (20)

Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
 
Columbus and the WordPress Community
Columbus and the WordPress CommunityColumbus and the WordPress Community
Columbus and the WordPress Community
 
What does the browser pre-loader do?
What does the browser pre-loader do?What does the browser pre-loader do?
What does the browser pre-loader do?
 
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital MarketersSearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
 
Mobile Web Performance - Getting and Staying Fast
Mobile Web Performance -  Getting and Staying FastMobile Web Performance -  Getting and Staying Fast
Mobile Web Performance - Getting and Staying Fast
 
Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)Progressive Enhancement 2.0 (Conference Agnostic)
Progressive Enhancement 2.0 (Conference Agnostic)
 
What is HTML 5?
What is HTML 5?What is HTML 5?
What is HTML 5?
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
 
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
The Case for HTTP/2  - Internetdagarna 2015 - StockholmThe Case for HTTP/2  - Internetdagarna 2015 - Stockholm
The Case for HTTP/2 - Internetdagarna 2015 - Stockholm
 
The Case for HTTP/2 - EpicFEL Sept 2015
The Case for HTTP/2 - EpicFEL Sept 2015The Case for HTTP/2 - EpicFEL Sept 2015
The Case for HTTP/2 - EpicFEL Sept 2015
 
Extending spring
Extending springExtending spring
Extending spring
 
Speed Matters!
Speed Matters!Speed Matters!
Speed Matters!
 
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
 
Web Standards: Fueling Innovation [Web Design World Boston '08]
Web Standards: Fueling Innovation [Web Design World Boston '08]Web Standards: Fueling Innovation [Web Design World Boston '08]
Web Standards: Fueling Innovation [Web Design World Boston '08]
 
Footprints for backlinks - Find quality backlinks in minutes
Footprints for backlinks - Find quality backlinks in minutesFootprints for backlinks - Find quality backlinks in minutes
Footprints for backlinks - Find quality backlinks in minutes
 
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
[HEWEBAR 2012] Beyond Desktop Browsing (HTML5)
 
WordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie MeekerWordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie Meeker
 
Hardening WordPress - Friends of Search 2014 (WordPress Security)
Hardening WordPress - Friends of Search 2014 (WordPress Security)Hardening WordPress - Friends of Search 2014 (WordPress Security)
Hardening WordPress - Friends of Search 2014 (WordPress Security)
 
Top 5 Web Trends Of 2009 The Real Time Web
Top 5 Web Trends Of 2009  The Real Time WebTop 5 Web Trends Of 2009  The Real Time Web
Top 5 Web Trends Of 2009 The Real Time Web
 
SearchLove Boston 2018 - Bartosz Goralewicz - JavaScript: Looking Past the ...
SearchLove Boston 2018 -  Bartosz Goralewicz -  JavaScript: Looking Past the ...SearchLove Boston 2018 -  Bartosz Goralewicz -  JavaScript: Looking Past the ...
SearchLove Boston 2018 - Bartosz Goralewicz - JavaScript: Looking Past the ...
 

Destacado

That old Spring magic has me in its SpEL
That old Spring magic has me in its SpELThat old Spring magic has me in its SpEL
That old Spring magic has me in its SpELCraig Walls
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJoshua Long
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action Alex Movila
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Sam Brannen
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring BootJoshua Long
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCdigitalsonic
 

Destacado (17)

That old Spring magic has me in its SpEL
That old Spring magic has me in its SpELThat old Spring magic has me in its SpEL
That old Spring magic has me in its SpEL
 
Spring boot
Spring bootSpring boot
Spring boot
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
 
Boot It Up
Boot It UpBoot It Up
Boot It Up
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
 
Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
 

Similar a Modular Java - OSGi

How WordPress Frameworks actually work
How WordPress Frameworks actually workHow WordPress Frameworks actually work
How WordPress Frameworks actually workKoombea
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Edureka!
 
Selenium 4 with Simon Stewart [Webinar]
Selenium 4 with Simon Stewart [Webinar]Selenium 4 with Simon Stewart [Webinar]
Selenium 4 with Simon Stewart [Webinar]BrowserStack
 
960 grid psd
960 grid psd960 grid psd
960 grid psdRaju Nag
 
Modular Open Source in Java for Now and Later
Modular Open Source in Java for Now and LaterModular Open Source in Java for Now and Later
Modular Open Source in Java for Now and LaterBob Paulin
 
Java Fundamentals to Advance
Java Fundamentals to AdvanceJava Fundamentals to Advance
Java Fundamentals to AdvanceKrish
 
Helpful Tools and Widgets
Helpful Tools and WidgetsHelpful Tools and Widgets
Helpful Tools and WidgetsJacqui Sharp
 
Loosely Coupled Teaching with "Web 2.0" Tools (2008)
Loosely Coupled Teaching with "Web 2.0" Tools (2008)Loosely Coupled Teaching with "Web 2.0" Tools (2008)
Loosely Coupled Teaching with "Web 2.0" Tools (2008)Jared Stein
 
10 Web Performance Lessons For the 21st Century
10 Web Performance Lessons For the  21st Century10 Web Performance Lessons For the  21st Century
10 Web Performance Lessons For the 21st CenturyMateusz Kwasniewski
 
Using Web 2 Technologies For Communication And Fruitful Ministry
Using Web 2 Technologies For Communication And Fruitful MinistryUsing Web 2 Technologies For Communication And Fruitful Ministry
Using Web 2 Technologies For Communication And Fruitful MinistryRoy Yabuki
 
CloudStack University by Sebastien Goasguen
CloudStack University by Sebastien GoasguenCloudStack University by Sebastien Goasguen
CloudStack University by Sebastien Goasguenbuildacloud
 
Managing Content in Drupal with Workbench
Managing Content in Drupal with WorkbenchManaging Content in Drupal with Workbench
Managing Content in Drupal with WorkbenchAcquia
 

Similar a Modular Java - OSGi (20)

How WordPress Frameworks actually work
How WordPress Frameworks actually workHow WordPress Frameworks actually work
How WordPress Frameworks actually work
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Old Dog, New Tricks
Old Dog, New TricksOld Dog, New Tricks
Old Dog, New Tricks
 
Selenium 4 with Simon Stewart [Webinar]
Selenium 4 with Simon Stewart [Webinar]Selenium 4 with Simon Stewart [Webinar]
Selenium 4 with Simon Stewart [Webinar]
 
960 grid psd
960 grid psd960 grid psd
960 grid psd
 
Remix
RemixRemix
Remix
 
Modular Open Source in Java for Now and Later
Modular Open Source in Java for Now and LaterModular Open Source in Java for Now and Later
Modular Open Source in Java for Now and Later
 
Java Fundamentals to Advance
Java Fundamentals to AdvanceJava Fundamentals to Advance
Java Fundamentals to Advance
 
Helpful Tools and Widgets
Helpful Tools and WidgetsHelpful Tools and Widgets
Helpful Tools and Widgets
 
Loosely Coupled Teaching with "Web 2.0" Tools (2008)
Loosely Coupled Teaching with "Web 2.0" Tools (2008)Loosely Coupled Teaching with "Web 2.0" Tools (2008)
Loosely Coupled Teaching with "Web 2.0" Tools (2008)
 
10 Web Performance Lessons For the 21st Century
10 Web Performance Lessons For the  21st Century10 Web Performance Lessons For the  21st Century
10 Web Performance Lessons For the 21st Century
 
Refresh OKC
Refresh OKCRefresh OKC
Refresh OKC
 
Using Web 2 Technologies For Communication And Fruitful Ministry
Using Web 2 Technologies For Communication And Fruitful MinistryUsing Web 2 Technologies For Communication And Fruitful Ministry
Using Web 2 Technologies For Communication And Fruitful Ministry
 
CloudStack University by Sebastien Goasguen
CloudStack University by Sebastien GoasguenCloudStack University by Sebastien Goasguen
CloudStack University by Sebastien Goasguen
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Drupal for rlace
Drupal for rlaceDrupal for rlace
Drupal for rlace
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Managing Content in Drupal with Workbench
Managing Content in Drupal with WorkbenchManaging Content in Drupal with Workbench
Managing Content in Drupal with Workbench
 
Into the Box 2018 Building a PWA
Into the Box 2018 Building a PWA Into the Box 2018 Building a PWA
Into the Box 2018 Building a PWA
 
Atomic design
Atomic designAtomic design
Atomic design
 

Modular Java - OSGi

  • 1. Modular Java An Introduction to OSGi Craig Walls
  • 2. Who Am I? E-mail: craig@habuma.com 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: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. Modularity promotes... E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 9. Modularity promotes... • Testability E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 10. Modularity promotes... • Testability E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 11. Modularity promotes... • Testability • Comprehensibility E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 12. Modularity promotes... • Testability • Comprehensibility E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 13. Modularity promotes... • Testability • Comprehensibility • Flexibility E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 14. Modularity promotes... • Testability • Comprehensibility • Flexibility E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 15. Modularity promotes... • Testability • Comprehensibility • Flexibility • Reusability E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 16. Modularity promotes... • Testability • Comprehensibility • Flexibility • Reusability E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 17. 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
  • 18. Modularity in Java? E-mail: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 25. 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
  • 26. Where’s the modularity? E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 27. 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
  • 28. 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
  • 29. JAR Hell E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 30. JAR Hell E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 31. JAR/Classpath Hell E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 32. No boundaries E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 33. Building walls around JARs E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 34. Delegating classloading E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 35. Add a service registry E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 36. Publish services E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 37. Consume services E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 38. Only import service API E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 39. Only import service API OSGi! E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 40. 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
  • 42. OSGi implementations E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 43. 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
  • 44. 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
  • 45. Bundles E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 46. Bundles • Just JAR files E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 47. 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
  • 48. 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
  • 49. 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
  • 50. Bundle Lifecycle E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 51. Fragments E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 52. 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
  • 53. 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
  • 54. 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
  • 55. 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
  • 56. 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
  • 57. 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
  • 58. Versioning E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 59. 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
  • 60. 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
  • 61. 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
  • 62. Services E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 63. Services • Bundle functionality encapsulated behind services E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 64. 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
  • 65. 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
  • 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: craig@habuma.com 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: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 69. 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
  • 70. 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
  • 71. Example 1 Simple Service/Consumer using a Bundle Activator
  • 72. OSGi Blueprint Services
  • 73. 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
  • 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: craig@habuma.com 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: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 76. Blueprint vs. Spring-DM E-mail: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 81. Example 2 Service/Consumer using OSGi Blueprint Services
  • 83. 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
  • 84. 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
  • 85. Bundle Testing E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 86. 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
  • 87. 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
  • 88. 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
  • 89. 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
  • 90. Bundle Testing Options E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 91. Bundle Testing Options Spring-DM E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 92. 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
  • 93. 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
  • 94. Pax-Exam/Spring-DM Testing E-mail: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com 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: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 100. Example 3 Testing OSGi Services with Pax Exam
  • 102. Strategy E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 103. 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
  • 104. 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
  • 105. E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 106. Converting Big Apps E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 107. Converting Big Apps E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 108. Converting Big Apps E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 109. Converting Big Apps E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 110. Converting Big Apps E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 111. Dealing with Legacy JARs E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 112. Dealing with Legacy JARs • BND E-mail: craig@habuma.com Blog: http://www.springinaction.com Twitter: @habuma Slides: http://www.slideshare.net/habuma
  • 113. 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
  • 114. 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

Notas del editor