SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Spring DM - OSGi with Spring Framework Patrick Baumgartner AD Consultant patrick.baumgartner@trivadis.com Zürich, 10.11.2009
About me Application Development Consultant Web development with Spring Framework OSGi with Spring DM &  Spring Framework Agile Software Development Certified ScrumMaster Co-Author of "OSGi in der Praxis“ Spring Dynamic Modules - OSGi with Spring Framework 2
Agenda What is OSGi? The hard-coding Way Declarative Services Spring DM Blueprint Services Demo Conclusion Spring Dynamic Modules - OSGi with Spring Framework 3
What is OSGi? The OSGi framework is a module system for Java that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments. […] (Source: Wikipedia) Spring Dynamic Modules - OSGi with Spring Framework 4
Bundle Manifest – A special JAR Spring Dynamic Modules - OSGi with Spring Framework 5 Image Source: http://www.handycandy.co.uk
Lifecycle of a Bundle Spring Dynamic Modules - OSGi with Spring Framework 6 UPDATE REFRESH INSTALL STARTING INSTALLED START UPDATE REFRESH RESOLVE EXCEPTION ACTIVE RESOLVED UNINSTALL UNINSTALL STOP STOPPING UNINSTALLED
Service Registry Spring Dynamic Modules - OSGi with Spring Framework 7 SERVICE REGISTRY REGISTER DISCOVER SERVICE DESCRIPTION BIND SERVICE CONSUMER SERVICE  PROVIDER
OSGi – A Module System for Java Clear boundaries Dependencies Metadata Lifecycle Service Registry Spring Dynamic Modules - OSGi with Spring Framework 8
The hard-coding Way Spring Dynamic Modules - OSGi with Spring Framework 9
The hard-coding Way – Register a Service Register 	ServiceRegistration reg = bundleContext.registerService(	ChatterBoxService.class.getName(), 		twitterChatterbox, properties); Unregister 	reg.unregister(); Spring Dynamic Modules - OSGi with Spring Framework 10
The hard-coding Way – Consume a Service Get Service 	ServiceReference ref = bundleContext.getServiceReference(	ChatterBoxService.class.getName()); 	ChatterBoxService chatterbox = 	(ChatterBoxService)bundleContext.getService(ref); Unget Service 	bundleContext.ungetService(ref); Spring Dynamic Modules - OSGi with Spring Framework 11
The hard-coding Way – Consume a Service Get Service with ServiceTracker 	ServiceTracker tracker = new ServiceTracker(	bundleContext, LogService.class.getName(), 	serviceTrackerCustomizer); 	tracker.open();LogService logService = (LogService) tracker.getService(); Spring Dynamic Modules - OSGi with Spring Framework 12
Declarative Services Spring Dynamic Modules - OSGi with Spring Framework 13
Declarative Services Declarative Services (DS) are part of OSGi R4 Specification – Service Compendium Declaration of components in XML OSGI-INF/<component>.xml Components provides and depend on other Services  Components need a special bundle manifest headere.g. Service-Component: OSGI-INF/TwitterChatterBox.xml Spring Dynamic Modules - OSGi with Spring Framework 14
Declarative Services <?xml version="1.0" encoding="UTF-8"?> <component name="com.trivadis.chatterbox.twitter">    <implementation       class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl"/>    <service>       <provide      interface="com.trivadis.chatterbox.service.ChatterBoxService"/>    </service> <reference name="LOGGER"       interface="org.osgi.service.log.LogService"       cardinality="0..n"       policy="dynamic"       bind="addLogService"       unbind="removeLogService"/> </component> Spring Dynamic Modules - OSGi with Spring Framework 15
Spring Dynamic Modules Spring Dynamic Modules - OSGi with Spring Framework 16
Spring Dynamic Modules Integration of Springs Dependency Injection and OSGi Formerly known as Spring OSGi XML files are located in META-INF/spring Very similar approach compared to DS Uses Spring DI for references to other Services and POJOs (Almost) no dependencies on OSGi APIs Components need a special bundle manifest headere.g. Spring-Context: META-INF/spring/bundle-context.xml, … Spring Dynamic Modules - OSGi with Spring Framework 17
The Spring DM Idea Spring Dynamic Modules - OSGi with Spring Framework 18 APPLICATION CONTEXT APPLICATION CONTEXT APPLICATION CONTEXT Imported Service Exported Service Spring Bean SPRING & SPRING DM OSGI FRAMEWORK JVM
Spring Dynamic Modules bundle-context.xml <beans … > <bean id="twitterChatterBox"class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl"> 	<property name="logService" ref="logServiceOsgi" /> </bean> </beans> Spring Dynamic Modules - OSGi with Spring Framework 19
Spring Dynamic Modules bundle-context-osgi.xml <beans:beans …>    <service ref="twitterChatterBox"       interface="com.trivadis.chatterbox.service.ChatterBoxService"/>    <reference id="logServiceOsgi"   interface="org.osgi.service.log.LogService" /> </beans:beans> Spring Dynamic Modules - OSGi with Spring Framework 20
Spring Dynamic Modules Also supports listeners, filters, and collections Dynamics are handled by the framework Proxies for service instances and collections Method calls are buffered Configurable timeouts Annotation-Based Injection with @ServiceReference Spring Dynamic Modules - OSGi with Spring Framework 21
Blueprint Services Spring Dynamic Modules - OSGi with Spring Framework 22
Blueprint Services Blueprint Services are a Standard since OSGi R 4.2 and based on the Ideas of Spring DM 1.0 Spring DM 2.0 is the Reference Implementation (RI) Apache Aries Blueprint is an other implementation Extremely similar to Spring DM but a standard XML files are located in META-INF/blueprint Components need a special bundle manifest headere.g. Bundle-Blueprint: OSGI-INF/blueprint/config.xml, … Spring Dynamic Modules - OSGi with Spring Framework 23
Blueprint Services config.xml <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">    <bean id="twitterChatterBox"               class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl">       <property name="logService" ref="logService" />    </bean>    <service ref="twitterChatterBox"                    interface="com.trivadis.chatterbox.service.ChatterBoxService" />    <reference id="logService"      interface="org.osgi.service.log.LogService" /> </blueprint> Spring Dynamic Modules - OSGi with Spring Framework 24
Comparison Spring DM vs. Blueprint Services Dependency Injection Spring Dynamic Modules - OSGi with Spring Framework 25 Spring DM Blueprint Services Constructor Injection Setter Injection Field Injection Method Injection  Arbitrary Method Injection Autowiring YES YES YES YES YES YES YES YES NO NO NO NO Source: Spring Dynamic Modules Reference Guide 2.0.0.M1
Comparison Spring DM vs. Blueprint Services Component Lifecycle Spring Dynamic Modules - OSGi with Spring Framework 26 Spring DM Blueprint Services Lazy Initialization Bean Scopes Custom Bean Scopes Built-in Callbacks Custom Callbacks Initialization Processing YES YES YES YES YES YES YES YES NO NO YES NO Source: Spring Dynamic Modules Reference Guide 2.0.0.M1
Demo Spring Dynamic Modules - OSGi with Spring Framework 27
Conclusion Should I use Declarative Services, Spring DM or Blueprint Services? DS, DM or Blueprint Services are better than program the life cycles and service infrastructure by hand If you already use Spring, use Spring DM If you want to use Standards use DS or Blueprint To switch from Blueprint Services to Spring DM you need just a few changes in the XML configuration. Spring Dynamic Modules - OSGi with Spring Framework 28
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architecture
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Micro Frontends
Micro FrontendsMicro Frontends
Micro Frontends
 
