Beyond
OSGi Software
 Architecture

  Jeroen van Grondelle
    Marcel Offermans
     11 november - JFall 2009
About Us


Marcel Offermans   Jeroen van Grondelle
Lean Development
    Service Interfaces
    OSGi based Apps
Service Creation Patterns
Lean Development

       Part 1
Anticipate Change


Yes, there WILL be new
    requirements...
"Non-Functionals“
Great functionality! And can you do that, in a ... way.




                    Based on Luke Hohmann's book Beyond Software Architecture
Anticipate, don’t
over dimension

Do not try to support the things now
   that MIGHT be required next...
No decision is irreversible, but some
  are VERY expensive to reverse...
Service Interfaces that
  help you Change

          Part 2
Behavior Only
 Do NOT disclose parameters and implementation details.
Do NOT shape a Service after your rst/only implementation.
        This is NOT Object Orientation. Or is it... ;-)
Scale Invariance




 Service Interface should NOT re ect the scale 
   your ( rst) implementation will support.
Decoupling



If your implementations require other services, 
 access these services through interfaces only.
Think BIG
      act small!


    Your service interface should be future proof,
  your implementation should t your current needs.

         Keep many possible implementations 
(functionality, scale) in mind when designing interfaces.
Service Oriented Apps
      using OSGi

         Part 3
OSGi Recap
                                                                                                                         Service
                                                  Log                      Store                  Prefs
                                                                                       publish              publish
                                              publish                        use
                                                             use                                  use

                                                Bundle                Bundle            Bundle            Bundle




                                                        install                                                       Life Cycle
                                                                       installed
                          Service              start                                 start       starting
Bundle Bundle Bundle   Life Cycle                                      resolved                                          active
                         Module
                                                end                         uninstall            stopping       stop
                        Security
                                                                      uninstalled
                        OSGi framework
                       Java Virtual Machine

                                                                                                                        Module
                                                   Bundle                Bundle              Bundle          Bundle
                                                            imports                 exports           imports
                                               exports                         exports                             exports

                                              org.apache.util 1.0                  org.apache.db 1.4
                                                                  org.apache.log 2.3                  org.apache.util 1.1
Container Style
 Development


        Application consists of
      interdependent Services

   Public Services are accessed
      through UI/SOAP/JMS/...
Be a Good Host
                       Offer facilities to
                      your components




              OSGi Compendium is a
           Catalog of generic Facilities

Add your own to the container if needed
Deploy Everything



            Not just code!

                  Content
            Configurations
                Testcases
                     Work
Inversion of Control




        Use declarative Lifecycle and
          Dependency Management

                    Develop POJO’s
                   Delegate injection
Add Chemistry



          Deployed services react
                   on each other

             Resulting in behavior
                and new services

 Define these reactions in terms of
      life cycle and dependencies
Patterns for Creating
   Service Graphs
         Part 4
Singleton Services
                    Singleton
       Document
       Repository
 get()                                     Storage
 getVersions()                  requires
 get(version)
 store(Document)




         Bind Logic in a Single Instance
Singleton Services
class Activator {
   public void init(context, manager) {

        manager.add(
        	 createService()
           	 .setInterface(DocumentRepository.class.getName())
                                   (Pseudo)Code
        	 	 .setImplementation(DocumentRepositoryImpl.class)
        	 	 .add(
        	 	 	 createServiceDependency()
              	 	 .setService(Storage.class)));

    }
}
Aspect Services
                       Aspect
    Repository Cache                        Repository
get()                                   get()
getVersions()              intercepts   getVersions()
get(version)                            get(version)
store(Document)                         store(Document)




Transparently inject an interceptor service 
 "in front of" all services matching a lter
Aspect Services
class Activator {
   public void init(context, manager) {
         manager.add(
         	 createAspectService(
         	 	 DocumentRepository.class,
         	 	 DocumentRepositoryCache.class,
         	 	 10));

    }
}
Adapter Services
                       Adapter
    Repository Cache                       Repository Cache
        Manageable                        get()
 getCacheHits()                           getVersions()
                                 adapts
 setSize()                                get(version)
 setTTL()                                 store(Document)
 flush()




Start an instance of the adapter service for any
       "adaptee" service matching a lter
Adapter Services
class Activator {
   public void init(context, manager) {

        manager.add(
        	 createAdapterService(
        	 	 Manageable.class,
        	 	 DocumentRepositoryCache.class,
        	 	 DocumentRepositoryCacheManageable.class));

    }
}
Resource Adapters
                             Resource
                 Audio Track Adapter
            play()                               MP3
                                        adapts
            pause()                              File
            stop()



   Start an instance of a Resource Driven Service for all
                 resources matching a lter

Resources: File(system) abstraction, access by InputStream
Resource Adapters
class Activator {
   public void init(context, manager) {

          manager.add(
          	 createResourceAdapterService(
                "(extension=mp3)",
          	 	 AudioTrack.class,
          	 	 MP3AudioTrack.class));

    }
}
Dependency
Management & OSGi
 Not standard OSGi, a number of extensions available.
