PluginDevGuide PluginInterface

From VuzeWiki
Jump to: navigation, search

Plugin Development Guide: How plugins work with Azureus[edit]

So, now that we've explained how to begin writing a plugin, now to explain how plugins actually integrate with Azureus.

The PluginInterface[edit]

Plugins only need to implement one particular method.

public void initialize(PluginInterface plugin_interface) {
    // Do something here.

This method is where the magic happens. :) Your plugin is passed a PluginInterface object - this object provides links to all functionality provided to plugins.

  • You want to get access to a list of downloads?
    • plugin_interface.getDownloadManager().getDownloads()
  • You want to create a menu item?
    • plugin_interface.getUIManager().getMenuManager().addMenuItem("menuname", "menuitemname")

Some of the functionality is provided directly on the PluginInterface object - most of it is split off into separate manager objects which provide access to particular pieces of functionality (like downloads, user interface, connection handling, save location logic, peer communication)...

So - everything that your plugin wants to do, will be done using functionality derived from the PluginInterface object. All the functionality provided in the plugin API is listed here.

Method types[edit]

Roughly speaking, there are three types of code that plugins will have:

  • Code executed on plugin initialisation.
  • Code executed by listener methods.
  • Code running in a separate thread.

Let's explain this in a bit more detail. Let's say that you want your plugin to provide a menu item to do some particular behaviour for a torrent.

This would be done by the plugin creating a menu item at initialisation time, and adding a menu listener to react when the menu item is activated. That largely explains the majority of plugins - plugins do a lot of registering at initialisation time, and then do the more interesting code when Azureus calls the listener code.

Some plugins may need to run part of its code in its own thread - but most of the code works in this manner.