OSGi ecosystems compared on Apache Karaf - Christian Schneider
Modular Java With Osgi and Karaf
-
Upload
cristiano-costantini -
Category
Technology
-
view
796 -
download
3
description
Transcript of Modular Java With Osgi and Karaf
![Page 1: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/1.jpg)
Modular Java with OSGi and Karafby Cristiano Costantini and Giuseppe Gerla
![Page 2: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/2.jpg)
Modularity
![Page 3: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/3.jpg)
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
![Page 4: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/4.jpg)
Where to find modularity?
4
There are two facets of Modularity
x Development Model
x Runtime Model
![Page 5: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/5.jpg)
Why modularity?
“Modularity is the best hope to reduce the costs of changes due to
architectural decisions”
5
“to tame complexity”
![Page 6: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/6.jpg)
6
![Page 7: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/7.jpg)
7
![Page 8: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/8.jpg)
Modularity in Java
8
![Page 9: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/9.jpg)
Modularity Patterns
9
![Page 10: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/10.jpg)
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.
![Page 11: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/11.jpg)
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.
![Page 12: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/12.jpg)
Modularity Patterns
12
Dependency Patterns: NO CYCLES!
NO CYCLES!
![Page 13: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/13.jpg)
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 the abstract elements of the module so to improve extensibility and reduce the number of dependencies.
Rely heavily on the use of implementation factories and dependencies injection framework.
Separate abstractions from the classes that implement them in separate modules, so to help eliminate 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.
![Page 14: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/14.jpg)
Let’s open pack 1:
14
Development Model
x Development Model
![Page 15: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/15.jpg)
Let’s open pack 1:
15
Development Model
![Page 16: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/16.jpg)
Let’s open pack 2:
16
Runtime Model
x Runtime Model
![Page 17: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/17.jpg)
Let’s open pack 2:
17
Runtime Model
![Page 18: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/18.jpg)
Karaf
![Page 19: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/19.jpg)
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.
![Page 20: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/20.jpg)
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
![Page 21: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/21.jpg)
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
![Page 22: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/22.jpg)
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
![Page 23: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/23.jpg)
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
![Page 24: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/24.jpg)
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
![Page 25: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/25.jpg)
No WebServices?
Don’t worry: using Camel you can extend an OSGi service with a WebService and more (as we’ll see later).
25
![Page 26: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/26.jpg)
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
![Page 27: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/27.jpg)
Karaf + Camel = ServiceMix
27
+ =
![Page 28: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/28.jpg)
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.
![Page 29: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/29.jpg)
SensorMixAn example of a Java Modular Application
![Page 30: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/30.jpg)
SensorMix
30
External Architecture
![Page 31: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/31.jpg)
SensorMix
31
Internal Architecture
![Page 32: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/32.jpg)
SensorMix
32
Canonical Data Model Bundle
![Page 33: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/33.jpg)
SensorMix
33
Integration Bundle: Camel routes for sensors’ samples
![Page 34: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/34.jpg)
SensorMix
34
Data Service Bundle: persistence of data
![Page 35: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/35.jpg)
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:
![Page 36: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/36.jpg)
Conclusions
![Page 37: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/37.jpg)
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
![Page 38: Modular Java With Osgi and Karaf](https://reader034.fdocuments.us/reader034/viewer/2022050919/5478acb05906b58f048b4595/html5/thumbnails/38.jpg)
Modularity is goodFollow Modular PatternsBuild modular java software with MavenRun modular java software with KarafCheck SensorMix for an example
lesson learnt: