Polyglot
OSGi
Matt Stine
Or...
“How to sneak your favorite JVM language into
the enterprise!”
polyglot
Many Languages
From Ancient Greek πολύγλωττος
(poluglōttos), “‘'many-tongued, polyglot'’”), from
πολύ...
Polyglot Programming
We are entering a new era of software development.
For most of our (short) history, we've primarily w...
The Golden
Hammer
Anti-pattern
Using the same tool,
product, or technique to
solve every problem
The Golden
Hammer
Anti-pattern
Using the same tool,
product, or technique to
solve every problem
You’re doing it already...
You’re doing it already...
SQL
You’re doing it already...
SQL
JavaScript
You’re doing it already...
SQL
JavaScript
XML
You’re doing it already...
SQL
JavaScript
XML
HTML
You’re doing it already...
SQL
JavaScript
XML
HTML
Ant/Maven
Adoption of additional languages is driven
by critical mass being reached in an area
of business or technical demand.
Drivers
SQL
JavaScript
XML
HTML
Ant/Maven
Drivers
SQL Data Management in
RDBMS
JavaScript
XML
HTML
Ant/Maven
Drivers
SQL Data Management in
RDBMS
JavaScript Web 2.0/Ajax
XML
HTML
Ant/Maven
Drivers
SQL Data Management in
RDBMS
JavaScript Web 2.0/Ajax
XML Data interchange
HT...
Drivers
SQL Data Management in
RDBMS
JavaScript Web 2.0/Ajax
XML Data interchange
HT...
Drivers
SQL Data Management in
RDBMS
JavaScript Web 2.0/Ajax
XML Data interchange
HT...
Drivers?
Drivers?
Polyglot Drivers
Polyglot Drivers
Concurrency/Multi-core Hardware
Polyglot Drivers
Concurrency/Multi-core Hardware
Framework Availability
Polyglot Drivers
Concurrency/Multi-core Hardware
Framework Availability
Special purpose language constructs/libraries
Polyglot Drivers
Concurrency/Multi-core Hardware
Framework Availability
Special purpose language constructs/libraries
...
Polyglot Drivers
Concurrency/Multi-core Hardware
Framework Availability
Special purpose language constructs/libraries
...
Polyglot Drivers
Concurrency/Multi-core Hardware
Framework Availability
Special purpose language constructs/libraries
...
OSGi
The Dynamic Module system for Java
OSGi Architecture
Application/Bundles
Services
...
SOA in a JVM!
OSGi
Service
Registry
...
Modularity...how?
Modularity...how?
Encapsulation
Modularity...how?
Encapsulation
Service Registry
Modularity...how?
Encapsulation
Service Registry
Versioning
Bundle Versioning
Foo
1.0.0
Bar ...
Modularity...how?
Encapsulation
Service Registry
Versioning
Modularity...how?
Encapsulation
Service Registry
Versioning
Dynamism/Lifecycle
Modularity...how?
Encapsulation
Service Registry
Versioning
Dynamism/Lifecycle
Strong-Naming
OSGi Implementations
OSGi Implementations
Equinox
PAX Tools for OSGi
PaxConstruct
PaxConstruct
Script-oriented toolkit for OSGi development
PaxConstruct
Script-oriented toolkit for OSGi development
Similar to Rails/Grails development model
PaxConstruct
Script-oriented toolkit for OSGi development
Similar to Rails/Grails development model
Built on Maven 2
PaxConstruct
Script-oriented toolkit for OSGi development
Similar to Rails/Grails development model
Built on Maven 2
PaxRunner
PaxRunner
OSGi framework launcher
PaxRunner
OSGi framework launcher
Facilitates quick start OSGi exploration
PaxRunner
OSGi framework launcher
Facilitates quick start OSGi exploration
Facilitates swapping OSGi platforms (works with...
PaxRunner
OSGi framework launcher
Facilitates quick start OSGi exploration
Facilitates swapping OSGi platforms (works with...
PaxRunner
OSGi framework launcher
Facilitates quick start OSGi exploration
Facilitates swapping OSGi platforms (works with...
PaxExam
PaxExam
Testing toolkit for OSGi
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
Flow:
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
Flow:
Starts OSGi container of ...
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
Flow:
Starts OSGi container of ...
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
Flow:
Starts OSGi container of ...
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
Flow:
Starts OSGi container of ...
PaxExam
Testing toolkit for OSGi
Facilitates in-container integration testing of bundles
Flow:
Starts OSGi container of ...
Why Polyglot OSGi?
Why Polyglot OSGi?
Java Java Service
Java Client
Service Implementation
...
Why Polyglot OSGi?
Java Java Service
Java Client
Service Implementation
...
Why Polyglot OSGi?
Java Java Service
Java Client
Service Implementation
...
Why Polyglot OSGi?
Java Java Service
Java Client
Service Implementation
...
Why Polyglot OSGi?
Java Groovy Service
Java Service
Java Client
...
Why Polyglot OSGi?
Java GroovyService
Scala Service
...
Why Polyglot OSGi?
Java GroovyService
Clojure Service
...
Why Polyglot OSGi?
Java GroovyService
Clojure Service
...
The line must be drawn HERE!
Polyglot OSGi Pros
Polyglot OSGi Pros
Manage Risk
Polyglot OSGi Pros
Manage Risk
Encapsulation
Polyglot OSGi Pros
Manage Risk
Encapsulation
Decoupled Architecture
Polyglot OSGi Pros
Manage Risk
Encapsulation
Decoupled Architecture
Java = JVM Lingua Franca
Polyglot OSGi Cons
Polyglot OSGi Cons
Constant Java translation at boundary
Polyglot OSGi Cons
Constant Java translation at boundary
Less idiomatic code
Polyglot OSGi Cons
Constant Java translation at boundary
Less idiomatic code
Language / OSGi mismatch
Polyglot OSGi Cons
Constant Java translation at boundary
Less idiomatic code
Language / OSGi mismatch
Not a silver bullet...
A Polylgot OSGi Vending Machine
PGOVM Specification
Valid Actions:
NICKLE, DIME, QUARTER, DOLLAR - insert money
COIN RETURN - returns all inserted mone...
PGOVM Specification
Valid Responses:
NICKLE, DIME, QUARTER - return coin
A, B, C - vend item A, B, or C
Track state:
...
PGOVM Specification
Example Traces:
Buy B with exact change:
Q, Q, Q, Q, GET-B
-> B
Add change, hit coin return:
...
Why this spec?
Why this spec?
Simple to understand, yet...
Why this spec?
Simple to understand, yet...
...demonstrates reasonable complexity one might find
in a real application
Why this spec?
Simple to understand, yet...
...demonstrates reasonable complexity one might find
in a real application
Al...
Goals
Implement a Java interface contract for the spec
Test-drive a Java implementation
Use tests as a contract to impleme...
DEMO
http://localhost:8080/pgovm/vm.html
Java Contract
PaxExam Tests
Run Test Demo
Groovy Implementation
Scala
Implementation
Scala Gotchas
Scala Gotchas
Scala in Maven Central is NOT an OSGi Bundle!
Scala Gotchas
Scala in Maven Central is NOT an OSGi Bundle!
Can download from http://scala-lang.org.
Scala Gotchas
Scala in Maven Central is NOT an OSGi Bundle!
Can download from http://scala-lang.org.
Swap it out manually....
Scala Gotchas
Scala in Maven Central is NOT an OSGi Bundle!
Can download from http://scala-lang.org.
Swap it out manually....
Scala Gotchas
Scala in Maven Central is NOT an OSGi Bundle!
Can download from http://scala-lang.org.
Swap it out manually....
Scala Gotchas
Scala in Maven Central is NOT an OSGi Bundle!
Can download from http://scala-lang.org.
Swap it out manually....
Clojure
Implementation
Clojure Gotchas
Clojure Gotchas
Clojure also not available as an OSGi bundle!
Clojure Gotchas
Clojure also not available as an OSGi bundle!
Use Pax Construct to embed in bundle for Clojure
implementa...
Clojure Gotchas
Clojure also not available as an OSGi bundle!
Use Pax Construct to embed in bundle for Clojure
implementa...
Clojure Gotchas
Clojure also not available as an OSGi bundle!
Use Pax Construct to embed in bundle for Clojure
implementa...
Clojure Gotchas
Clojure Gotchas
Not OSGi related, but...
Clojure Gotchas
Not OSGi related, but...
Maven Clojure Plugin won’t seem to compile Clojure
first, so if your Java code d...
Clojure Gotchas
Not OSGi related, but...
Maven Clojure Plugin won’t seem to compile Clojure
first, so if your Java code d...
Spring MVC Web
Implementation
That’s all folks!
Please fill out your evaluations!
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
Polyglot OSGi
of 130

Polyglot OSGi

Published on: Mar 4, 2016
Published in: Technology      
Source: www.slideshare.net


Transcripts - Polyglot OSGi

  • 1. Polyglot OSGi Matt Stine
  • 2. Or... “How to sneak your favorite JVM language into the enterprise!”
  • 3. polyglot Many Languages From Ancient Greek πολύγλωττος (poluglōttos), “‘'many-tongued, polyglot'’”), from πολύς (polus), “‘many’”) + γλῶττα (glōtta), “‘'tongue, language'’”)
  • 4. Polyglot Programming We are entering a new era of software development. For most of our (short) history, we've primarily written code in a single language...but I'm beginning to see a time where even the core language...will cease its monoculture...applications of the future will take advantage of the polyglot nature of the language world...it's all about choosing the right tool for the job and leveraging it correctly...the times of writing an application in a single general purpose language is over. - Excerpts from: Neal Ford, “Polyglot Programming” http://memeagora.blogspot.com/2006/12/polyglot- programming.html
  • 5. The Golden Hammer Anti-pattern Using the same tool, product, or technique to solve every problem
  • 6. The Golden Hammer Anti-pattern Using the same tool, product, or technique to solve every problem
  • 7. You’re doing it already...
  • 8. You’re doing it already... SQL
  • 9. You’re doing it already... SQL JavaScript
  • 10. You’re doing it already... SQL JavaScript XML
  • 11. You’re doing it already... SQL JavaScript XML HTML
  • 12. You’re doing it already... SQL JavaScript XML HTML Ant/Maven
  • 13. Adoption of additional languages is driven by critical mass being reached in an area of business or technical demand.
  • 14. Drivers SQL JavaScript XML HTML Ant/Maven
  • 15. Drivers SQL Data Management in RDBMS JavaScript XML HTML Ant/Maven
  • 16. Drivers SQL Data Management in RDBMS JavaScript Web 2.0/Ajax XML HTML Ant/Maven
  • 17. Drivers SQL Data Management in RDBMS JavaScript Web 2.0/Ajax XML Data interchange HTML Ant/Maven
  • 18. Drivers SQL Data Management in RDBMS JavaScript Web 2.0/Ajax XML Data interchange HTML Web 1.0 Ant/Maven
  • 19. Drivers SQL Data Management in RDBMS JavaScript Web 2.0/Ajax XML Data interchange HTML Web 1.0 Ant/Maven Build configuration
  • 20. Drivers?
  • 21. Drivers?
  • 22. Polyglot Drivers
  • 23. Polyglot Drivers Concurrency/Multi-core Hardware
  • 24. Polyglot Drivers Concurrency/Multi-core Hardware Framework Availability
  • 25. Polyglot Drivers Concurrency/Multi-core Hardware Framework Availability Special purpose language constructs/libraries
  • 26. Polyglot Drivers Concurrency/Multi-core Hardware Framework Availability Special purpose language constructs/libraries Essence over Ceremony
  • 27. Polyglot Drivers Concurrency/Multi-core Hardware Framework Availability Special purpose language constructs/libraries Essence over Ceremony Testing
  • 28. Polyglot Drivers Concurrency/Multi-core Hardware Framework Availability Special purpose language constructs/libraries Essence over Ceremony Testing The JVM Itself
  • 29. OSGi The Dynamic Module system for Java
  • 30. OSGi Architecture Application/Bundles Services Security OSGi Platform Service Registry Lifecycle Modules Java Virtual Machine Java Platform Operating System Hardware Inspired by Modular Java (Craig Walls), page 16
  • 31. SOA in a JVM! OSGi Service Registry Dis ice c erv ov sS ers ter Se gis rvi Re ce Service Consumes Service Consumer Bundle Bundle Inspired by Modular Java (Craig Walls), page 17
  • 32. Modularity...how?
  • 33. Modularity...how? Encapsulation
  • 34. Modularity...how? Encapsulation Service Registry
  • 35. Modularity...how? Encapsulation Service Registry Versioning
  • 36. Bundle Versioning Foo 1.0.0 Bar Qib 1.0.2 2.0.1 Zab Zab 1.0.4 2.1.3 Inspired by Modular Java (Craig Walls), page 18
  • 37. Modularity...how? Encapsulation Service Registry Versioning
  • 38. Modularity...how? Encapsulation Service Registry Versioning Dynamism/Lifecycle
  • 39. Modularity...how? Encapsulation Service Registry Versioning Dynamism/Lifecycle Strong-Naming
  • 40. OSGi Implementations
  • 41. OSGi Implementations Equinox
  • 42. PAX Tools for OSGi
  • 43. PaxConstruct
  • 44. PaxConstruct Script-oriented toolkit for OSGi development
  • 45. PaxConstruct Script-oriented toolkit for OSGi development Similar to Rails/Grails development model
  • 46. PaxConstruct Script-oriented toolkit for OSGi development Similar to Rails/Grails development model Built on Maven 2
  • 47. PaxConstruct Script-oriented toolkit for OSGi development Similar to Rails/Grails development model Built on Maven 2
  • 48. PaxRunner
  • 49. PaxRunner OSGi framework launcher
  • 50. PaxRunner OSGi framework launcher Facilitates quick start OSGi exploration
  • 51. PaxRunner OSGi framework launcher Facilitates quick start OSGi exploration Facilitates swapping OSGi platforms (works with all major open source implementations)
  • 52. PaxRunner OSGi framework launcher Facilitates quick start OSGi exploration Facilitates swapping OSGi platforms (works with all major open source implementations) Facilitates provisioning OSGi bundles from multiple sources
  • 53. PaxRunner OSGi framework launcher Facilitates quick start OSGi exploration Facilitates swapping OSGi platforms (works with all major open source implementations) Facilitates provisioning OSGi bundles from multiple sources Magic behind “pax-provision” and PaxExam
  • 54. PaxExam
  • 55. PaxExam Testing toolkit for OSGi
  • 56. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles
  • 57. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles Flow:
  • 58. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles Flow: Starts OSGi container of choice
  • 59. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles Flow: Starts OSGi container of choice Provisions and starts selected bundles
  • 60. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles Flow: Starts OSGi container of choice Provisions and starts selected bundles Injects OSGi BundleContext to your JUnit test
  • 61. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles Flow: Starts OSGi container of choice Provisions and starts selected bundles Injects OSGi BundleContext to your JUnit test Executes a test method
  • 62. PaxExam Testing toolkit for OSGi Facilitates in-container integration testing of bundles Flow: Starts OSGi container of choice Provisions and starts selected bundles Injects OSGi BundleContext to your JUnit test Executes a test method Rinse and repeat until done!
  • 63. Why Polyglot OSGi?
  • 64. Why Polyglot OSGi? Java Java Service Java Client Service Implementation Client Module Server Module
  • 65. Why Polyglot OSGi? Java Java Service Java Client Service Implementation Client Module Server Module
  • 66. Why Polyglot OSGi? Java Java Service Java Client Service Implementation Client Module Server Module
  • 67. Why Polyglot OSGi? Java Java Service Java Client Service Implementation Client Module Server Module
  • 68. Why Polyglot OSGi? Java Groovy Service Java Service Java Client Service Implementation Client Module Server Module
  • 69. Why Polyglot OSGi? Java GroovyService Scala Service Java Service Java Client Service Implementation Client Module Server Module
  • 70. Why Polyglot OSGi? Java GroovyService Clojure Service Scala Service Java Java Client Service Implementation Client Module Server Module
  • 71. Why Polyglot OSGi? Java GroovyService Clojure Service JRubyService Scala Service Java Java Client Service Implementation Client Module Server Module
  • 72. The line must be drawn HERE!
  • 73. Polyglot OSGi Pros
  • 74. Polyglot OSGi Pros Manage Risk
  • 75. Polyglot OSGi Pros Manage Risk Encapsulation
  • 76. Polyglot OSGi Pros Manage Risk Encapsulation Decoupled Architecture
  • 77. Polyglot OSGi Pros Manage Risk Encapsulation Decoupled Architecture Java = JVM Lingua Franca
  • 78. Polyglot OSGi Cons
  • 79. Polyglot OSGi Cons Constant Java translation at boundary
  • 80. Polyglot OSGi Cons Constant Java translation at boundary Less idiomatic code
  • 81. Polyglot OSGi Cons Constant Java translation at boundary Less idiomatic code Language / OSGi mismatch
  • 82. Polyglot OSGi Cons Constant Java translation at boundary Less idiomatic code Language / OSGi mismatch Not a silver bullet for large teams with few polyglots
  • 83. A Polylgot OSGi Vending Machine
  • 84. PGOVM Specification Valid Actions: NICKLE, DIME, QUARTER, DOLLAR - insert money COIN RETURN - returns all inserted money SERVICE - a service person opens the machine and sets the available change and items GET-A, GET-B, GET-C - select item A ($.65), B ($1), or C ($1.50)
  • 85. PGOVM Specification Valid Responses: NICKLE, DIME, QUARTER - return coin A, B, C - vend item A, B, or C Track state: available items (count, price, selector) available change (# of nickles, dimes, quarters, dollars available) currently inserted money
  • 86. PGOVM Specification Example Traces: Buy B with exact change: Q, Q, Q, Q, GET-B -> B Add change, hit coin return: Q, Q, COIN-RETURN -> Q, Q Buy A without exact change (return $.35) DOLLAR, GET-A -> A, Q, D
  • 87. Why this spec?
  • 88. Why this spec? Simple to understand, yet...
  • 89. Why this spec? Simple to understand, yet... ...demonstrates reasonable complexity one might find in a real application
  • 90. Why this spec? Simple to understand, yet... ...demonstrates reasonable complexity one might find in a real application Algorithms suitable for showcasing language features
  • 91. Goals Implement a Java interface contract for the spec Test-drive a Java implementation Use tests as a contract to implement in: Groovy Scala Clojure Build a Spring MVC application to exercise different vending machines
  • 92. DEMO http://localhost:8080/pgovm/vm.html
  • 93. Java Contract
  • 94. PaxExam Tests
  • 95. Run Test Demo
  • 96. Groovy Implementation
  • 97. Scala Implementation
  • 98. Scala Gotchas
  • 99. Scala Gotchas Scala in Maven Central is NOT an OSGi Bundle!
  • 100. Scala Gotchas Scala in Maven Central is NOT an OSGi Bundle! Can download from http://scala-lang.org.
  • 101. Scala Gotchas Scala in Maven Central is NOT an OSGi Bundle! Can download from http://scala-lang.org. Swap it out manually...
  • 102. Scala Gotchas Scala in Maven Central is NOT an OSGi Bundle! Can download from http://scala-lang.org. Swap it out manually... ...however...
  • 103. Scala Gotchas Scala in Maven Central is NOT an OSGi Bundle! Can download from http://scala-lang.org. Swap it out manually... ...however... won’t work with Maven anymore!
  • 104. Scala Gotchas Scala in Maven Central is NOT an OSGi Bundle! Can download from http://scala-lang.org. Swap it out manually... ...however... won’t work with Maven anymore! Use Groovy script to swap out Scala jars.
  • 105. Clojure Implementation
  • 106. Clojure Gotchas
  • 107. Clojure Gotchas Clojure also not available as an OSGi bundle!
  • 108. Clojure Gotchas Clojure also not available as an OSGi bundle! Use Pax Construct to embed in bundle for Clojure implementation.
  • 109. Clojure Gotchas Clojure also not available as an OSGi bundle! Use Pax Construct to embed in bundle for Clojure implementation. Mixed experiences out there with trying to share a common Clojure bundle.
  • 110. Clojure Gotchas Clojure also not available as an OSGi bundle! Use Pax Construct to embed in bundle for Clojure implementation. Mixed experiences out there with trying to share a common Clojure bundle. OGEE Project (Roman Roelofsen) http://ogeesource.org
  • 111. Clojure Gotchas
  • 112. Clojure Gotchas Not OSGi related, but...
  • 113. Clojure Gotchas Not OSGi related, but... Maven Clojure Plugin won’t seem to compile Clojure first, so if your Java code depends on Clojure code...
  • 114. Clojure Gotchas Not OSGi related, but... Maven Clojure Plugin won’t seem to compile Clojure first, so if your Java code depends on Clojure code... Must run “mvn clojure:compile” first
  • 115. Spring MVC Web Implementation
  • 116. That’s all folks! Please fill out your evaluations!

Related Documents