Enterprise Applications with OSGi
           and SpringSource dm Server

                                  Eberhard Wolff – SpringSource
                                    Sam Brannen – OpenCredo

                          Jazoon – 24 June 2009 – Zürich, Switzerland




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
Eberhard.Wolff (@) SpringSource.com
   • Regional Director of German speaking
     countries and Principal Consultant
   • Author of several articles and books
   • First German book on Spring
   • Speaker at national and international
     conferences
   • Blog: http://jandiandme.blogspot.com/




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   2
SpringSource
   • Employs most committers for Spring
   • Committers for Tomcat, ActiveMQ, Apache
     HTTP
   • New: tc Server / dm Server
   • Groovy / Grails
   • Hyperic

   • Training
   • Consulting
   • Subscription / Support
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   3
Sam.Brannen (@) OpenCredo.com
   • Software Consultant
   • Spring Framework Core Developer
   • Previous SpringSource dm Server developer:
     OSGi-enabled Web deployment models,
     Tomcat integration, Test Framework
   • Java developer with 10+ years' experience
   • Regular speaker at conferences on Spring, dm
     Server, Java, and testing
   • Co-author of Spring in a Nutshell; chief
     technical reviewer for Spring Recipes


Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   4
Open Credo
   • Experts in Open Source application
     development
   • Consulting
   • Coaching
   • Management Training
   • Committers for numerous Spring projects
             – Spring Framework
             – Spring Integration
             – Spring .NET



Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   5
Why another Application Server?




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
OSGi’s Promise of Modularity
   • Modularization is key to maintainable
     software
   • Application Server itself is modularized
             – No more "one size fits all"
             – Java EE 6 introduces profiles
   • On the client and in the embedded world
     OSGi has succeeded as a standard for
     modularization
   • OSGi enters the enterprise server market…


Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   7
Building on OSGi
   • Almost all app server vendors base their
     systems on OSGi (JBoss, Sun, Oracle, IBM)
   • But none offers OSGi as a programming
     model for the customer

   • Why shouldn't the customer be as
     empowered as the app server vendor?
   • Enter SpringSource dm Server…



Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   8
OSGi




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
It's a module system
   • Partition a system into a number of modules –
     "bundles"

   • Dynamic: bundles can be installed, started,
     stopped, uninstalled and updated
             – ...at runtime
   • better operations

   • Strict visibility rules
   • Resolution process satisfies dependencies of a
     module
   • Understands versioning

Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   10
It's even service-oriented
   • Bundles can publish services…
     dynamically!

   • Service Registry allows other bundles to
     consume services

   • Services come and go at runtime
             – … transparently when using Spring-DM




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   11
OSGi Bundle
   • The fundamental unit of deployment and
     modularity in OSGi
   • Just a JAR file
             – with additional entries in META-INF/MANIFEST.MF
   • Common manifest headers:
             –     Bundle-SymbolicName
             –     Bundle-Version
             –     Bundle-Name
             –     Bundle-ManifestVersion
             –     Bundle-Vendor




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   12
Export & Import Packages
   Declare package-level visibility and
   dependencies of your bundle.

   Export-Package: com.xyz.bar
   Export-Package: com.xyz.bar;version="1.0.5"
   Import-Package: com.xyz.foo
   Import-Package:                  >= 1.0.3; e.g.,
     com.xyz.foo;version="1.0.3"    1.0.3, 1.0.3.GA,
   Import-Package:                  1.0.4, 2.0, etc.

     com.xyz.foo;version="[1.0.3,1.0.3]"
   Import-Package:
     com.xyz.foo;version="[1.0.3,1.1.0)",
     com.xyz.bar;version="[1.0.3,2.0.0)"
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   13
Publish a Service

              ServiceRegistration reg =
                bundleContext.registerService(
                 Bar.class.getName(),
               myBarService);
              ...
              reg.unregister();




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   14
Consume a Service
   ServiceReference ref =
     bundleContext.getServiceReference(
      Bar.class.getName());
     Bar bar = (Bar)
       bundleContext.getService(ref);
     ...
     bundleContext.ungetService(ref);
     // bar should no longer be used here

                     Complex… Potential resource leaks!
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   15
OSGi in the Enterprise




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
OSGi as a Server Platform

                                   Web
                                 Application

                                                Enterprise Server Bundles

                                    Web                            Transaction                              ...                            OSGi
                                  Container                        Management                                                            Application




                                                                                 Features might be
                                                                                 added on demand



                                                                       OSGi Service Platform




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.                 17
OSGi for Enterprise Applications
   • Dynamic services are hard to develop
     (boiler plate code)
   • Basic infrastructure for OSGi + Web has to
     be done by yourself
   • What do we do about WARs?
   • How do you keep a service or type from
     leaking out of an application?
             – The notion of an application does not exist in
               OSGi…
   • Many enterprise libraries are not suited for
     OSGi
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   18
Enterprise Libraries under OSGi
   • Class and resource loading problems
             – class visibility
             – context class loader is undefined in OSGi
             – resources in META-INF
             –…


   • Not directly supported: libraries with
     multiple bundles




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   19
Example: Class Visibility


                                                                            Data Layer
                                                                             Data Layer
                                                                              Bundle
                                                                               Bundle

                 Import-Package                                                                                         Import-Package


                                      Domain Model
                                       Domain Model                                                           Hibernate
                                                                                                               Hibernate
                                         Bundle
                                          Bundle                                                               Bundle
                                                                                                                Bundle
                                      <Export-Pkg>
                                       <Export-Pkg>                                                         <Export-Pkg>
                                                                                                             <Export-Pkg>
  Domain
  types &                                                                                                                                SessionFactory
  mapping
  files

Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.               20
Good News for OSGi in the Enterprise
   • Spring 2.5 and many other Spring projects
     are OSGi-ready
             – modules shipped as bundles
             – all class loading behaves correctly under OSGi


   • Hundreds of other enterprise libraries are
     now also packaged for use under OSGi in
     the SpringSource Enterprise Bundle
     Repository



Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   21
Spring Dynamic Modules &
                  SpringSource dm Server




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
Spring-DM: ApplicationContext
   • Configuration files in /META-INF/spring
   • Automatically merged
   • ..and an ApplicationContext is created
      – one per Bundle


   • Spring-DM manages the
     ApplicationContext lifecycle
   • OSGi manages the Bundle lifecycle



Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   23
Spring-DM: Service Registry (1/2)
                           Contrast with
  <beans ...>            programmatic API
    <osgi:service ref="customerDAO"
      interface="dao.ICustomerDAO" />
    <osgi:reference id="dataSource"
      interface="javax.sql.DataSource" />
  </beans>

  Also supports filters, listeners, collections (lists
  and sets), etc.

Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   24
Spring-DM: Service Registry (2/2)
   • Dynamic services handled automatically
             – Instances and collections are proxied
             – Method calls are buffered
             – Configurable timeouts
   • Purely declarative




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   25
Out-of-scope for Spring-DM
   •      Easy import of bundles and libraries
   •      Using JPA or Hibernate in OSGi
   •      Seamless Web support
   •      Notion of an application



   • Enter SpringSource dm Server…




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   26
dm Server Platform
• Built on Equinox
• Modular architecture
   –Subsystems
   –Bundles
