From VuzeWiki
Jump to: navigation, search


Inter Plugin Communications (IPC for short), is a way for plugins to directly interact with one another.

The communication is done by calling methods of the target Plugin through the IPCInterface.

For documentation of the interface see: IPC Java Doc


Now a step by step Tutorial how to get this working. For this example, lets assume we want to send a mail via the Status Mailer Plugin.

Getting Ready[edit]

We need to get the PluginInterface from the Status Mailer Plugin (SMP from now on). We do so by using the PluginManager method getPluginInterfaceByID(). The pluginID of SMP is "azstatusmailer" so we call PluginManager.getPluginInterfaceByID("azstatusmailer"). It will return the PluginInterface or it will be null if the plugin is not loaded.

Opening Communications Channel[edit]

Now that we have the PluginInterface, you may want to check the Version of SMP to see if the method you want to call is available. To communicate with the Plugin we now have to get the IPCInterface for the plugin. Simply call PluginInterface.getIPC();

Communicate with another Plugin[edit]

Now the fun part begins, you need to know the signature of the method you want to call. Note: only call public methods. So we go into the source of SMP and look for the send method. For us the Signature is:

 public void sendMessage(
 		String		server,
 		int		port,
 		boolean		ssl,
 		String		user_name,
 		String		password,
 		boolean		html_message,
 		String		subject,
 		String		to,
 		String		from,
 		String[]	lines )

The method signature of the invoke method is: invoke(String methodName, Object[] params)

So our call will look like this:

 IPCInterface.invoke("sendMessage", new Object[] {
 	"Test Message send via IPC",
 	"To Recipent",
 	new String[]{"FirstLine","SecondLine"}} );


You may have noticed that I was using Integer.valueOf(portNumber), this is because Java 1.4 doesn't support autoboxing you have to use the Objects for the primitive types yourself. eg. Integer for int, Long for long and so on. In Java 1.5 the JVM takes care of that.

If you have done anything wrong or the method is not found, you'll get an IPCException.

Invoke will return an Object as result. In this case it would be null since we are calling a void method.

Advanced Stuff[edit]

You can use all native Java Objects as parameters or return.

If you want to share custom Objects you need to put the Interfaces for those Objects in a jar and put it in the Azureus shared library dir.


Example Class

--Damokles 18:31, 25 August 2006 (GMT)

Code Convention[edit]

Methods that should be used via IPC should be prefixed with ipc eg. ipcSendMessage.