Creating a custom Module
You can customize and extend the Content Deployer by writing 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 whenever a Transport Package is being processed. 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, it can be configured in the Content Deployer configuration file, cd_deployer_conf.xml (refer to the Content Deployer sample configuration file for details), with the following elements:
<Processor Action="Deploy" Class="com.tridion.deployer.Processor">
<Module Type="PageDeploy" Class="com.tridion.deployer.modules.PageDeploy"/>
<Module Type="BinaryDeploy" Class="com.tridion.deployer.modules.BinaryDeploy"/>
<Module Type="ComponentDeploy" Class="com.tridion.deployer.modules.ComponentDeploy"/>
<Module Type="TemplateDeploy" Class="com.tridion.deployer.modules.TemplateDeploy"/>
<Module Type="SchemaDeploy" Class="com.tridion.deployer.modules.SchemaDeploy"/>
<Module Type="ComponentPresentationDeploy" Class="com.tridion.deployer.modules.ComponentPresentationDeploy"/>
<Module Type="CacheFlusher" Class="com.tridion.examples.CacheFlusher">
<AppInstance>default</AppInstance>
</Module>
</Processor>
The custom Module is configured as the last module for the Processor that handles a deployment action. As a result, it is called after all other Modules 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.