• Small footprint
• Modular profiles
• Bundle repository
• Library provisioning
• Serviceability
   –FFDC
   –Logging
   –Tracing



 Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   27
Importing & Exporting Types
   • Plain OSGi + …
   • Import-Library and Import-Bundle
             – Library imports bundle imports
             – Bundle imports  package imports
             – OSGi runtime semantics remain the same

   Import-Library:
          org.springframework.spring;
          version="[2.5.6,3.0)"
   Import-Bundle:
          com.springsource.org.hibernate;
          version="[3.2.6.ga,3.2.6.ga]"
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   28
Example Application Bundles
   • Web
                                                                                                                  Export                  Web
   • Service
   • API                                                                                                         Import
             – Only interfaces and                                                                                                        API
               domain classes
             – Implementation can
               be exchanged                                                                                                              Service

   • Could add
     infrastructure: data
     source, transaction
     manager, etc.
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.             29
Bundles & Types
   • Only dependencies on the API
             – Implementation can be exchanged, …
               even at runtime
   • No direct dependencies on any
     implementation
   • Not shown: dependencies on external
     bundles
   • … can be installed in dm Server
   • … modular middleware!


Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   30
Bundles & Services
                                                                                                                                         Service
    Type:                                                                Web                                                             Registry
    Import                                                                                                               consume



    Services:                                                API
    Publish /
    Consume                                                                                                                publish
                                                                       Service




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.              31
Bundles & Services
   • Infrastructure can use the same principle as
     application services
             – DataSource and PlatformTransactionManager
               are just services


   Can I still run on plain Java EE?
   • Yes: instead of OSGi Service directly inject
     Spring Beans
   • No more dynamic services / modularization
   • No code change needed
   • Application can run on Java EE or OSGi

Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   32
PAR
• Packaging format for all
  modules in an app.

