SlideShare a Scribd company logo
OSGi
for mere mortals

                                                Simple and robus t sof t ware is go o d f or yo ur wor k-life b alance .

Bertrand Delacrétaz
Senior Developer, Adobe Digital Enterprise Systems, www.day.com
Apache So ware Foundation Member and (current) Director
h p://grep.codeconsult.ch - twi er: @bdelacretaz - bdelacretaz@apache.org
ApacheCon North America 2011, Vancouver, November 2011
slides revision: 2011-11-05 (on a plane)


OSGi for                                                                                            1
Mere Mortals
                                                                                                                           1
what?
        a simple RESTful server
       built from scratch on OSGi
               to show that it’s not rocket science,
                   even starting from scratch...


OSGi for
Mere Mortals
                                                       2
RESTfulcontent:
POST to store
              server?

$ date | curl -T - -X POST -D - http://localhost:8080/store/example

HTTP/1.1 201 Created
Location: /store/example
Content-Type: text/plain; charset=utf-8
Content-Length: 178
Server: Jetty(6.1.x)

Stored at /store/example
StoredBy:ch.x42.osgi.samples.osgi101.app.servlets.StorageServlet
StoredAt:Fri Nov 04 10:41:30 CET 2011
Path:/store/example

Fri Nov   4 10:41:30 CET 2011




OSGi for
Mere Mortals
                                                                      3
RESTful server!
GET to retrieve content:




$ curl http://localhost:8080/store/example
StoredBy:ch.x42.osgi.samples.osgi101.app.servlets.StorageServlet
StoredAt:Fri Nov 04 10:41:30 CET 2011
Path:/store/example

Fri Nov   4 10:41:30 CET 2011



                                  In terms of functionality, that’s it!



OSGi for
Mere Mortals
                                                                          4
It’s not big...
      107   ./app/pom.xml
       35   ./app/.../InMemoryStorage.java
       34   ./app/.../PathsStorage.java
      147   ./app/.../StorageServlet.java
      101   ./core/pom.xml
        6   ./core/...CoreConstants.java
       32   ./core/...DefaultGetServlet.java
       32   ./core/...DefaultPostServlet.java
      116   ./core/...DispatcherServlet.java
        8   ./core/...Storage.java
      208   ./launcher/pom.xml
       84   ./launcher/...OsgiBootstrap.java
       52   ./pom.xml



               962 lines in total, including 468 lines in pom.xml files...
OSGi for
Mere Mortals
                                                                             5
Components
                                                       Dynamic Services
    Server        OSGi framework          Application core        Application services
 Bootstrapping    and standard services

          HTTP         HttpService           Dispatcher
                                                                      InMemoryStorage
                                              Servlet
                  Services Components
                                            Default POST
                     Runtime (SCR)                                     StorageServlet
                                               Servlet

                      Configuration          Default GET
                                                                        PathsStorage
                                              Servlet
                         Logging

          HTTP     Felix Web Console

          shell         Felix Shell
                                                    indicates SCR ser vices
                                                    also:
                                                    maven-bundle plugin
                                                    maven-scr-plugin
OSGi for                                            maven-dependency-plugin
Mere Mortals
                                                                                         6
Bootstrapping
               and loading bundles




OSGi for                             7
Mere Mortals
                                         7
Framework start and stop
Called from a plain main() method




OSGi for
Mere Mortals
                                    8
Get bundles from Maven repo
Copy to a folder using maven-dependency-plugin in launcher




OSGi for
Mere Mortals
                                                             9
Install bundles from lesystem
BundleContext.installBundle(URL)
Install all bundles rst, then start all




OSGi for
Mere Mortals
                                          10
Live bundles list
From the Felix console at /system/console




                                            We’re good to go!

OSGi for
Mere Mortals
                                                                11
Our OSGi bundles
        HttpService        org.apache.felix.h p.je y

          Logging          org.apache.sling.commons.log
    Services Components
       Runtime (SCR)       org.apache.felix.scr

       Configuration
                           org.apache.felix.metatype
                           org.apache.felix.con gadmin
         Felix Shell
                           org.apache.felix.shell
                           org.apache.felix.shell.tui
     Felix Web Console     org.apache.felix.webconsole

      Application Core     osgi-for-mere-mortals-core
    Application Services   osgi-for-mere-mortals-app
