Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Plug-in Architectures With Layrry and the Java Module System (vJUG)

Plug-in Architectures With Layrry and the Java Module System (vJUG)

-- A joint talk with Andres Almiray at Virtual JUG --

The Java Module System lays the foundation for building modularized applications on the JVM. It doesn’t concern itself though with resolving module versions and obtaining modules from repositories.

This is where Layrry comes in: an API and launcher for modularized Java applications which takes a descriptor of the module layer(s) to assemble, fetches the modules and starts up the application.

Join us for this session and learn how to:

* Build Java applications using layers, e.g. providing isolation between different versions of one module.
* Use jbang to launch your layered apps in no time.
* Create plug-in based rich-client applications using JavaFX and Layrry, allowing to – dynamically reconfigure and update your layer hierarchy, no restarts required.
* Create your own customized Layrry launcher if needed

This session is code-centered, be ready to see the Java Module System, Layrry, and JavaFX in action!

Gunnar Morling

November 24, 2020
Tweet

More Decks by Gunnar Morling

Other Decks in Programming

Transcript

  1. @gunnarmorling | @aalmiray #Layrry
    Plug-in Architectures With Layrry and
    the Java Module System
    Gunnar Morling | Andres Almiray

    View full-size slide

  2. @gunnarmorling | @aalmiray #Layrry
    Gunnar Morling
    ● Open source software engineer at Red Hat
    ○ Debezium
    ○ Hibernate
    ● Spec Lead for Bean Validation 2.0
    ● Java Champion
    ● @gunnarmorling

    View full-size slide

  3. @gunnarmorling | @aalmiray #Layrry
    Andres Almiray
    ● Senior Principal Product Manager @ Oracle
    ○ “Seasoned Sourceror”
    ● ❤ Open Source & Java
    ● Apache Groovy PMC
    ● Java Champion Alumni
    ● @aalmiray

    View full-size slide

  4. @gunnarmorling | @aalmiray #Layrry
    JPMS
    Java Platform Module System (also known as Jigsaw)
    Introduced in Java 9
    Designed to break down the JVM monolith
    Applicable to user space as well
    The promise is to give developers better code encapsulation and design foundations

    View full-size slide

  5. @gunnarmorling | @aalmiray #Layrry
    However...
    © Alexander Henning Drachmann https://flic.kr/p/uUA4G (CC BY-SA 2.0)

    View full-size slide

  6. @gunnarmorling | @aalmiray #Layrry
    Some User Statements
    “JPMS only allows for one version of a module”
    “JPMS doesn’t allow to add modules at runtime”
    “I have to modularize ALL my dependencies in order to benefit from JPMS”
    “It’s so hard to map dependency coordinates to module dependencies”
    “Help, non-exported packages of different modules collide!”

    View full-size slide

  7. @gunnarmorling | @aalmiray #Layrry
    What no one ever said
    “Let’s use JPMS Layers to tackle
    (some of) these issues”

    View full-size slide

  8. @gunnarmorling | @aalmiray #Layrry
    Module Layers
    https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/ModuleLayer.html

    View full-size slide

  9. @gunnarmorling | @aalmiray #Layrry
    Using the Layers API

    View full-size slide

  10. @gunnarmorling | @aalmiray #Layrry
    Hello, Layrry!
    An API and Launcher for Modularized Java Applications

    View full-size slide

  11. @gunnarmorling | @aalmiray #Layrry
    Hello,
    Layrry!

    View full-size slide

  12. @gunnarmorling | @aalmiray #Layrry
    Layrry
    JPMS
    © Christoper Michel https://flic.kr/p/UMtHv5 (CC BY 2.0)

    View full-size slide

  13. @gunnarmorling | @aalmiray #Layrry
    Ready-Made
    Launcher
    layrry-launcher--all.jar \
    —layers-config layers.yml

    View full-size slide

  14. @gunnarmorling | @aalmiray #Layrry
    Parameterization

    View full-size slide

  15. @gunnarmorling | @aalmiray #Layrry
    Built-in
    Template
    Support
    layrry-launcher--all.jar \
    —layers-config javafx.toml \
    —properties versions.properties

    View full-size slide

  16. @gunnarmorling | @aalmiray #Layrry
    jbang layrry@moditect \
    —layers-config javafx.toml \
    —properties versions.properties

    View full-size slide

  17. @gunnarmorling | @aalmiray #Layrry
    Local Repositories
    © Andres Almiray (CC BY 2.0)

    View full-size slide

  18. @gunnarmorling | @aalmiray #Layrry
    Local Repositories
    ● Artifacts can be organized in a local repository that does not require remote
    resolution
    ● Two layouts currently supported

    View full-size slide

  19. @gunnarmorling | @aalmiray #Layrry
    Local Repositories

    View full-size slide

  20. @gunnarmorling | @aalmiray #Layrry
    Local Repositories

    View full-size slide

  21. @gunnarmorling | @aalmiray #Layrry
    Plug-in Architectures
    © Justin Taylor https://flic.kr/p/4fQz9t (CC BY 2.0)

    View full-size slide

  22. @gunnarmorling | @aalmiray #Layrry
    Plug-in Architectures
    Can dynamically add (and remove) layers at runtime

    View full-size slide

  23. @gunnarmorling | @aalmiray #Layrry
    Plug-in Architectures

    View full-size slide

  24. @gunnarmorling | @aalmiray #Layrry
    © Bob Adams https://flic.kr/p/cYV7gq (CC BY-SA 2.0)
    Demo

    View full-size slide

  25. @gunnarmorling | @aalmiray #Layrry
    Bonus: Class Unloading
    ● Classes and layer class loader subject to GC after plug-in removal
    ● Dragons beware, class loader leaks can happen
    ○ Dangling references in remaining layers
    ○ Started threads
    ○ Shutdown hooks

    View full-size slide

  26. @gunnarmorling | @aalmiray #Layrry

    View full-size slide

  27. @gunnarmorling | @aalmiray #Layrry

    View full-size slide

  28. @gunnarmorling | @aalmiray #Layrry

    View full-size slide

  29. @gunnarmorling | @aalmiray #Layrry

    View full-size slide

  30. @gunnarmorling | @aalmiray #Layrry
    Outlook
    ● Remote layer files
    ● Binary distributions: Github Releases, Homebrew, SDKMan, etc.
    ● Integration with jlink
    ● Derive layers from pom.xml?
    ● Programmatic plug-in API
    ● Your contributions?!

    View full-size slide

  31. @gunnarmorling | @aalmiray #Layrry
    Resources
    Source code
    https://github.com/moditect/layrry
    https://github.com/moditect/layrry-examples

    View full-size slide

  32. @gunnarmorling | @aalmiray #Layrry
    Resources
    Blog posts
    https://www.morling.dev/blog/introducing-layrry-runner-and-api-for-
    modularized-java-applications/
    https://www.morling.dev/blog/plugin-architectures-with-layrry-and-
    the-java-module-system/
    https://www.morling.dev/blog/class-unloading-in-layered-java-applications/

    View full-size slide

  33. @gunnarmorling | @aalmiray #Layrry
    Q & A

    View full-size slide

  34. @gunnarmorling | @aalmiray #Layrry
    Demo

    View full-size slide

  35. @gunnarmorling | @aalmiray #Layrry
    JavaFX Demo

    View full-size slide