diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2016-01-14 15:49:58 +0200 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2016-01-14 15:49:58 +0200 |
commit | abc4bfa220216f986f2f336bd17672e4dea6bc21 (patch) | |
tree | 810dd16371359ec67e1e6b15de80872048737d5b /README.md | |
parent | 494d0fed21a0b939ee61058fdee621f794aea2b8 (diff) | |
download | pf4j-abc4bfa220216f986f2f336bd17672e4dea6bc21.tar.gz pf4j-abc4bfa220216f986f2f336bd17672e4dea6bc21.zip |
Add 'ServiceLoader interoperability' section in readme
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -343,6 +343,39 @@ public static void main(String[] args) { } ``` +ServiceLoader interoperability +------------------- +Starting with version 0.12 PF4J comes with a better support for `ServiceLoader`. +PF4J can read `META-INF/services` (Java Service Provider mechanism) as extensions, so, +if you have a modular application based on `java.util.ServiceLoader` class you can replace entirely the `ServiceLoader.load()` +calls from your application with `PluginManager.getExtensions()` and migrate smooth from ServiceLoader to PF4J. + +Also you have the possibility to change the `ExtensionStorage` used in `ExtensionAnnotationProcessor`. +By default we use the format with `META-INF/extensions.idx` +``` +ro.fortsoft.pf4j.demo.HowdyGreeting +ro.fortsoft.pf4j.demo.WhazzupGreeting +``` + +but you can use a more standard location and format, `META-INF/services/<extension-point>`, used by Java Service Provider +(see `java.util.ServiceLoader`) via `ServiceProviderExtensionStorage` implementation. +In this case the format of `META-INF/services/ro.fortsoft.pf4j.demo.api.Greeting` is +``` +# Generated by PF4J +ro.fortsoft.pf4j.demo.HowdyGreeting +ro.fortsoft.pf4j.demo.WhazzupGreeting # pf4j extension +``` + +where the `ro.fortsoft.pf4j.demo.HowdyGreeting` entry is legacy (it's not generated by PF4J) but it's seen as +an extension of `Greeting` by PF4J (at runtime). + +You can plug your custom `ExtensionStorage` implementation in `ExtensionAnnotationProcessor` in two possible modes: +- set the annotation procesor option with key `pf4j.storageClassName` +- set the system property with key `pf4j.storageClassName` + +For example if I want to use `ServiceProviderExtensionStorage` then the value for the `pf4j.storageClassName` key must be +`ro.fortsoft.pf4j.processor.ServiceProviderExtensionStorage` + Demo ------------------- I have a tiny demo application. The demo application is in demo folder. |