
"PF4J expects that your plugin code has a class that extends org.pf4j.Plugin interface. And for running and stopping the plugin, methods start() and stop() of this interface will be called. But our service is expected to have completely pure logic - without any side effects - we need to bring these two worlds together - Java impure plugins start/stop and Scala pure logic."
"Therefore, start/stop interop could act like this:In start(), we need to do the following: initialize service resources, execute service business logic, and send all this to the background job. To execute all this in the dirty-dirty Java world and pass our Fiber instance, we execute our program with unsafeRunSync(). On the Java side, it should return Fiber, which we will put into an AtomicReference to use for stopping.Later, in stop(), we will use this Fiber to cancel processing."
PF4J plugins require start() and stop() lifecycle methods while Cats Effect provides pure, side-effect-free Scala abstractions. Start should acquire necessary resources, run business logic via resource.use, shift execution to the background with .start, and call unsafeRunSync to obtain a Fiber instance. Store the returned Fiber in an AtomicReference (often wrapped in an Option) so stop() can access and cancel it to prevent resource leaks. Include error and exit logging around the program to surface failures. This approach bridges impure Java plugin lifecycle hooks with pure Scala concurrency and resource management.
Read at Medium
Unable to calculate read time
Collection
[
|
...
]