Grokking #9: Building a real-time and offline editing service with Couchbase
Grokking #9: Building a real-time and offline editing service with CouchbaseGrokking #9: Building a real-time and offline editing service with Couchbase
Grokking #9: Building a real-time and offline editing service with Couchbase
 
Mini-Training Owin Katana
Mini-Training Owin KatanaMini-Training Owin Katana
Mini-Training Owin Katana
 
Latest Javascript MVC & Front End Frameworks 2017
Latest Javascript MVC & Front End Frameworks 2017Latest Javascript MVC & Front End Frameworks 2017
Latest Javascript MVC & Front End Frameworks 2017
 
Simple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerSimple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and Swagger
 
Vue micro frontend implementation patterns
Vue micro frontend implementation patternsVue micro frontend implementation patterns
Vue micro frontend implementation patterns
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
TUTTO SU VISUAL STUDIO ALM 2015
TUTTO SU VISUAL STUDIO ALM 2015TUTTO SU VISUAL STUDIO ALM 2015
TUTTO SU VISUAL STUDIO ALM 2015
 
Will the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir ZukerWill the Real Public API Please Stand Up? Amir Zuker
Will the Real Public API Please Stand Up? Amir Zuker
 
Lagom framework
Lagom frameworkLagom framework
Lagom framework
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val Karpov
 
