Creating a custom Module

You can customize and extend the Content Deployer worker by developing custom Content Deployer Modules in Java. A Module can also extend the default Modules to implement functionality that act on the Transport Package data structures.

A custom Module is a Java class that is loaded and called by the Content Deployer worker. The following example demonstrates how to flush the application server cache when new content is deployed:

package com.tridion.examples;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tridion.transport.transportpackage.*;
import com.tridion.configuration.*;
import com.tridion.deployer.ProcessingException;
import com.tridion.deployer.Processor;
import com.tridion.deployer.Module;
import com.perfectsoftware.AppServer.*;

public class CacheFlusher extends Module {
	private static Logger log = LoggerFactory.getLogger(CacheFlusher.class);

	//imaginary appserver API
	AppManager server = CachingAppServer.getManagerInstance();

	public CacheFlusher(Configuration config, Processor processor) 
		throws ConfigurationException {
		super(config, processor);
	}

	// This method is called once for each TransportPackage that is deployed.
	public void process(TransportPackage data) throws ProcessingException {
		try {
			server.flush(config.getAttribute("AppInstance"));
		} catch (ConfigurationException e) {
			log.error("Could not get custom configuration", e);
		}
	}
}
Once this class is compiled and available to the Content Deployer worker, it can be configured in the Content Deployer worker configuration file, deployer-conf.xml (refer to the Content Deployer sample configuration file for details), with the following elements:
<Step Factory="com.sdl.delivery.deployer.steps.TridionExecutableStepFactory" Id="CacheFlusherStep">
	<Module Type="CacheFlusher" Class="com.tridion.examples.CacheFlusher">
		<AppInstance>default</AppInstance>
	</Module>
</Step>

The custom Module is configured as the module in the last Step in the Pipeline that handles a deployment or undeployment action. As a result, it is called after all other Steps have finished processing. It is possible to use custom configuration for a Module by adding XML elements to the Module configuration. This configuration information is passed to the custom Module constructor.