Felix Dependency Manager implements these patterns.
Lean Development
    Service Interfaces
    OSGi based Apps
Service Creation Patterns
Questions?


Marcel Offermans              Jeroen van Grondelle
marcel.offermans@luminis.nl    j.vangrondelle@beinformed.nl

Beyond OSGi Software Architecture

  • 1.
    Beyond OSGi Software Architecture Jeroen van Grondelle Marcel Offermans 11 november - JFall 2009
  • 2.
    About Us Marcel Offermans Jeroen van Grondelle
  • 3.
    Lean Development Service Interfaces OSGi based Apps Service Creation Patterns
  • 4.
  • 5.
    Anticipate Change Yes, thereWILL be new requirements...
  • 6.
    "Non-Functionals“ Great functionality! Andcan you do that, in a ... way. Based on Luke Hohmann's book Beyond Software Architecture
  • 7.
    Anticipate, don’t over dimension Donot try to support the things now that MIGHT be required next...
  • 8.
    No decision isirreversible, but some are VERY expensive to reverse...
  • 9.
    Service Interfaces that help you Change Part 2
  • 10.
    Behavior Only DoNOT disclose parameters and implementation details. Do NOT shape a Service after your rst/only implementation. This is NOT Object Orientation. Or is it... ;-)
  • 11.
    Scale Invariance ServiceInterface should NOT re ect the scale  your ( rst) implementation will support.
  • 12.
    Decoupling If your implementationsrequire other services,  access these services through interfaces only.
  • 13.
    Think BIG act small! Your service interface should be future proof, your implementation should t your current needs. Keep many possible implementations  (functionality, scale) in mind when designing interfaces.
  • 14.
    Service Oriented Apps using OSGi Part 3
  • 15.
    OSGi Recap Service Log Store Prefs publish publish publish use use use Bundle Bundle Bundle Bundle install Life Cycle installed Service start start starting Bundle Bundle Bundle Life Cycle resolved active Module end uninstall stopping stop Security uninstalled OSGi framework Java Virtual Machine Module Bundle Bundle Bundle Bundle imports exports imports exports exports exports org.apache.util 1.0 org.apache.db 1.4 org.apache.log 2.3 org.apache.util 1.1
  • 16.
    Container Style Development Application consists of interdependent Services Public Services are accessed through UI/SOAP/JMS/...
  • 17.
    Be a GoodHost Offer facilities to your components OSGi Compendium is a Catalog of generic Facilities Add your own to the container if needed
  • 18.
    Deploy Everything Not just code! Content Configurations Testcases Work
  • 19.
    Inversion of Control Use declarative Lifecycle and Dependency Management Develop POJO’s Delegate injection
  • 20.
    Add Chemistry Deployed services react on each other Resulting in behavior and new services Define these reactions in terms of life cycle and dependencies
  • 21.
    Patterns for Creating Service Graphs Part 4
  • 22.
    Singleton Services Singleton Document Repository get() Storage getVersions() requires get(version) store(Document) Bind Logic in a Single Instance
  • 23.
    Singleton Services class Activator{ public void init(context, manager) { manager.add( createService() .setInterface(DocumentRepository.class.getName()) (Pseudo)Code .setImplementation(DocumentRepositoryImpl.class) .add( createServiceDependency() .setService(Storage.class))); } }
  • 24.
    Aspect Services Aspect Repository Cache Repository get() get() getVersions() intercepts getVersions() get(version) get(version) store(Document) store(Document) Transparently inject an interceptor service  "in front of" all services matching a lter
  • 25.
    Aspect Services class Activator{ public void init(context, manager) { manager.add( createAspectService( DocumentRepository.class, DocumentRepositoryCache.class, 10)); } }
  • 26.
    Adapter Services Adapter Repository Cache Repository Cache Manageable get() getCacheHits() getVersions() adapts setSize() get(version) setTTL() store(Document) flush() Start an instance of the adapter service for any "adaptee" service matching a lter
  • 27.
    Adapter Services class Activator{ public void init(context, manager) { manager.add( createAdapterService( Manageable.class, DocumentRepositoryCache.class, DocumentRepositoryCacheManageable.class)); } }
  • 28.
    Resource Adapters Resource Audio Track Adapter play() MP3 adapts pause() File stop() Start an instance of a Resource Driven Service for all resources matching a lter Resources: File(system) abstraction, access by InputStream
  • 29.
    Resource Adapters class Activator{ public void init(context, manager) { manager.add( createResourceAdapterService( "(extension=mp3)", AudioTrack.class, MP3AudioTrack.class)); } }
  • 30.
    Dependency Management & OSGi Not standard OSGi, a number of extensions available. Felix Dependency Manager implements these patterns.
  • 31.
    Lean Development Service Interfaces OSGi based Apps Service Creation Patterns
  • 32.
    Questions? Marcel Offermans Jeroen van Grondelle marcel.offermans@luminis.nl j.vangrondelle@beinformed.nl