OSGi for
Mere Mortals
                                                          12
Dispatcher
                 Servlet

OSGi for                    13
Mere Mortals
                                 13
DispatcherServletforComponent
Register with H pService and watch Servlet services
                                           Dispatcher
                                            Servlet




OSGi for
Mere Mortals
                                                        14
DispatcherServletServlets
Dispatch to OSGi services which are
                                               Dispatcher
                                                Servlet




                                 Default GET
                                   Servlet


OSGi for
Mere Mortals
                                                            15
Default GET
                 Servlet

OSGi for                     16
Mere Mortals
                                  16
Default GETSCR annotations
Just a servlet, with some
                          servlet
                                    Default GET
                                      Servlet




OSGi for
Mere Mortals
                                                  17
Storage
               Services

OSGi for                  18
Mere Mortals
                               18
Storage service interface
De ned in the core bundle, package is exported




OSGi for
Mere Mortals
                                                 19
Storage service#1: in memory
Active by default




OSGi for
Mere Mortals
                               20
Storage service#2: can be activated in console
Alternate service, inactive by default,
                                        just paths




OSGi for
Mere Mortals
                                                     21
Storage
               Servlet

OSGi for                 22
Mere Mortals
                              22
StorageServlet service
Uses @Reference to get a Storage




                                           Properties used by DispatcherSer vlet




               The Component will only start once a Storage service is available




OSGi for
Mere Mortals
                                                                                   23
Alternate Storage
               demo


OSGi for              24
Mere Mortals
                           24
Replaceone and enabling another ComponentStorage
By disabling
             In-memory with paths


      1) disable inMemoryStorage -> StorageServlet stops




      2) enable PathsStorage -> StorageServlet is back




OSGi for
Mere Mortals
                                                           25
Con guration
               demo



OSGi for                 26
Mere Mortals
                              26
Configuring the StorageServlet
Con gurationAdmin service, console and annotations




1) User provides con guration data in web console (or Felix shell, Sling Installer, ...)

  Felix Web Console

2) Console (con guration agent) changes values

 ConfigurationAdmin                                   StorageServlet

3) Con gurationAdmin deactivates and
reactivates Component with new Con g

                                                0) Component has metatype=true and some
OSGi for                                        non-private @Property annotations
Mere Mortals
                                                                                           27
StorageServlet Configuration code
Annotations + read values in activate()
                   Parameter names + descriptions in metatype.properties




OSGi for
Mere Mortals
                                                                           28
Conclusions


              29
Conclusions
Powerful out of the box
infrastructure, not much
code to write.
Modular component-based
architecture.
Dynamic (re)con guration,
both in terms of components
and parameters.
OSGi materializes the component-based programming
vision in Java, and using it is not rocket science!
 Code at github.com/bdelacretaz/OSGi-for-mere-mortals
 Your host today: @bdelacretaz, grep.codeconsult.ch
OSGi for
Mere Mortals
                                                        30

More Related Content

PDF
From Distributed to Pervasive OSGi
PDF
Distributed Services - OSGi 4.2 and possible future enhancements
PDF
HA Clustering of PostgreSQL(replication)@2012.9.29 PG Study.
PDF
Posh Devcon2009
PDF
Maximize the power of OSGi
PDF
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
KEY
How to Test Enterprise Java Applications
ZIP
Puppet and the Model-Driven Infrastructure
From Distributed to Pervasive OSGi
Distributed Services - OSGi 4.2 and possible future enhancements
HA Clustering of PostgreSQL(replication)@2012.9.29 PG Study.
Posh Devcon2009
Maximize the power of OSGi
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
How to Test Enterprise Java Applications
Puppet and the Model-Driven Infrastructure

What's hot (20)