Micronaut Deep Dive - Codeone 2019
Micronaut Deep Dive - Codeone 2019Micronaut Deep Dive - Codeone 2019
Micronaut Deep Dive - Codeone 2019
 
Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?Why You Should Use MERN Stack for Startup Apps?
Why You Should Use MERN Stack for Startup Apps?
 
Introduction to Micronaut at Oracle CodeOne 2018
Introduction to Micronaut at Oracle CodeOne 2018Introduction to Micronaut at Oracle CodeOne 2018
Introduction to Micronaut at Oracle CodeOne 2018
 
Unpacking .NET Core | EastBanc Technologies
Unpacking .NET Core | EastBanc TechnologiesUnpacking .NET Core | EastBanc Technologies
Unpacking .NET Core | EastBanc Technologies
 
ASP.NET 5 Overview
ASP.NET 5 OverviewASP.NET 5 Overview
ASP.NET 5 Overview
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
ASP.NET Core
ASP.NET CoreASP.NET Core
ASP.NET Core
 

Andere mochten auch

OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 

Andere mochten auch (9)

Modular Web Applications with OSGi
Modular Web Applications with OSGiModular Web Applications with OSGi
Modular Web Applications with OSGi
 
OSGi and Spring Data for simple (Web) Application Development
OSGi and Spring Data  for simple (Web) Application DevelopmentOSGi and Spring Data  for simple (Web) Application Development
OSGi and Spring Data for simple (Web) Application Development
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
Strata+Hadoop 2017 San Jose: Lessons from a year of supporting Apache Kafka
Strata+Hadoop 2017 San Jose: Lessons from a year of supporting Apache KafkaStrata+Hadoop 2017 San Jose: Lessons from a year of supporting Apache Kafka
Strata+Hadoop 2017 San Jose: Lessons from a year of supporting Apache Kafka
 
Microservices OSGi-running-with-apache-karaf
Microservices OSGi-running-with-apache-karafMicroservices OSGi-running-with-apache-karaf
Microservices OSGi-running-with-apache-karaf
 
Strata+Hadoop 2017 San Jose - The Rise of Real Time: Apache Kafka and the Str...
Strata+Hadoop 2017 San Jose - The Rise of Real Time: Apache Kafka and the Str...Strata+Hadoop 2017 San Jose - The Rise of Real Time: Apache Kafka and the Str...
Strata+Hadoop 2017 San Jose - The Rise of Real Time: Apache Kafka and the Str...
 
Enabling Real-Time Analytics for IoT
Enabling Real-Time Analytics for IoTEnabling Real-Time Analytics for IoT
Enabling Real-Time Analytics for IoT
 
Tapjoy: Building a Real-Time Data Science Service for Mobile Advertising
Tapjoy: Building a Real-Time Data Science Service for Mobile AdvertisingTapjoy: Building a Real-Time Data Science Service for Mobile Advertising
Tapjoy: Building a Real-Time Data Science Service for Mobile Advertising
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 

Ähnlich wie OSGi with the Spring Framework

OFMP The Road To OSGi Eclipse Democamp Luxembour 2008
OFMP The Road To OSGi Eclipse Democamp Luxembour 2008OFMP The Road To OSGi Eclipse Democamp Luxembour 2008
OFMP The Road To OSGi Eclipse Democamp Luxembour 2008
Frederic Conrotte
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
marpierc
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 

