SlideShare a Scribd company logo
1 of 39
Download to read offline
Modular Java 
with OSGi and Karaf
by Cristiano Costantini and Giuseppe Gerla
Modularity
What does “module” means?
“A software module is a deployable,
manageable, natively reusable, composable,
stateless unit of software that provides a
concise interface to consumers”
Deployable: modules are unit of deployment.
Manageable: modules are unit of management.
Natively Reusable: modules are a unit of intraprocess reuse.
Composable: modules are a unit of composition.
Stateless: modules are stateless (*running software from a module has a state).
Testability: modules are a unit of testability.
uhm… the JAR file!
3
Where to find modularity?
4
There are two facets of Modularity
x Development
Model
x Runtime
Model
Why modularity?
“Modularity is the best hope to
reduce the costs of changes due to
architectural decisions”
5
“to tame complexity”
6
7
Modularity in Java
8
Modularity Patterns
9
Modularity Patterns
10
Base Patterns
Base patterns advise to
design and manage
relationships between
modules, that you have
to emphasize
reusability at software
module level, and that
modules shall be
cohesive and have a
behavior that serves a
singular purpose.
Modularity Patterns
11
Dependency Patterns
Dependency patterns
teach you that there must
be no cycles between
modules, that should be
organized in levels and
in physical layers. And
that a module should be
independent from the
runtime container and
deployable
independently from
other modules.
Modularity Patterns
12
Dependency Patterns: NO CYCLES!
NO CYCLES!
Modularity Patterns
13
Usability, Extensibility, Utility Patterns
The modules shall have a
public interface that is well
known.
Modules are configured
externally.
For improving usability,
create a façade serving as a
coarse-grained entry point
to another fine-grained
module.
Restricted dependency to theabstract elements of the moduleso to improve extensibility andreduce the number of
dependencies. 
Rely heavily on the use of
implementation factories anddependencies injection
framework.
Separate abstractions from theclasses that implement them inseparate modules, so to helpeliminate module relationships.
Perform a levelized build,
repeatable build of the
modules. This has positive
effect on the lifecycle of
software development as a
levelized build integrate
testing that require to
integrate early and often,
which guarantees a system
health always in a good
status. 
Modules should have a test
module.
Let’s open pack 1:
14
Development Model
x Development
Model
Let’s open pack 1:
15
Development Model
Let’s open pack 2:
16
Runtime Model
x Runtime
Model
Let’s open pack 2:
17
Runtime Model
Karaf
Karaf: an OSGi container
Karaf is a small OSGi based runtime which provides a
lightweight container onto which various components and
applications can be deployed.
19
Apache Karaf can trace it's origins back to the Apache
ServiceMix project's Kernel.
Karaf: what is it in detail?
Karaf is a platform that
allow you to deploy your
application.
You can install/uninstall/
start/stop your application
in several easy way.
You can replace/update it
and you can change its
configuration on the fly.
20
Karaf: what is an application?
An application is a
composition of
modules.
Each module can
depend from other
modules of
application or from
other module of the
container.
21
Karaf: what is a module?
A module is a bundle
Bundle is a Jar with a
Manifest richer than that one
We can develop a bundle
using Eclipse and Maven
22
Karaf: how a bundle interact?
Each bundle can registers one or more service.
Each service can be retrieved by other bundle.
Each service can obtain the reference of other services.
23
Karaf: What is a service?
We can define a service using the SOA definition.
“A Service is a self-contained unit of
functionality”
Caution: service in OSGi is NOT a WebService but it is an
intra-JVM service.
24
No WebServices?
Don’t worry: using Camel you can extend an OSGi service
with a WebService and more (as we’ll see later).
25
Karaf & Spring
Karaf has its own Dependency Injection API: Blueprint
Blueprint is a standard defined in OSGi that allow bean
definition, service definition and dependency injection
Using Spring Dynamic Module we can also use Spring in
Karaf. 
SpringDM explores bundles and load Spring xml files
Spring DM allows you to interact with the world without using
OSGi API in our code: in this way the code is cleaner and
classes that we write (our modules) can be reused on other
platforms.
26
Karaf + Camel = ServiceMix
27
+ =
Karaf & Web
28
Pax Web allows Karaf to support web. Using integrated Web
Server Jetty, it implements:
-HTTP Service API defined in OSGi
-Web Application API defined in OSGi Enterprise 
Like Spring DM, Pax Web explores Bundles installed in Karaf
to find web.xml files. 
When it finds ithe filet, Pax Web starts application by creating
servlets,filters and initializing servlet context defined in web
deployment descriptor.
SensorMix
An example of a Java Modular Application
SensorMix
30
External Architecture
SensorMix
31
Internal Architecture
SensorMix
32
Canonical Data Model Bundle
SensorMix
33
Integration Bundle: Camel routes for sensors’ samples
SensorMix
34
Data Service Bundle: persistence of data
SensorMix
Slides:

 http://cristcost.github.io/sensormix/
Sensormix:

 https://github.com/cristcost/sensormix/
Sensormix Android:

 https://github.com/cristcost/sensormix-android/
Sensormix Arduino:

 https://github.com/michelefi/sensormix-arduino/ 
35
Links:
Conclusions
Books
• “Java Application Architecture: Modularity Patterns with
Examples Using OSGi”, Kirk Knoernschild - Prentice Hall
• “Spring DM in Action”, A. Cogoluègnes, T. Templier, A.
Piper - Manning
• “OSGi in Action”, R. S. Hall, K. Pauls, S. McCulloch, D.
Savage - Manning
• “OSGi In depth”, Alexandre de Castro Alves - Manning
• “Enterprise Integration Patterns”, G. Hohpe, B. Woolf -
Addison Wesley
• “Camel in Action”, C. Ibsen, J. Anstey - Manning
37
Modularity is good	
Follow Modular Patterns	
Build modular java software with Maven	
Run modular java software with Karaf	
Check SensorMix for an example
lesson learnt:
Giuseppe Gerla
giuseppe.gerla@gmail.com
Cristiano Costantini
cristiano.costantini@gmail.com

More Related Content

Viewers also liked

Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
Praktyczne wprowadzenie do OSGi i Enterprise OSGi
Praktyczne wprowadzenie do OSGi i Enterprise OSGiPraktyczne wprowadzenie do OSGi i Enterprise OSGi
Praktyczne wprowadzenie do OSGi i Enterprise OSGiJacek Laskowski
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGipradeepfn
 
Deep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerDeep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerAruna Karunarathna
 
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 GlassFishArun Gupta
 
Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGiIlya Rybak
 
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 Howmrdon
 
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil BartlettCook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlettmfrancis
 
Scaling and Orchestrating Microservices with OSGi - N Bartlett
Scaling and Orchestrating Microservices with OSGi - N BartlettScaling and Orchestrating Microservices with OSGi - N Bartlett
Scaling and Orchestrating Microservices with OSGi - N Bartlettmfrancis
 
Apache Aries: A blueprint for developing with OSGi and JEE
Apache Aries: A blueprint for developing with OSGi and JEEApache Aries: A blueprint for developing with OSGi and JEE
Apache Aries: A blueprint for developing with OSGi and JEEmahrwald
 
Modular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafModular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafIoan Eugen Stan
 
OSGi Web Development in Action
OSGi Web Development in Action	OSGi Web Development in Action
OSGi Web Development in Action OSGiUsers
 
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)Kai Wähner
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in PractiseDavid Bosschaert
 

Viewers also liked (18)

Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
Praktyczne wprowadzenie do OSGi i Enterprise OSGi
Praktyczne wprowadzenie do OSGi i Enterprise OSGiPraktyczne wprowadzenie do OSGi i Enterprise OSGi
Praktyczne wprowadzenie do OSGi i Enterprise OSGi
 
The Java Carputer
The Java CarputerThe Java Carputer
The Java Carputer
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
Deep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle LayerDeep dive into OSGi Lifecycle Layer
Deep dive into OSGi Lifecycle Layer
 
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
 
JavaEE + OSGi
JavaEE + OSGiJavaEE + OSGi
JavaEE + OSGi
 
Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGi
 
OSGi & Blueprint
OSGi & BlueprintOSGi & Blueprint
OSGi & Blueprint
 
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
 
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil BartlettCook Up a Runtime with The New OSGi Resolver - Neil Bartlett
Cook Up a Runtime with The New OSGi Resolver - Neil Bartlett
 
Scaling and Orchestrating Microservices with OSGi - N Bartlett
Scaling and Orchestrating Microservices with OSGi - N BartlettScaling and Orchestrating Microservices with OSGi - N Bartlett
Scaling and Orchestrating Microservices with OSGi - N Bartlett
 
Apache Aries: A blueprint for developing with OSGi and JEE
Apache Aries: A blueprint for developing with OSGi and JEEApache Aries: A blueprint for developing with OSGi and JEE
Apache Aries: A blueprint for developing with OSGi and JEE
 
Modular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache KarafModular Java applications with OSGi on Apache Karaf
Modular Java applications with OSGi on Apache Karaf
 
OSGi Blueprint Services
OSGi Blueprint ServicesOSGi Blueprint Services
OSGi Blueprint Services
 
OSGi Web Development in Action
OSGi Web Development in Action	OSGi Web Development in Action
OSGi Web Development in Action
 
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
 
Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in Practise
 

Recently uploaded

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