PDF
Kayobe_desc
PDF
What's cool in the new and updated OSGi Specs (EclipseCon 2014)
PDF
Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
PDF
OSGi Cloud Ecosystems (EclipseCon 2013)
PDF
Puppet evolutions
DOCX
Php version 5
PDF
kubernetes practice
PDF
Writing Plugged-in Java EE Apps: Jason Lee
PDF
What you need to remember when you upload to CPAN
PPTX
Making Exceptions on Exception Handling (WEH 2012 Keynote Speech)
PDF
Continuous Integration: SaaS vs Jenkins in Cloud
PDF
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
PDF
Fiber in the 10th year
PDF
Mac ruby deployment
PPTX
Using puppet
PDF
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
PPT
Stackless Python In Eve
PDF
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
PDF
ZODB Tips and Tricks
PDF
Scaling Django with gevent
Kayobe_desc
What's cool in the new and updated OSGi Specs (EclipseCon 2014)
Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
OSGi Cloud Ecosystems (EclipseCon 2013)
Puppet evolutions
Php version 5
kubernetes practice
Writing Plugged-in Java EE Apps: Jason Lee
What you need to remember when you upload to CPAN
Making Exceptions on Exception Handling (WEH 2012 Keynote Speech)
Continuous Integration: SaaS vs Jenkins in Cloud
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
Fiber in the 10th year
Mac ruby deployment
Using puppet
"Highlights from Java 10&11 and Future of Java" at Java User Group Bonn 2018 ...
Stackless Python In Eve
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
ZODB Tips and Tricks
Scaling Django with gevent
Ad

Similar to OSGi for mere mortals (20)

PDF
Getting Into The Flow With CQ DAM
PDF
OSGi-enabled Java EE applications in GlassFish
KEY
Polyglot OSGi
PDF
OSGi-enabled Java EE Applications using GlassFish
PDF
Getting Into The Flow With Cq Dam
 
PDF
Enterprise OSGi at eBay
PDF
OSGi and Java EE in GlassFish - Tech Days 2010 India
PDF
OSGi & Java EE in GlassFish - Best of both worlds
PPTX
Hybrid Applications
PDF
Managing large and distributed Eclipse server applications.
PDF
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
PDF
Using OSGi for script deployment in Apache Sling
PDF
OSGi Service Platform 4.2
PDF
TDC 2011: OSGi-enabled Java EE Application
PDF
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
PDF
Distributed OSGi Demo Eclipsecon 2009
PDF
Tales from the OSGi trenches
PDF
Escape the defaults - Configure Sling like AEM as a Cloud Service
PDF
A Tale of a Server Architecture (Frozen Rails 2012)
PDF
CQ5 and Sling overview
Getting Into The Flow With CQ DAM
OSGi-enabled Java EE applications in GlassFish
Polyglot OSGi
OSGi-enabled Java EE Applications using GlassFish
Getting Into The Flow With Cq Dam
 
Enterprise OSGi at eBay
OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi & Java EE in GlassFish - Best of both worlds
Hybrid Applications
Managing large and distributed Eclipse server applications.
OSGi & Java EE in GlassFish @ Silicon Valley Code Camp 2010
Using OSGi for script deployment in Apache Sling
OSGi Service Platform 4.2
TDC 2011: OSGi-enabled Java EE Application
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
Distributed OSGi Demo Eclipsecon 2009
Tales from the OSGi trenches
Escape the defaults - Configure Sling like AEM as a Cloud Service
A Tale of a Server Architecture (Frozen Rails 2012)
CQ5 and Sling overview
Ad

More from Bertrand Delacretaz (20)

