SlideShare a Scribd company logo
1 of 30
Download to read offline
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

What's hot

Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
Steve Singer - Managing PostgreSQL with Puppet @ Postgres OpenSteve Singer - Managing PostgreSQL with Puppet @ Postgres Open
Steve Singer - Managing PostgreSQL with Puppet @ Postgres Open
PostgresOpen
 
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
kwatch
 
Using puppet
Using puppetUsing puppet
Using puppet
Alex Su
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
l xf
 
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
Performance evaluation of cloudera impala 0.6 beta with comparison to HivePerformance evaluation of cloudera impala 0.6 beta with comparison to Hive
Performance evaluation of cloudera impala 0.6 beta with comparison to Hive
Yukinori Suda
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with gevent
Mahendra M
 

What's hot (20)

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

Similar to OSGi for mere mortals

Getting Into The Flow With Cq Dam
Getting Into The Flow With Cq DamGetting Into The Flow With Cq Dam
Getting Into The Flow With Cq Dam
day
 
Enterprise OSGi at eBay
Enterprise OSGi at eBayEnterprise OSGi at eBay
Enterprise OSGi at eBay
Tony Ng
 
OSGi Service Platform 4.2
OSGi Service Platform 4.2OSGi Service Platform 4.2
OSGi Service Platform 4.2
Ilya Katsov
 

Similar to OSGi for mere mortals (20)

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

More from Bertrand Delacretaz

More from Bertrand Delacretaz (20)

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

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

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