Building a Java Module

The Java API gives you more control than any other method of creating a module. To be able to use your module, PipeT needs it to be in a JAR file with only two requirements:

Creating a module class

As said, a basic requirement of the module class is that it implements net.sf.pipet.api.ModuleInterface. However, there are several abstract classes which may do most of the work for your.

  1. net.sf.pipet.api.InputOutputModule is probably the best choice if your module has just one input and one output stream. (Requires pipet-module-api-1.2.15.jar).
  2. net.sf.pipet.api.ConfigurableModuleInterface has advanced configuration options. (Requires pipet-api-1.2.15.jar).
  3. net.sf.pipet.api.DefaultModuleInterface gives you full control. (Requires pipet-module-api-1.2.15.jar).

InputOutputModule

The following code shows a module which ignores the input stream and writes a message to the output stream.

package net.sf.pipet.examples;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

import net.sf.pipet.api.InputOutputModule;
import net.sf.pipet.api.ModuleAttributes;
import net.sf.qxs.messenger.Messenger;

/**
 * A simple implementation of a module, which writes a predefined string to a predefined pipe.
 */
public class SimpleModule 
	extends InputOutputModule
{
	/**
	 * The module's title. Keep it short and descriptive.
	 */
	private static final String TITLE = "Simple Module";

	/**
	 * A free-text string which describes the module.
	 */
	private static final String DESCRIPTION = "A simple module which generates a static string.";

	/**
	 * The module's output: a static string in our case.
	 */
	private static final String MESSAGE = "Hello world!";

	/**
	 * The module's output type. Best practice is to always use mime types.
	 */
	private static final String OUTPUT_TYPE = "text/plain";
	
	public SimpleModule()
	{
		super(TITLE, DESCRIPTION, null, OUTPUT_TYPE);
	}

	public boolean run(InputStream is, OutputStream os, ModuleAttributes atts, Messenger messenger)
	{
		PrintStream out = new PrintStream(os);
		out.print(MESSAGE);
		out.close();
		return true;
	}
}

Modules extending InputOutputModule should use and package pipet-module-api-1.2.15.jar.

Manifest

The manifest file must contain a Module-Interface entry which points to the module class. If you use Maven, see Building a Maven module for instructions. The manifest file is located in the JAR in META-INF/MANIFEST.MF and should look like this:

Manifest-Version: 1.0
Module-Interface: org.example.HelloWorld
Build-Jdk: 1.6.0_20
Created-By: Apache Maven
Archiver-Version: Plexus Archiver

Testing

For unit-testing the module, see the PipeT Test Suite manual.