PDF
VanillaJS & the Web Platform, a match made in heaven?
PDF
Surviving large online communities with conciseness and clarity
PDF
Repoinit: a mini-language for content repository initialization
PDF
The Moving House Model, adhocracy and remote collaboration
PDF
GraphQL in Apache Sling - but isn't it the opposite of REST?
PDF
Open Source Changes the World!
PDF
How to convince your left brain (or manager) to follow the Open Source path t...
PDF
L'Open Source change le Monde - BlendWebMix 2019
PDF
Shared Neurons - the Secret Sauce of Open Source communities?
PDF
Sling and Serverless, Best Friends Forever?
PDF
Serverless - introduction et perspectives concrètes
PDF
State of the Feather - ApacheCon North America 2018
PDF
Karate, the black belt of HTTP API testing?
PDF
Open Source at Scale: the Apache Software Foundation (2018)
PDF
They don't understand me! Tales from the multi-cultural trenches
PDF
Prise de Décisions Asynchrone, Devoxx France 2018 (avec vidéo)
PDF
Project and Community Services the Apache Way
PDF
La Fondation Apache - keynote au Paris Open Source Summit 2017
PDF
Asynchronous Decision Making - FOSS Backstage 2017
PDF
Building an Apache Sling Rendering Farm
VanillaJS & the Web Platform, a match made in heaven?
Surviving large online communities with conciseness and clarity
Repoinit: a mini-language for content repository initialization
The Moving House Model, adhocracy and remote collaboration
GraphQL in Apache Sling - but isn't it the opposite of REST?
Open Source Changes the World!
How to convince your left brain (or manager) to follow the Open Source path t...
L'Open Source change le Monde - BlendWebMix 2019
Shared Neurons - the Secret Sauce of Open Source communities?
Sling and Serverless, Best Friends Forever?
Serverless - introduction et perspectives concrètes
State of the Feather - ApacheCon North America 2018
Karate, the black belt of HTTP API testing?
Open Source at Scale: the Apache Software Foundation (2018)
They don't understand me! Tales from the multi-cultural trenches
Prise de Décisions Asynchrone, Devoxx France 2018 (avec vidéo)
Project and Community Services the Apache Way
La Fondation Apache - keynote au Paris Open Source Summit 2017
Asynchronous Decision Making - FOSS Backstage 2017
Building an Apache Sling Rendering Farm

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation theory and applications.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Modernizing your data center with Dell and AMD
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
NewMind AI Monthly Chronicles - July 2025
Encapsulation theory and applications.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
Approach and Philosophy of On baking technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Modernizing your data center with Dell and AMD
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I

