-
Notifications
You must be signed in to change notification settings - Fork 2
Plugin API
Work in progress please help to update.
For a tutorial on creating a full fledged plugin with web-interface, see the Plugin Development Tutorial.
We'll start by examining the HelloWorld plugin. The source of this plugin can be found lower on this page.
A plugin is created by implementing various FredPlugin*
interfaces. The most important ones are listed here. But more can be found in freenet.pluginmanager
.
- freenet.pluginmanager.FredPlugin
- freenet.pluginmanager.FredPluginHTTP
- freenet.pluginmanager.FredPluginThreadless
- freenet.pluginmanager.FredPluginL10n
- freenet.pluginmanager.FredPluginVersioned
- freenet.pluginmanager.FredPluginRealVersioned
For the HelloWorld plugin, only FredPlugin is implemented. The FredPlugin interface takes care that runPlugin()
is be called when the plugin gets loaded and terminate()
will be called when it is removed or when the node shuts down.
The first thing you want to do when your runPlugin() gets called is saving your PluginRespirator. The PluginRespirator is your starting point in communicating with the node.
Then we'll print the Heartbeat
to System.err
and wait 1 second as long as the boolean goon
is true
. This message ends up in wrapper.log
in the directory of your node. On linux you can watch the messages with tail -F /directory/of/node/wrapper.log
.
When the node shuts down or your plugin gets unloaded terminate is called()
. As we don't want to do any stuff after being asked to terminate we kill the loop by making goon false.
This is all that's needed to create a basic plugin. The whole source:
package plugins.HelloWorld;
import freenet.pluginmanager.*;
import java.util.Date;
public class HelloWorld implements FredPlugin {
private volatile boolean goon = true;
PluginRespirator pr;
public void terminate() {
goon = false;
}
public void runPlugin(PluginRespirator pr) {
this.pr = pr;
while(goon) {
System.err.println("Heartbeat from HelloWorld-plugin: " + (new Date()));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Who cares ?
}
}
}
}
You must
- Create an instance of HighLevelSimpleClient from PluginRespirator:
HighLevelSimpleClient hlsc = pr.getHLSimpleClient();
- Create an instance of FetchResult
- use
hlsc.fetch(new FreenetURI("CHK@..."))
to return you yourFetchResult
Watch for the FetchException from that function, it can mean that the redirect was encountered, simple test if (e.newURI != null)
will tell you if the Exception is an actual error.
(coming soon)
See also