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

How to create your own Quarkus extension

How to create your own Quarkus extension

Quarkus Insights: Holly Cummins discusses the basics, tips and tricks of creating your own Quarkus extensions.

https://www.youtube.com/watch?v=90FEj1zqjWQ

Holly Cummins

August 11, 2024
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. @holly_cummins Java dynamism </> build time runtime load and parse

    • config files • properties • yaml • xml • etc.
  2. @holly_cummins Java dynamism @ @ </> build time runtime •

    classpath scanning and annotation discovery • attempt to load class to enable/disable features
  3. @holly_cummins what if we start the application more than once?

    @ @ </> @ @ </> @ @ </> @ @ </> so much work gets redone every time
  4. @holly_cummins @ @ </> build time runtime start • thread

    pools • I/O • etc. what if we initialize at build time?
  5. @holly_cummins @ @ </> build time runtime ready to do

    work! start • thread pools • I/O • etc. what if we initialize at build time?
  6. @holly_cummins doing more up-front - speeds up start - shrinks

    memory footprint - improves throughput (!)
  7. why write a new extension? • the community hasn’t written

    one yet • it’s your library • support a use case particular to your environment
  8. build items are communication mechanism between build steps framework automatically

    determines correct execution order and injects parameters
  9. what kind of things can build items do? Create a

    servlet Create a route Pull an external bean into the closed world Turn one annotation into another Add a log handler Read an extra application archive Flag a capability as present Interact with Kubernetes Communicate between extensions! …
  10. existing build items cover almost all needs like a library

    for extension writers but you can write your own too
  11. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template maturity model for quarkus extensions
  12. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template maturity model for quarkus extensions
  13. extension concept GraalVM • Contribute GraalVM configuration ◦ Reflection registration

    ◦ Dynamic proxy registration ◦ Resource files ◦ Message bundles ◦ Etc. • Provide substitutions ◦ Pieces of code that are used in place of regular library code when in native mode
  14. Substitutions @TargetClass(org.infinispan.client.hotrod.impl.RemoteCacheImpl.class) public final class SubstituteRemoteCacheImpl { @Delete private ObjectName

    mbeanObjectName; @Substitute private void registerMBean(ObjectName jmxParent) { } @Substitute private void unregisterMBean() { } @Delete public void init(OperationsFactory operationsFactory, Configuration configuration, ObjectName jmxParent) { } }
  15. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template maturity model for quarkus extensions
  16. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template examples: configuration
  17. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template examples: dev service
  18. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template examples: dev ui
  19. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template examples: joyful programming model
  20. open world closed world hard to build-time optimise easy to

    build-time optimise runtime class surprise!
  21. open world closed world hard to build-time optimise easy to

    build-time optimise runtime class surprise!
  22. open world closed world hard to build-time optimise easy to

    build-time optimise no worries runtime class surprise!
  23. open world closed world hard to build-time optimise easy to

    build-time optimise no worries runtime class surprise!
  24. open world closed world hard to build-time optimise easy to

    build-time optimise uh oh, this is outside our closed world no worries runtime class surprise!
  25. extension concept gizmo when you don’t want to ASM… …

    but bytecode recording isn’t enough
  26. <persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/ persistence https://jakarta.ee/xml/ns/persistence/ persistence_3_0.xsd"> <!--

    Define persistence unit --> <persistence-unit name="my-persistence-unit"> </persistence-unit> </persistence> persistence.xml hibernate extension the hibernate extension makes this go away
  27. works in dev mode works in JVM works in native

    mode con fi guration provides a dev service supersonic performance joyful programming model dev UI codestart template examples: supersonic subatomic performance
  28. @holly_cummins JVM spends time loading classes for specific databases JVM

    class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database footprint example: Hibernate
  29. @holly_cummins JVM spends time loading classes for specific databases JVM

    class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database class for unused database turns out they’re never used footprint example: Hibernate
  30. @holly_cummins JVM spends time loading classes for specific databases JVM

    turns out they’re never used JIT spends time unloading classes footprint example: Hibernate
  31. @holly_cummins Hibernate example: ~500 classes which are only useful if

    you're running an Oracle database loaded and then unloaded
  32. @holly_cummins Hibernate example: ~500 classes which are only useful if

    you're running an Oracle database loaded and then unloaded every single start.
  33. @holly_cummins unused implementation the one we want interface unused implementation

    unused implementation the true cost of loaded classes isn’t just memory + start time method dispatching:
  34. @holly_cummins unused implementation the one we want interface unused implementation

    unused implementation the true cost of loaded classes isn’t just memory + start time method dispatching:
  35. @holly_cummins unused implementation the one we want interface megamorphic call

    slow dispatching unused implementation unused implementation the true cost of loaded classes isn’t just memory + start time method dispatching:
  36. @holly_cummins the true cost of loaded classes isn’t just memory

    + start time the one we want monomorphic call fast dispatching interface