• JAR with Application-*
  manifest headers

• Single unit: deploy,
  refresh, undeploy

• Application boundaries
      – Scoping of types / services
      – DataSource does not leak
        out of the application
      – Hibernate can change
        domain objects

 Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   33
Web Migration:
                                           From WAR to PAR




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
Web Application Deployment Options
• Standard Java EE WAR
      – supported as is
      – converted into an OSGi
        bundle
• Shared Libraries WAR
      – WAR + OSGi package
        imports
      – Eradicate library bloat of
        monolithic Java EE
        WARs
• Shared Services WAR
      – Uses OSGi services with
        Spring's <osgi:reference>
• Web Module
 Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   35
Web Module
   • Deployment & packaging option for OSGi-
     compliant web applications: stand-alone or
     within a PAR

   • OSGi bundle: structure similar to Shared
     Services WAR + MODULE-INF for resources

   • Reduced configuration for Spring MVC
     applications via Web manifest headers
             – Auto-configuration of Spring MVC's
               DispatcherServlet
             – Single WebApplicationContext and no Root WAC

   • Additional configuration via web.xml fragments

Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   36
Web Manifest Headers
   Manifest-Version: 1.0
   Bundle-ManifestVersion: 2
   ...
   Module-Type: Web
   Web-ContextPath: /my-web-app
   Web-DispatcherServletUrlPatterns: *.do




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   37
DEMO

          Web Module




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   38
Roadmap




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
dm Server 2.0 Roadmap
   • SpringSource dm Server 2.0: 3rd quarter 2009
   • Cloning bundles
             – Solves problems around static variables and more
   • Shared Repository
             – Share a single repository among several servers
   • Plan Files
             – Define an application as a collection of bundles
             – Does not contain the bundles, more flexible
   • Distributed and improved management
             – Operation on a group of servers
             – Like tc Server for Tomcat
   • Modular Web Applications
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   40
Support for Enterprise OSGi Standards
   • RFC 66: Web Container for OSGi (RI based
     on dm Server)
   • RFC 119: Distributed OSGi
   • RFC 124: Blueprint Service (RI based on
     Spring-DM)
   • RFC 139: JMX interface for OSGi
   • RFC 142: JNDI and OSGi integration




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   41
Summary




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
Summary: SpringSource dm Server
   • Based on proven, established
     modularization technology (OSGi)
   • Based on proven, established Web
     technology (Tomcat)
   • Spring and Spring-DM programming
     models: easy to use
   • Solves OSGi problems (e.g., context
     class loading)
   • Dynamic updates of running modules
   • Lightweight

Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   43
Summary: Deployment Options
   • OSGi bundles
   • PAR = logical & physical application
     boundary
   • dm Server supports multiple Web
     deployment formats and therefore
     migration
             – Java EE WAR → Shared Libraries WAR →
               Shared Services WAR → Web Module




Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   44
Resources
• OSGi:
      http://osgi.org
• Spring Framework:
      http://springframework.org
• Spring-DM:
      http://springframework.org/osgi
• SpringSource dm Server:
      http://springframework.org/dmserver
• SpringSource Team Blog:
      http://blog.springsource.com
• German Getting Started:
      http://www.dpunkt.de/buecher/3231.html