Modular Java With Osgi and Karaf

  • 1. Modular Java with OSGi and Karaf by Cristiano Costantini and Giuseppe Gerla
  • 3. What does “module” means? “A software module is a deployable, manageable, natively reusable, composable, stateless unit of software that provides a concise interface to consumers” Deployable: modules are unit of deployment. Manageable: modules are unit of management. Natively Reusable: modules are a unit of intraprocess reuse. Composable: modules are a unit of composition. Stateless: modules are stateless (*running software from a module has a state). Testability: modules are a unit of testability. uhm… the JAR file! 3
  • 4. Where to find modularity? 4 There are two facets of Modularity x Development Model x Runtime Model
  • 5. Why modularity? “Modularity is the best hope to reduce the costs of changes due to architectural decisions” 5 “to tame complexity”
  • 6. 6
  • 7. 7
  • 10. Modularity Patterns 10 Base Patterns Base patterns advise to design and manage relationships between modules, that you have to emphasize reusability at software module level, and that modules shall be cohesive and have a behavior that serves a singular purpose.
  • 11. Modularity Patterns 11 Dependency Patterns Dependency patterns teach you that there must be no cycles between modules, that should be organized in levels and in physical layers. And that a module should be independent from the runtime container and deployable independently from other modules.
  • 13. Modularity Patterns 13 Usability, Extensibility, Utility Patterns The modules shall have a public interface that is well known. Modules are configured externally. For improving usability, create a façade serving as a coarse-grained entry point to another fine-grained module. Restricted dependency to theabstract elements of the moduleso to improve extensibility andreduce the number of dependencies. Rely heavily on the use of implementation factories anddependencies injection framework. Separate abstractions from theclasses that implement them inseparate modules, so to helpeliminate module relationships. Perform a levelized build, repeatable build of the modules. This has positive effect on the lifecycle of software development as a levelized build integrate testing that require to integrate early and often, which guarantees a system health always in a good status. Modules should have a test module.
  • 14. Let’s open pack 1: 14 Development Model x Development Model
  • 15. Let’s open pack 1: 15 Development Model
  • 16. Let’s open pack 2: 16 Runtime Model x Runtime Model
  • 17. Let’s open pack 2: 17 Runtime Model
  • 18. Karaf
  • 19. Karaf: an OSGi container Karaf is a small OSGi based runtime which provides a lightweight container onto which various components and applications can be deployed. 19 Apache Karaf can trace it's origins back to the Apache ServiceMix project's Kernel.
  • 20. Karaf: what is it in detail? Karaf is a platform that allow you to deploy your application. You can install/uninstall/ start/stop your application in several easy way. You can replace/update it and you can change its configuration on the fly. 20
  • 21. Karaf: what is an application? An application is a composition of modules. Each module can depend from other modules of application or from other module of the container. 21
  • 22. Karaf: what is a module? A module is a bundle Bundle is a Jar with a Manifest richer than that one We can develop a bundle using Eclipse and Maven 22
  • 23. Karaf: how a bundle interact? Each bundle can registers one or more service. Each service can be retrieved by other bundle. Each service can obtain the reference of other services. 23
  • 24. Karaf: What is a service? We can define a service using the SOA definition. “A Service is a self-contained unit of functionality” Caution: service in OSGi is NOT a WebService but it is an intra-JVM service. 24
  • 25. No WebServices? Don’t worry: using Camel you can extend an OSGi service with a WebService and more (as we’ll see later). 25
  • 26. Karaf & Spring Karaf has its own Dependency Injection API: Blueprint Blueprint is a standard defined in OSGi that allow bean definition, service definition and dependency injection Using Spring Dynamic Module we can also use Spring in Karaf. SpringDM explores bundles and load Spring xml files Spring DM allows you to interact with the world without using OSGi API in our code: in this way the code is cleaner and classes that we write (our modules) can be reused on other platforms. 26
  • 27. Karaf + Camel = ServiceMix 27 + =
  • 28. Karaf & Web 28 Pax Web allows Karaf to support web. Using integrated Web Server Jetty, it implements: -HTTP Service API defined in OSGi -Web Application API defined in OSGi Enterprise Like Spring DM, Pax Web explores Bundles installed in Karaf to find web.xml files. When it finds ithe filet, Pax Web starts application by creating servlets,filters and initializing servlet context defined in web deployment descriptor.
  • 29. SensorMix An example of a Java Modular Application
  • 33. SensorMix 33 Integration Bundle: Camel routes for sensors’ samples
  • 34. SensorMix 34 Data Service Bundle: persistence of data
  • 35. SensorMix Slides: http://cristcost.github.io/sensormix/ Sensormix: https://github.com/cristcost/sensormix/ Sensormix Android: https://github.com/cristcost/sensormix-android/ Sensormix Arduino: https://github.com/michelefi/sensormix-arduino/ 35 Links:
  • 37. Books • “Java Application Architecture: Modularity Patterns with Examples Using OSGi”, Kirk Knoernschild - Prentice Hall • “Spring DM in Action”, A. Cogoluègnes, T. Templier, A. Piper - Manning • “OSGi in Action”, R. S. Hall, K. Pauls, S. McCulloch, D. Savage - Manning • “OSGi In depth”, Alexandre de Castro Alves - Manning • “Enterprise Integration Patterns”, G. Hohpe, B. Woolf - Addison Wesley • “Camel in Action”, C. Ibsen, J. Anstey - Manning 37
  • 38. Modularity is good Follow Modular Patterns Build modular java software with Maven Run modular java software with Karaf Check SensorMix for an example lesson learnt: