-
Notifications
You must be signed in to change notification settings - Fork 20
Create a Plugin
The easiest way to get started is to checkout and modify the example plugin.
Plugin classes are instantiated only once for the whole application.
A new extension will be instantiated for each extension point.
If a plugin needs to receive lifecycle-hooks it must implement a class extending Plugin
.
This plugin class could implement extension points directly, but there will be two different objects created,
one for the plugin and another one for the extension.
<dependencies>
<dependency>
<groupId>com.exxeta</groupId>
<artifactId>correomqtt</artifactId>
<version>0.12.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
To access the plugin object for an extension use this constructor
@Extension
public class ExampleExtension implements ExampleHook {
public ExampleExtension(Plugin plugin) {
this.plugin = (ExamplePlugin) plugin;
}
...
}
If a plugin or extension needs more permissions it must provide a class extending PermissionPlugin
which is a subclass of Plugin
.
To add new permissions override the Permissions getPermissions() {}
method.
To provide a simple extension leave the <plugin.class />
tag empty and create a new class
which implements your desired hook from the package com.exxeta.correomqtt.plugin.spi
.
Annotate the class with the @Extension
annotation from PF4J
and that's it.
That's possible. Just add the @ExtensionId("my-id")
annotation to each class.
Users then need to declare the plugin inside the plugins/protocol.xml
like this:
<plugin name="example-id" extensionId="my-id" />
Users can configure each extension in the plugins/protocol.xml
.
<plugin name="example-id">
<config>
<example color="green" />
</config>
</plugin>
Your extension receives this configuration each time it is instantiated. Just implement this method:
void onConfigReceived(Element config) {}
Each extension can make up it's own configuration structure.
CorreoMQTT is using PF4J to provide it's plugin architecture.
Learn more about PF4J on it's official homepage.
QUICK NAV
For users
For developers