• OpenCredo:
      http://opencredo.com
Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.   45
Questions?


Eberhard Wolff                                                                                        Sam Brannen
eberhard.wolff@springsource.com                                                                       sam.brannen@opencredo.com

http://SpringSource.com                                                                               http://OpenCredo.com




 Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.

More Related Content

PDF
RESTful Services and Distributed OSGi - 04/2009
PDF
Apache MyFaces 1.2 Web Application Development
PDF
Webfest 2011 PHP on Windows by Rama Yurindra
PDF
(Oleg zhurakousky)spring integration-scala-intro
PDF
Getting started with PHP on IBM i
PDF
Concierge - Bringing OSGi (back) to Embedded Devices
PDF
Towards a modularity maturity model - osgi users forum uk 16-nov2011
PPTX
Concept based semantic search
RESTful Services and Distributed OSGi - 04/2009
Apache MyFaces 1.2 Web Application Development
Webfest 2011 PHP on Windows by Rama Yurindra
(Oleg zhurakousky)spring integration-scala-intro
Getting started with PHP on IBM i
Concierge - Bringing OSGi (back) to Embedded Devices
Towards a modularity maturity model - osgi users forum uk 16-nov2011
Concept based semantic search

Similar to Enterprise Applications With OSGi and SpringSource dm Server (20)

PDF
Modular Web Applications with OSGi
PDF
TDC 2011: OSGi-enabled Java EE Application
PDF
OSGi In Anger - Tara Simpson
PDF
Server Day 2009: Spring dm Server by Alef Arendsen
KEY
A Platform Approach to Enterprise Content Management with Eclipse Apricot, CM...
PDF
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
PDF
OSGi tech session
PDF
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
PDF
OSGi & Java EE in GlassFish - Best of both worlds
PDF
Enterprise OSGi at eBay
KEY
Beyond OSGi Software Architecture
PDF
OSGi-enabled Java EE Applications using GlassFish
PDF
OSGi-enabled Java EE applications in GlassFish
PDF
OSGi Mars World in Action
PPTX
Enterprise Spring Building Scalable Applications
PPT
Enabling modularization through OSGi and SpringDM
PDF
Crx 2.2 Deep-Dive
PDF
Balconies, Patios, Terraces, and Bridges. Architectural approaches for moving...
PDF
Building LinkedIn's Next Generation Architecture with OSGi
PDF
2009 Q2 WSO2 Technical Update
Modular Web Applications with OSGi
TDC 2011: OSGi-enabled Java EE Application
OSGi In Anger - Tara Simpson
Server Day 2009: Spring dm Server by Alef Arendsen
A Platform Approach to Enterprise Content Management with Eclipse Apricot, CM...
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi tech session
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
OSGi & Java EE in GlassFish - Best of both worlds
Enterprise OSGi at eBay
Beyond OSGi Software Architecture
OSGi-enabled Java EE Applications using GlassFish
OSGi-enabled Java EE applications in GlassFish
OSGi Mars World in Action
Enterprise Spring Building Scalable Applications
Enabling modularization through OSGi and SpringDM
Crx 2.2 Deep-Dive
Balconies, Patios, Terraces, and Bridges. Architectural approaches for moving...
Building LinkedIn's Next Generation Architecture with OSGi
2009 Q2 WSO2 Technical Update
Ad

More from Sam Brannen (20)