Ähnlich wie OSGi with the Spring Framework (20)

The Web on OSGi: Here's How
The Web on OSGi: Here's HowThe Web on OSGi: Here's How
The Web on OSGi: Here's How
 
Cocoon OSGi CocoonGT2007
Cocoon OSGi CocoonGT2007Cocoon OSGi CocoonGT2007
Cocoon OSGi CocoonGT2007
 
Creating Yahoo Mobile Widgets
Creating Yahoo Mobile WidgetsCreating Yahoo Mobile Widgets
Creating Yahoo Mobile Widgets
 
Apache Aries Blog Sample
Apache Aries Blog SampleApache Aries Blog Sample
Apache Aries Blog Sample
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
OGCE Project Overview
OGCE Project OverviewOGCE Project Overview
OGCE Project Overview
 
Introduction To Eclipse RCP
Introduction To Eclipse RCPIntroduction To Eclipse RCP
Introduction To Eclipse RCP
 
RomaFramework Tutorial Basics
RomaFramework Tutorial BasicsRomaFramework Tutorial Basics
RomaFramework Tutorial Basics
 
OFMP The Road To OSGi Eclipse Democamp Luxembour 2008
OFMP The Road To OSGi Eclipse Democamp Luxembour 2008OFMP The Road To OSGi Eclipse Democamp Luxembour 2008
OFMP The Road To OSGi Eclipse Democamp Luxembour 2008
 
GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009GTLAB Installation Tutorial for SciDAC 2009
GTLAB Installation Tutorial for SciDAC 2009
 
Spring boot
Spring bootSpring boot
Spring boot
 
Ibm
IbmIbm
Ibm
 
Spring Surf 101
Spring Surf 101Spring Surf 101
Spring Surf 101
 
Flex_rest_optimization
Flex_rest_optimizationFlex_rest_optimization
Flex_rest_optimization
 
IMS Learning Tools Interoperability @ UCLA
IMS Learning Tools Interoperability @ UCLAIMS Learning Tools Interoperability @ UCLA
IMS Learning Tools Interoperability @ UCLA
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Introduction To ASP.NET MVC
Introduction To ASP.NET MVCIntroduction To ASP.NET MVC
Introduction To ASP.NET MVC
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 

Mehr von Patrick Baumgartner

No Sql in Enterprise Java Applications
No Sql in Enterprise Java ApplicationsNo Sql in Enterprise Java Applications
No Sql in Enterprise Java Applications
Patrick Baumgartner
 
Daten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4jDaten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4j
Patrick Baumgartner
 
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGiOSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
Patrick Baumgartner
 

Mehr von Patrick Baumgartner (11)

Customer is king
Customer is kingCustomer is king
Customer is king
 
Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)
 
No Sql in Enterprise Java Applications
No Sql in Enterprise Java ApplicationsNo Sql in Enterprise Java Applications
No Sql in Enterprise Java Applications
 
Daten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4jDaten natuerlich modellieren und verarbeiten mit Neo4j
Daten natuerlich modellieren und verarbeiten mit Neo4j
 
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow BaselHow to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel
 
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Zurich
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow ZurichHow to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Zurich
How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Zurich
 
BED-Con - Tools für den täglichen Kampf als Entwickler
BED-Con - Tools für den täglichen Kampf als EntwicklerBED-Con - Tools für den täglichen Kampf als Entwickler
BED-Con - Tools für den täglichen Kampf als Entwickler
 
JFS 2011 - Top 10 Tools & Methoden - Baumgartner, Oehmichen
JFS 2011 - Top 10 Tools & Methoden - Baumgartner, OehmichenJFS 2011 - Top 10 Tools & Methoden - Baumgartner, Oehmichen
JFS 2011 - Top 10 Tools & Methoden - Baumgartner, Oehmichen
 
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGiOSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
OSGi für Praktiker - Web Applikationen und verteilte Systeme mit OSGi
 
Pax – Tools für den OSGi Alltag
Pax – Tools für den OSGi AlltagPax – Tools für den OSGi Alltag
Pax – Tools für den OSGi Alltag
 