OSGi for mere mortals

  • 1. OSGi for mere mortals Simple and robus t sof t ware is go o d f or yo ur wor k-life b alance . Bertrand Delacrétaz Senior Developer, Adobe Digital Enterprise Systems, www.day.com Apache So ware Foundation Member and (current) Director h p://grep.codeconsult.ch - twi er: @bdelacretaz - bdelacretaz@apache.org ApacheCon North America 2011, Vancouver, November 2011 slides revision: 2011-11-05 (on a plane) OSGi for 1 Mere Mortals 1
  • 2. what? a simple RESTful server built from scratch on OSGi to show that it’s not rocket science, even starting from scratch... OSGi for Mere Mortals 2
  • 3. RESTfulcontent: POST to store server? $ date | curl -T - -X POST -D - http://localhost:8080/store/example HTTP/1.1 201 Created Location: /store/example Content-Type: text/plain; charset=utf-8 Content-Length: 178 Server: Jetty(6.1.x) Stored at /store/example StoredBy:ch.x42.osgi.samples.osgi101.app.servlets.StorageServlet StoredAt:Fri Nov 04 10:41:30 CET 2011 Path:/store/example Fri Nov 4 10:41:30 CET 2011 OSGi for Mere Mortals 3
  • 4. RESTful server! GET to retrieve content: $ curl http://localhost:8080/store/example StoredBy:ch.x42.osgi.samples.osgi101.app.servlets.StorageServlet StoredAt:Fri Nov 04 10:41:30 CET 2011 Path:/store/example Fri Nov 4 10:41:30 CET 2011 In terms of functionality, that’s it! OSGi for Mere Mortals 4
  • 5. It’s not big... 107 ./app/pom.xml 35 ./app/.../InMemoryStorage.java 34 ./app/.../PathsStorage.java 147 ./app/.../StorageServlet.java 101 ./core/pom.xml 6 ./core/...CoreConstants.java 32 ./core/...DefaultGetServlet.java 32 ./core/...DefaultPostServlet.java 116 ./core/...DispatcherServlet.java 8 ./core/...Storage.java 208 ./launcher/pom.xml 84 ./launcher/...OsgiBootstrap.java 52 ./pom.xml 962 lines in total, including 468 lines in pom.xml files... OSGi for Mere Mortals 5
  • 6. Components Dynamic Services Server OSGi framework Application core Application services Bootstrapping and standard services HTTP HttpService Dispatcher InMemoryStorage Servlet Services Components Default POST Runtime (SCR) StorageServlet Servlet Configuration Default GET PathsStorage Servlet Logging HTTP Felix Web Console shell Felix Shell indicates SCR ser vices also: maven-bundle plugin maven-scr-plugin OSGi for maven-dependency-plugin Mere Mortals 6
  • 7. Bootstrapping and loading bundles OSGi for 7 Mere Mortals 7
  • 8. Framework start and stop Called from a plain main() method OSGi for Mere Mortals 8
  • 9. Get bundles from Maven repo Copy to a folder using maven-dependency-plugin in launcher OSGi for Mere Mortals 9
  • 10. Install bundles from lesystem BundleContext.installBundle(URL) Install all bundles rst, then start all OSGi for Mere Mortals 10
  • 11. Live bundles list From the Felix console at /system/console We’re good to go! OSGi for Mere Mortals 11
  • 12. Our OSGi bundles HttpService org.apache.felix.h p.je y Logging org.apache.sling.commons.log Services Components Runtime (SCR) org.apache.felix.scr Configuration org.apache.felix.metatype org.apache.felix.con gadmin Felix Shell org.apache.felix.shell org.apache.felix.shell.tui Felix Web Console org.apache.felix.webconsole Application Core osgi-for-mere-mortals-core Application Services osgi-for-mere-mortals-app OSGi for Mere Mortals 12
  • 13. Dispatcher Servlet OSGi for 13 Mere Mortals 13
  • 14. DispatcherServletforComponent Register with H pService and watch Servlet services Dispatcher Servlet OSGi for Mere Mortals 14
  • 15. DispatcherServletServlets Dispatch to OSGi services which are Dispatcher Servlet Default GET Servlet OSGi for Mere Mortals 15
  • 16. Default GET Servlet OSGi for 16 Mere Mortals 16
  • 17. Default GETSCR annotations Just a servlet, with some servlet Default GET Servlet OSGi for Mere Mortals 17
  • 18. Storage Services OSGi for 18 Mere Mortals 18
  • 19. Storage service interface De ned in the core bundle, package is exported OSGi for Mere Mortals 19
  • 20. Storage service#1: in memory Active by default OSGi for Mere Mortals 20
  • 21. Storage service#2: can be activated in console Alternate service, inactive by default, just paths OSGi for Mere Mortals 21
  • 22. Storage Servlet OSGi for 22 Mere Mortals 22
  • 23. StorageServlet service Uses @Reference to get a Storage Properties used by DispatcherSer vlet The Component will only start once a Storage service is available OSGi for Mere Mortals 23
  • 24. Alternate Storage demo OSGi for 24 Mere Mortals 24
  • 25. Replaceone and enabling another ComponentStorage By disabling In-memory with paths 1) disable inMemoryStorage -> StorageServlet stops 2) enable PathsStorage -> StorageServlet is back OSGi for Mere Mortals 25
  • 26. Con guration demo OSGi for 26 Mere Mortals 26
  • 27. Configuring the StorageServlet Con gurationAdmin service, console and annotations 1) User provides con guration data in web console (or Felix shell, Sling Installer, ...) Felix Web Console 2) Console (con guration agent) changes values ConfigurationAdmin StorageServlet 3) Con gurationAdmin deactivates and reactivates Component with new Con g 0) Component has metatype=true and some OSGi for non-private @Property annotations Mere Mortals 27
  • 28. StorageServlet Configuration code Annotations + read values in activate() Parameter names + descriptions in metatype.properties OSGi for Mere Mortals 28
  • 30. Conclusions Powerful out of the box infrastructure, not much code to write. Modular component-based architecture. Dynamic (re)con guration, both in terms of components and parameters. OSGi materializes the component-based programming vision in Java, and using it is not rocket science! Code at github.com/bdelacretaz/OSGi-for-mere-mortals Your host today: @bdelacretaz, grep.codeconsult.ch OSGi for Mere Mortals 30