Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Is OSGi Modularity
Always Worth It?
Glyn Normington
Agenda
• Costs and benefits
• Case studies
• When is OSGi worth it?
OSGi Benefits
✓Encapsulated module internals
✓Easier to understand, maintain, and extend
✓Explicit, versioned dependencies
...
OSGi Benefits
✓Side-by-side versioning
✓Dynamism
✓Loose coupling via services
OSGi Costs
Learning: OSGi, new runtime, new tools
Reusing 3rd party JARs
Designing appropriate bundles and services
Definin...
vert.x Case Study
vert.x
• Asynchronous, event-driven web apps
• HTTP, WebSockets, sockjs
• Apps in Java, Groovy, JavaScript, Ruby
•Apps nee...
class loaderclass loader
server
verticle busmod
event bus
JSON JSON
client
vert.x
HTTP, WebSockets, sockjs
modulemodule
Converting vert.x to OSGi
• Convert vert.x runtime to bundles
• Convert verticles to bundles
• (Convert busmods to bundles...
Convert Runtime to Bundles
• JARs:
• vert.x core
• Netty - network IO
• Jackson & Jackson Mapper - JSON
Approach
• Eye-ball existing OSGi manifests
• Generate manifests where necessary
• Use bnd orVirgo bundlor
• Create a mani...
Existing OSGi Manifests
✓Netty
• Bundle version 3.4.2.Final
✓Jackson & Jackson Mapper
• Bundle version 1.9.4
Bundle vert.x core
• Use bnd orVirgo bundlor
• Manifest template required ...
vert.x Core Template
• vert.x name and version
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.vertx.core
Bundle-Name: ...
vert.x Core Template
• Package import template version ranges
• Netty: [3.4.2.Final, 4.0)
• Jackson: [1.9.4, 2.0)
• Other ...
• Package import version ranges
• Netty: [3.4.2.Final, 4.0)
• Jackson: [1.9.4, 2.0)
• Other optional imports: 0
• 0 means ...
Version Ranges
• Lower bound
• What did you test?
• What old versions do you support?
• Upper bound
• Exporter’s versionin...
NettyVersion Range
[3.4.2.Final, 3.5)[3.4.2.Final, 4.0)
Generate Bundle
bundlor.sh -i vert.x-core.jar
-m vertx.core.mf
-o vert.x-core-1.0.0.final.jar
Test Metadata
• UsingVirgo, for simplicity
• Place dependencies in repository/usr
• Place vert.x core in pickup
• StartVir...
ModularVerticles
public class MyVerticle extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(
new Handler<Http...
public class MyVerticle extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(
new Handler<Http...
public class MyVerticle extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(
new Handler<Http...
public class MyVerticle extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(
new Handler<Http...
public class MyVerticle extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(
new Handler<Http...
ModularVerticle
• Move boilerplate code to a support bundle
• Convert configuration to declarative
metadata
• Use services ...
public class MyHandler implements
Handler<HttpServerRequest> {
public void handle(HttpServerRequest req) {
...
}
}
<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean class="org.ver...
org.vertx.core
bundle
modular
verticle
bundle
org.vertx.osgi
bundle
OSGi Service Registry
2. publish handler
3. listen for...
Was it worth it?
Benefits
✓vertx implementation can be hidden
✓Boilerplate factored out
✓Unit testing simplified
✓Configuration externalised
Costs
Deciding dependency version ranges
Reworking vert.x to improve encapsulation
Programming model changed
Shared depend...
Costs
Deciding dependency version ranges
Reworking vert.x to improve encapsulation
Programming model changed
Shared depend...
vSphere Web Client
Case Study
vSphere Web Client
• OSGi based web server
• Virgo Server for Apache Tomcat
• Plugins allow users to extend the Web Client...
browser
Virgo
(vSphere
Web Client)
vCenter Server
Flex UI
component
Data
Service
VMware
Inventory
Service
ESX
Server
ESX
S...
browser
Virgo
(vSphere
Web Client)
vCenter Server
Flex UI
component
Data
Service
VMware
Inventory
Service
Remote Data
Sour...
Was it worth it?
Benefits
✓Modular
✓Extensible by users
✓Internals not accessible to users
✓Dynamically updateable
Costs
Steep initial learning curve
Investment required inVirgo tooling
OSGi exposed to users
Costs
Steep initial learning curve
Investment required inVirgo tooling
OSGi exposed to users
Conclusion: worth it
Croatian Telecom
Case Study
Overview
• Virgo 3.0.3, EclipseLink,Atomikos,
ActiveMQ,Tomcat clustering, Hazelcast
• In production for more than a year
•...
Cited Benefits
✓Better understand components you use
✓Cleaner, higher quality code
✓Better system architecture
✓Reusable mo...
Cited Costs
Time to learn the intricacies of OSGi
Time to integrate non-OSGi ready
components
Cited Costs
Time to learn the intricacies of OSGi
Time to integrate non-OSGi ready
components
Conclusion: worth it
Wrap-up
OSGi Costs
Learning: OSGi, new runtime, new tools
Reusing 3rd party JARs
Designing appropriate bundles and services
Definin...
OSGi Benefits
✓Encapsulated module internals
✓Explicit, versioned dependencies
✓Side-by-side versioning
✓Dynamism
✓Visible ...
When is OSGi worth it?
✓Lower layers benefit most
✓Control dependencies
✓Hide internals
Lower layers push higher layers to ...
PRO TANTO QUID RETRIBUAMUS
For so much, what shall we give in return?
(wording from the edge of the Belfast £1 coin)
Further Information
• “Java Application Architecture” by Kirk
Knoernschild
• http://www.osgi.org
• http://underlap.blogspo...
Credits
• “Coins” by Rob Redwood
• “Benefits of using OSGi”
http://www.osgi.org/Technology/WhyOSGi
• “One Pound” by Leo Rey...
Upcoming SlideShare
Loading in …5
×

Is OSGi Modularity Always Worth It? - Glyn Normington

454 views

Published on

OSGi Community Event 2012

Published in: Technology
  • Be the first to comment

Is OSGi Modularity Always Worth It? - Glyn Normington

  1. 1. Is OSGi Modularity Always Worth It? Glyn Normington
  2. 2. Agenda • Costs and benefits • Case studies • When is OSGi worth it?
  3. 3. OSGi Benefits ✓Encapsulated module internals ✓Easier to understand, maintain, and extend ✓Explicit, versioned dependencies ✓Simplified impact analysis ✓Faster class loading ✓Visible architecture ✓bundles, services, dependencies ✓execution environment
  4. 4. OSGi Benefits ✓Side-by-side versioning ✓Dynamism ✓Loose coupling via services
  5. 5. OSGi Costs Learning: OSGi, new runtime, new tools Reusing 3rd party JARs Designing appropriate bundles and services Defining and upgrading dependencies Building bundles Debugging resolution failures and class loading Coping with dynamism
  6. 6. vert.x Case Study
  7. 7. vert.x • Asynchronous, event-driven web apps • HTTP, WebSockets, sockjs • Apps in Java, Groovy, JavaScript, Ruby •Apps need not be thread safe • JSON event bus
  8. 8. class loaderclass loader server verticle busmod event bus JSON JSON client vert.x HTTP, WebSockets, sockjs modulemodule
  9. 9. Converting vert.x to OSGi • Convert vert.x runtime to bundles • Convert verticles to bundles • (Convert busmods to bundles - similarly)
  10. 10. Convert Runtime to Bundles • JARs: • vert.x core • Netty - network IO • Jackson & Jackson Mapper - JSON
  11. 11. Approach • Eye-ball existing OSGi manifests • Generate manifests where necessary • Use bnd orVirgo bundlor • Create a manifest template • Test resolution
  12. 12. Existing OSGi Manifests ✓Netty • Bundle version 3.4.2.Final ✓Jackson & Jackson Mapper • Bundle version 1.9.4
  13. 13. Bundle vert.x core • Use bnd orVirgo bundlor • Manifest template required ...
  14. 14. vert.x Core Template • vert.x name and version Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.vertx.core Bundle-Name: vert.x Core Bundle-Version: 1.0.0.final Export-Template: *;version="1.0.0.final"
  15. 15. vert.x Core Template • Package import template version ranges • Netty: [3.4.2.Final, 4.0) • Jackson: [1.9.4, 2.0) • Other optional imports: 0 • 0 means [0, ∞)
  16. 16. • Package import version ranges • Netty: [3.4.2.Final, 4.0) • Jackson: [1.9.4, 2.0) • Other optional imports: 0 • 0 means [0, ∞) vert.x Core Template Where did these come from?
  17. 17. Version Ranges • Lower bound • What did you test? • What old versions do you support? • Upper bound • Exporter’s versioning policy? • How easy is it to change your bundle? • Lifespan? • Distribution?
  18. 18. NettyVersion Range [3.4.2.Final, 3.5)[3.4.2.Final, 4.0)
  19. 19. Generate Bundle bundlor.sh -i vert.x-core.jar -m vertx.core.mf -o vert.x-core-1.0.0.final.jar
  20. 20. Test Metadata • UsingVirgo, for simplicity • Place dependencies in repository/usr • Place vert.x core in pickup • StartVirgo: ... <DE0005I> Started bundle 'org.vertx.core' version '1.0.0.final'.
  21. 21. ModularVerticles
  22. 22. public class MyVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler( new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { ... } } ).listen(8080); } }
  23. 23. public class MyVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler( new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { ... } } ).listen(8080); } }
  24. 24. public class MyVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler( new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { ... } } ).listen(8080); } } redundant boilerplate
  25. 25. public class MyVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler( new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { ... } } ).listen(8080); } } redundant boilerplate not easily unit tested
  26. 26. public class MyVerticle extends Verticle { public void start() { vertx.createHttpServer().requestHandler( new Handler<HttpServerRequest>() { public void handle(HttpServerRequest req) { ... } } ).listen(8080); } } baked-in configuration redundant boilerplate not easily unit tested
  27. 27. ModularVerticle • Move boilerplate code to a support bundle • Convert configuration to declarative metadata • Use services for loose coupling • whiteboard pattern
  28. 28. public class MyHandler implements Handler<HttpServerRequest> { public void handle(HttpServerRequest req) { ... } }
  29. 29. <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean class="org.vertx.osgi.sample.MyHandler" id="handler"/> <service interface="org.vertx.java.core.Handler" ref="handler"> <service-properties> <entry key="type" value="HttpServerRequestHandler"> <entry key="port" value="8080"> </service-properties> </service> </blueprint>
  30. 30. org.vertx.core bundle modular verticle bundle org.vertx.osgi bundle OSGi Service Registry 2. publish handler 3. listen for/find handler 4. create server 5 register handler 6. set server listening 7. request from network 8. Handler.handle()9. HttpServerRequest operations blueprint service 1. listen for/find bundle
  31. 31. Was it worth it?
  32. 32. Benefits ✓vertx implementation can be hidden ✓Boilerplate factored out ✓Unit testing simplified ✓Configuration externalised
  33. 33. Costs Deciding dependency version ranges Reworking vert.x to improve encapsulation Programming model changed Shared dependencies must be thread safe
  34. 34. Costs Deciding dependency version ranges Reworking vert.x to improve encapsulation Programming model changed Shared dependencies must be thread safe Conclusion: probably not worth it
  35. 35. vSphere Web Client Case Study
  36. 36. vSphere Web Client • OSGi based web server • Virgo Server for Apache Tomcat • Plugins allow users to extend the Web Client • Custom data • Custom relationships (for new/existing data)
  37. 37. browser Virgo (vSphere Web Client) vCenter Server Flex UI component Data Service VMware Inventory Service ESX Server ESX Server ESX Server VMVMVM BlazeDS
  38. 38. browser Virgo (vSphere Web Client) vCenter Server Flex UI component Data Service VMware Inventory Service Remote Data Source Custom Flex UI component Custom Data Service ESX Server ESX Server ESX Server VMVMVM plugin zip plugin zip plugin zip BlazeDS BlazeDS
  39. 39. Was it worth it?
  40. 40. Benefits ✓Modular ✓Extensible by users ✓Internals not accessible to users ✓Dynamically updateable
  41. 41. Costs Steep initial learning curve Investment required inVirgo tooling OSGi exposed to users
  42. 42. Costs Steep initial learning curve Investment required inVirgo tooling OSGi exposed to users Conclusion: worth it
  43. 43. Croatian Telecom Case Study
  44. 44. Overview • Virgo 3.0.3, EclipseLink,Atomikos, ActiveMQ,Tomcat clustering, Hazelcast • In production for more than a year • last 7 months as a cluster • Nearly 1 million user accounts • 100s of web requests per second, peak • Only one major outage, due to a Linux bug
  45. 45. Cited Benefits ✓Better understand components you use ✓Cleaner, higher quality code ✓Better system architecture ✓Reusable modules
  46. 46. Cited Costs Time to learn the intricacies of OSGi Time to integrate non-OSGi ready components
  47. 47. Cited Costs Time to learn the intricacies of OSGi Time to integrate non-OSGi ready components Conclusion: worth it
  48. 48. Wrap-up
  49. 49. OSGi Costs Learning: OSGi, new runtime, new tools Reusing 3rd party JARs Designing appropriate bundles and services Defining and upgrading dependencies Building bundles Debugging resolution failures and class loading Coping with dynamism Reduced isolation in some cases Further investment in tooling required
  50. 50. OSGi Benefits ✓Encapsulated module internals ✓Explicit, versioned dependencies ✓Side-by-side versioning ✓Dynamism ✓Visible architecture ✓Loose coupling via services ✓Better understanding of components used ✓Reusable modules
  51. 51. When is OSGi worth it? ✓Lower layers benefit most ✓Control dependencies ✓Hide internals Lower layers push higher layers to OSGi ? Exposing OSGi to users ✓Long-lived or critical applications
  52. 52. PRO TANTO QUID RETRIBUAMUS For so much, what shall we give in return? (wording from the edge of the Belfast £1 coin)
  53. 53. Further Information • “Java Application Architecture” by Kirk Knoernschild • http://www.osgi.org • http://underlap.blogspot.co.uk/2012/06/osgi- case-study-modular-vertx.html • http://vertx.io/ • http://underlap.blogspot.co.uk/2012/10/ virgo-in-vsphere.html • http://www.osgi.org/wiki/uploads/Links/ SemanticVersioning.pdf
  54. 54. Credits • “Coins” by Rob Redwood • “Benefits of using OSGi” http://www.osgi.org/Technology/WhyOSGi • “One Pound” by Leo Reynolds

×