Whats New In Spring 3.0 ?
Whats New In Spring 3.0 ?Whats New In Spring 3.0 ?
Whats New In Spring 3.0 ?
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

OSGi with the Spring Framework

  • 1. Spring DM - OSGi with Spring Framework Patrick Baumgartner AD Consultant patrick.baumgartner@trivadis.com Zürich, 10.11.2009
  • 2. About me Application Development Consultant Web development with Spring Framework OSGi with Spring DM & Spring Framework Agile Software Development Certified ScrumMaster Co-Author of "OSGi in der Praxis“ Spring Dynamic Modules - OSGi with Spring Framework 2
  • 3. Agenda What is OSGi? The hard-coding Way Declarative Services Spring DM Blueprint Services Demo Conclusion Spring Dynamic Modules - OSGi with Spring Framework 3
  • 4. What is OSGi? The OSGi framework is a module system for Java that implements a complete and dynamic component model, something that does not exist in standalone Java/VM environments. […] (Source: Wikipedia) Spring Dynamic Modules - OSGi with Spring Framework 4
  • 5. Bundle Manifest – A special JAR Spring Dynamic Modules - OSGi with Spring Framework 5 Image Source: http://www.handycandy.co.uk
  • 6. Lifecycle of a Bundle Spring Dynamic Modules - OSGi with Spring Framework 6 UPDATE REFRESH INSTALL STARTING INSTALLED START UPDATE REFRESH RESOLVE EXCEPTION ACTIVE RESOLVED UNINSTALL UNINSTALL STOP STOPPING UNINSTALLED
  • 7. Service Registry Spring Dynamic Modules - OSGi with Spring Framework 7 SERVICE REGISTRY REGISTER DISCOVER SERVICE DESCRIPTION BIND SERVICE CONSUMER SERVICE PROVIDER
  • 8. OSGi – A Module System for Java Clear boundaries Dependencies Metadata Lifecycle Service Registry Spring Dynamic Modules - OSGi with Spring Framework 8
  • 9. The hard-coding Way Spring Dynamic Modules - OSGi with Spring Framework 9
  • 10. The hard-coding Way – Register a Service Register ServiceRegistration reg = bundleContext.registerService( ChatterBoxService.class.getName(), twitterChatterbox, properties); Unregister reg.unregister(); Spring Dynamic Modules - OSGi with Spring Framework 10
  • 11. The hard-coding Way – Consume a Service Get Service ServiceReference ref = bundleContext.getServiceReference( ChatterBoxService.class.getName()); ChatterBoxService chatterbox = (ChatterBoxService)bundleContext.getService(ref); Unget Service bundleContext.ungetService(ref); Spring Dynamic Modules - OSGi with Spring Framework 11
  • 12. The hard-coding Way – Consume a Service Get Service with ServiceTracker ServiceTracker tracker = new ServiceTracker( bundleContext, LogService.class.getName(), serviceTrackerCustomizer); tracker.open();LogService logService = (LogService) tracker.getService(); Spring Dynamic Modules - OSGi with Spring Framework 12
  • 13. Declarative Services Spring Dynamic Modules - OSGi with Spring Framework 13
  • 14. Declarative Services Declarative Services (DS) are part of OSGi R4 Specification – Service Compendium Declaration of components in XML OSGI-INF/<component>.xml Components provides and depend on other Services Components need a special bundle manifest headere.g. Service-Component: OSGI-INF/TwitterChatterBox.xml Spring Dynamic Modules - OSGi with Spring Framework 14
  • 15. Declarative Services <?xml version="1.0" encoding="UTF-8"?> <component name="com.trivadis.chatterbox.twitter"> <implementation class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl"/> <service> <provide interface="com.trivadis.chatterbox.service.ChatterBoxService"/> </service> <reference name="LOGGER" interface="org.osgi.service.log.LogService" cardinality="0..n" policy="dynamic" bind="addLogService" unbind="removeLogService"/> </component> Spring Dynamic Modules - OSGi with Spring Framework 15
  • 16. Spring Dynamic Modules Spring Dynamic Modules - OSGi with Spring Framework 16
  • 17. Spring Dynamic Modules Integration of Springs Dependency Injection and OSGi Formerly known as Spring OSGi XML files are located in META-INF/spring Very similar approach compared to DS Uses Spring DI for references to other Services and POJOs (Almost) no dependencies on OSGi APIs Components need a special bundle manifest headere.g. Spring-Context: META-INF/spring/bundle-context.xml, … Spring Dynamic Modules - OSGi with Spring Framework 17
  • 18. The Spring DM Idea Spring Dynamic Modules - OSGi with Spring Framework 18 APPLICATION CONTEXT APPLICATION CONTEXT APPLICATION CONTEXT Imported Service Exported Service Spring Bean SPRING & SPRING DM OSGI FRAMEWORK JVM
  • 19. Spring Dynamic Modules bundle-context.xml <beans … > <bean id="twitterChatterBox"class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl"> <property name="logService" ref="logServiceOsgi" /> </bean> </beans> Spring Dynamic Modules - OSGi with Spring Framework 19
  • 20. Spring Dynamic Modules bundle-context-osgi.xml <beans:beans …> <service ref="twitterChatterBox" interface="com.trivadis.chatterbox.service.ChatterBoxService"/> <reference id="logServiceOsgi" interface="org.osgi.service.log.LogService" /> </beans:beans> Spring Dynamic Modules - OSGi with Spring Framework 20
  • 21. Spring Dynamic Modules Also supports listeners, filters, and collections Dynamics are handled by the framework Proxies for service instances and collections Method calls are buffered Configurable timeouts Annotation-Based Injection with @ServiceReference Spring Dynamic Modules - OSGi with Spring Framework 21
  • 22. Blueprint Services Spring Dynamic Modules - OSGi with Spring Framework 22
  • 23. Blueprint Services Blueprint Services are a Standard since OSGi R 4.2 and based on the Ideas of Spring DM 1.0 Spring DM 2.0 is the Reference Implementation (RI) Apache Aries Blueprint is an other implementation Extremely similar to Spring DM but a standard XML files are located in META-INF/blueprint Components need a special bundle manifest headere.g. Bundle-Blueprint: OSGI-INF/blueprint/config.xml, … Spring Dynamic Modules - OSGi with Spring Framework 23
  • 24. Blueprint Services config.xml <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="twitterChatterBox" class="com.trivadis.chatterbox.twitter.service.internal.TwitterChatterboxServiceImpl"> <property name="logService" ref="logService" /> </bean> <service ref="twitterChatterBox" interface="com.trivadis.chatterbox.service.ChatterBoxService" /> <reference id="logService" interface="org.osgi.service.log.LogService" /> </blueprint> Spring Dynamic Modules - OSGi with Spring Framework 24
  • 25. Comparison Spring DM vs. Blueprint Services Dependency Injection Spring Dynamic Modules - OSGi with Spring Framework 25 Spring DM Blueprint Services Constructor Injection Setter Injection Field Injection Method Injection Arbitrary Method Injection Autowiring YES YES YES YES YES YES YES YES NO NO NO NO Source: Spring Dynamic Modules Reference Guide 2.0.0.M1
  • 26. Comparison Spring DM vs. Blueprint Services Component Lifecycle Spring Dynamic Modules - OSGi with Spring Framework 26 Spring DM Blueprint Services Lazy Initialization Bean Scopes Custom Bean Scopes Built-in Callbacks Custom Callbacks Initialization Processing YES YES YES YES YES YES YES YES NO NO YES NO Source: Spring Dynamic Modules Reference Guide 2.0.0.M1
  • 27. Demo Spring Dynamic Modules - OSGi with Spring Framework 27
  • 28. Conclusion Should I use Declarative Services, Spring DM or Blueprint Services? DS, DM or Blueprint Services are better than program the life cycles and service infrastructure by hand If you already use Spring, use Spring DM If you want to use Standards use DS or Blueprint To switch from Blueprint Services to Spring DM you need just a few changes in the XML configuration. Spring Dynamic Modules - OSGi with Spring Framework 28