PPTX
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
PDF
Testing with JUnit 5 and Spring - Spring I/O 2022
PDF
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
PPTX
JUnit 5: What's New and What's Coming - Spring I/O 2019
PDF
JUnit 5 - New Opportunities for Testing on the JVM
PPTX
Get the Most out of Testing with Spring 4.2
PPTX
JUnit 5 - from Lambda to Alpha and beyond
PDF
Testing with Spring: An Introduction
PDF
Testing with Spring 4.x
PDF
Spring Framework 4.1
PDF
Testing Spring MVC and REST Web Applications
PDF
Composable Software Architecture with Spring
PDF
Testing Web Apps with Spring Framework 3.2
PDF
Spring Framework 4.0 to 4.1
PDF
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
PPTX
Spring Framework 3.2 - What's New
PDF
Spring 3.1 and MVC Testing Support - 4Developers
PPTX
Effective out-of-container Integration Testing - 4Developers
PPTX
Spring 3.1 to 3.2 in a Nutshell - SDC2012
PPTX
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with JUnit 5 and Spring - Spring I/O 2022
JUnit 5 - Evolution and Innovation - SpringOne Platform 2019
JUnit 5: What's New and What's Coming - Spring I/O 2019
JUnit 5 - New Opportunities for Testing on the JVM
Get the Most out of Testing with Spring 4.2
JUnit 5 - from Lambda to Alpha and beyond
Testing with Spring: An Introduction
Testing with Spring 4.x
Spring Framework 4.1
Testing Spring MVC and REST Web Applications
Composable Software Architecture with Spring
Testing Web Apps with Spring Framework 3.2
Spring Framework 4.0 to 4.1
Spring Framework 4.0 - The Next Generation - Soft-Shake 2013
Spring Framework 3.2 - What's New
Spring 3.1 and MVC Testing Support - 4Developers
Effective out-of-container Integration Testing - 4Developers
Spring 3.1 to 3.2 in a Nutshell - SDC2012
Spring 3.1 to 3.2 in a Nutshell - Spring I/O 2012
Ad

Enterprise Applications With OSGi and SpringSource dm Server

  • 1. Enterprise Applications with OSGi and SpringSource dm Server Eberhard Wolff – SpringSource Sam Brannen – OpenCredo Jazoon – 24 June 2009 – Zürich, Switzerland Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 2. Eberhard.Wolff (@) SpringSource.com • Regional Director of German speaking countries and Principal Consultant • Author of several articles and books • First German book on Spring • Speaker at national and international conferences • Blog: http://jandiandme.blogspot.com/ Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 2
  • 3. SpringSource • Employs most committers for Spring • Committers for Tomcat, ActiveMQ, Apache HTTP • New: tc Server / dm Server • Groovy / Grails • Hyperic • Training • Consulting • Subscription / Support Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 3
  • 4. Sam.Brannen (@) OpenCredo.com • Software Consultant • Spring Framework Core Developer • Previous SpringSource dm Server developer: OSGi-enabled Web deployment models, Tomcat integration, Test Framework • Java developer with 10+ years' experience • Regular speaker at conferences on Spring, dm Server, Java, and testing • Co-author of Spring in a Nutshell; chief technical reviewer for Spring Recipes Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 4
  • 5. Open Credo • Experts in Open Source application development • Consulting • Coaching • Management Training • Committers for numerous Spring projects – Spring Framework – Spring Integration – Spring .NET Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 5
  • 6. Why another Application Server? Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 7. OSGi’s Promise of Modularity • Modularization is key to maintainable software • Application Server itself is modularized – No more "one size fits all" – Java EE 6 introduces profiles • On the client and in the embedded world OSGi has succeeded as a standard for modularization • OSGi enters the enterprise server market… Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 7
  • 8. Building on OSGi • Almost all app server vendors base their systems on OSGi (JBoss, Sun, Oracle, IBM) • But none offers OSGi as a programming model for the customer • Why shouldn't the customer be as empowered as the app server vendor? • Enter SpringSource dm Server… Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 8
  • 9. OSGi Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 10. It's a module system • Partition a system into a number of modules – "bundles" • Dynamic: bundles can be installed, started, stopped, uninstalled and updated – ...at runtime • better operations • Strict visibility rules • Resolution process satisfies dependencies of a module • Understands versioning Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 10
  • 11. It's even service-oriented • Bundles can publish services… dynamically! • Service Registry allows other bundles to consume services • Services come and go at runtime – … transparently when using Spring-DM Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 11
  • 12. OSGi Bundle • The fundamental unit of deployment and modularity in OSGi • Just a JAR file – with additional entries in META-INF/MANIFEST.MF • Common manifest headers: – Bundle-SymbolicName – Bundle-Version – Bundle-Name – Bundle-ManifestVersion – Bundle-Vendor Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 12
  • 13. Export & Import Packages Declare package-level visibility and dependencies of your bundle. Export-Package: com.xyz.bar Export-Package: com.xyz.bar;version="1.0.5" Import-Package: com.xyz.foo Import-Package: >= 1.0.3; e.g., com.xyz.foo;version="1.0.3" 1.0.3, 1.0.3.GA, Import-Package: 1.0.4, 2.0, etc. com.xyz.foo;version="[1.0.3,1.0.3]" Import-Package: com.xyz.foo;version="[1.0.3,1.1.0)", com.xyz.bar;version="[1.0.3,2.0.0)" Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 13
  • 14. Publish a Service ServiceRegistration reg = bundleContext.registerService( Bar.class.getName(), myBarService); ... reg.unregister(); Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 14
  • 15. Consume a Service ServiceReference ref = bundleContext.getServiceReference( Bar.class.getName()); Bar bar = (Bar) bundleContext.getService(ref); ... bundleContext.ungetService(ref); // bar should no longer be used here Complex… Potential resource leaks! Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 15
  • 16. OSGi in the Enterprise Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 17. OSGi as a Server Platform Web Application Enterprise Server Bundles Web Transaction ... OSGi Container Management Application Features might be added on demand OSGi Service Platform Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 17
  • 18. OSGi for Enterprise Applications • Dynamic services are hard to develop (boiler plate code) • Basic infrastructure for OSGi + Web has to be done by yourself • What do we do about WARs? • How do you keep a service or type from leaking out of an application? – The notion of an application does not exist in OSGi… • Many enterprise libraries are not suited for OSGi Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 18
  • 19. Enterprise Libraries under OSGi • Class and resource loading problems – class visibility – context class loader is undefined in OSGi – resources in META-INF –… • Not directly supported: libraries with multiple bundles Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 19
  • 20. Example: Class Visibility Data Layer Data Layer Bundle Bundle Import-Package Import-Package Domain Model Domain Model Hibernate Hibernate Bundle Bundle Bundle Bundle <Export-Pkg> <Export-Pkg> <Export-Pkg> <Export-Pkg> Domain types & SessionFactory mapping files Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 20
  • 21. Good News for OSGi in the Enterprise • Spring 2.5 and many other Spring projects are OSGi-ready – modules shipped as bundles – all class loading behaves correctly under OSGi • Hundreds of other enterprise libraries are now also packaged for use under OSGi in the SpringSource Enterprise Bundle Repository Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 21
  • 22. Spring Dynamic Modules & SpringSource dm Server Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 23. Spring-DM: ApplicationContext • Configuration files in /META-INF/spring • Automatically merged • ..and an ApplicationContext is created – one per Bundle • Spring-DM manages the ApplicationContext lifecycle • OSGi manages the Bundle lifecycle Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 23
  • 24. Spring-DM: Service Registry (1/2) Contrast with <beans ...> programmatic API <osgi:service ref="customerDAO" interface="dao.ICustomerDAO" /> <osgi:reference id="dataSource" interface="javax.sql.DataSource" /> </beans> Also supports filters, listeners, collections (lists and sets), etc. Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 24
  • 25. Spring-DM: Service Registry (2/2) • Dynamic services handled automatically – Instances and collections are proxied – Method calls are buffered – Configurable timeouts • Purely declarative Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 25
  • 26. Out-of-scope for Spring-DM • Easy import of bundles and libraries • Using JPA or Hibernate in OSGi • Seamless Web support • Notion of an application • Enter SpringSource dm Server… Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 26
  • 27. dm Server Platform • Built on Equinox • Modular architecture –Subsystems –Bundles • Small footprint • Modular profiles • Bundle repository • Library provisioning • Serviceability –FFDC –Logging –Tracing Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 27
  • 28. Importing & Exporting Types • Plain OSGi + … • Import-Library and Import-Bundle – Library imports bundle imports – Bundle imports package imports – OSGi runtime semantics remain the same Import-Library: org.springframework.spring; version="[2.5.6,3.0)" Import-Bundle: com.springsource.org.hibernate; version="[3.2.6.ga,3.2.6.ga]" Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 28
  • 29. Example Application Bundles • Web Export Web • Service • API Import – Only interfaces and API domain classes – Implementation can be exchanged Service • Could add infrastructure: data source, transaction manager, etc. Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 29
  • 30. Bundles & Types • Only dependencies on the API – Implementation can be exchanged, … even at runtime • No direct dependencies on any implementation • Not shown: dependencies on external bundles • … can be installed in dm Server • … modular middleware! Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 30
  • 31. Bundles & Services Service Type: Web Registry Import consume Services: API Publish / Consume publish Service Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 31
  • 32. Bundles & Services • Infrastructure can use the same principle as application services – DataSource and PlatformTransactionManager are just services Can I still run on plain Java EE? • Yes: instead of OSGi Service directly inject Spring Beans • No more dynamic services / modularization • No code change needed • Application can run on Java EE or OSGi Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 32
  • 33. PAR • Packaging format for all modules in an app. • JAR with Application-* manifest headers • Single unit: deploy, refresh, undeploy • Application boundaries – Scoping of types / services – DataSource does not leak out of the application – Hibernate can change domain objects Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 33
  • 34. Web Migration: From WAR to PAR Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 35. Web Application Deployment Options • Standard Java EE WAR – supported as is – converted into an OSGi bundle • Shared Libraries WAR – WAR + OSGi package imports – Eradicate library bloat of monolithic Java EE WARs • Shared Services WAR – Uses OSGi services with Spring's <osgi:reference> • Web Module Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 35
  • 36. Web Module • Deployment & packaging option for OSGi- compliant web applications: stand-alone or within a PAR • OSGi bundle: structure similar to Shared Services WAR + MODULE-INF for resources • Reduced configuration for Spring MVC applications via Web manifest headers – Auto-configuration of Spring MVC's DispatcherServlet – Single WebApplicationContext and no Root WAC • Additional configuration via web.xml fragments Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 36
  • 37. Web Manifest Headers Manifest-Version: 1.0 Bundle-ManifestVersion: 2 ... Module-Type: Web Web-ContextPath: /my-web-app Web-DispatcherServletUrlPatterns: *.do Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 37
  • 38. DEMO Web Module Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 38
  • 39. Roadmap Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 40. dm Server 2.0 Roadmap • SpringSource dm Server 2.0: 3rd quarter 2009 • Cloning bundles – Solves problems around static variables and more • Shared Repository – Share a single repository among several servers • Plan Files – Define an application as a collection of bundles – Does not contain the bundles, more flexible • Distributed and improved management – Operation on a group of servers – Like tc Server for Tomcat • Modular Web Applications Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 40
  • 41. Support for Enterprise OSGi Standards • RFC 66: Web Container for OSGi (RI based on dm Server) • RFC 119: Distributed OSGi • RFC 124: Blueprint Service (RI based on Spring-DM) • RFC 139: JMX interface for OSGi • RFC 142: JNDI and OSGi integration Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 41
  • 42. Summary Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.
  • 43. Summary: SpringSource dm Server • Based on proven, established modularization technology (OSGi) • Based on proven, established Web technology (Tomcat) • Spring and Spring-DM programming models: easy to use • Solves OSGi problems (e.g., context class loading) • Dynamic updates of running modules • Lightweight Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 43
  • 44. Summary: Deployment Options • OSGi bundles • PAR = logical & physical application boundary • dm Server supports multiple Web deployment formats and therefore migration – Java EE WAR → Shared Libraries WAR → Shared Services WAR → Web Module Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 44
  • 45. Resources • OSGi: http://osgi.org • Spring Framework: http://springframework.org • Spring-DM: http://springframework.org/osgi • SpringSource dm Server: http://springframework.org/dmserver • SpringSource Team Blog: http://blog.springsource.com • German Getting Started: http://www.dpunkt.de/buecher/3231.html • OpenCredo: http://opencredo.com Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited. 45
  • 46. Questions? Eberhard Wolff Sam Brannen eberhard.wolff@springsource.com sam.brannen@opencredo.com http://SpringSource.com http://OpenCredo.com Copyright 2008-2009 SpringSource and Open Credo. Copying, publishing or distributing without express written permission is prohibited.