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 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 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 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 Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  14. @gunnarmorling | @aalmiray #Layrry
    Parameterization

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

  19. @gunnarmorling | @aalmiray #Layrry
    Local Repositories

    View Slide

  20. @gunnarmorling | @aalmiray #Layrry
    Local Repositories

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

  26. @gunnarmorling | @aalmiray #Layrry

    View Slide

  27. @gunnarmorling | @aalmiray #Layrry

    View Slide

  28. @gunnarmorling | @aalmiray #Layrry

    View Slide

  29. @gunnarmorling | @aalmiray #Layrry

    View 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 Slide

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

    View 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 Slide

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

    View Slide

  34. @gunnarmorling | @aalmiray #Layrry
    Demo

    View Slide

  35. @gunnarmorling | @aalmiray #Layrry
    JavaFX Demo

    View Slide