CTP Plugins

From MircWiki
Revision as of 13:23, 21 November 2013 by Johnperry (Talk | contribs)

Jump to: navigation, search


CTP has three basic components:



1 Building and Deploying a Plugin



2 The Plugin Interface




3 The Plugin Lifecycle




Plugin thePlugin = Configuration.getInstance().getRegisteredPlugin(thePluginID);

When CTP shuts down, it calls the <tt>shutdown</tt> method of every component. CTP shuts down all the pipeline stages first and only then shuts down the plugins. Thus, a pipeline stage that references a plugin can use the plugin if necessary while its <tt>shutdown</tt> method is running.

The <tt>org.rsna.ctp.plugin.Plugin</tt> interface provides an <tt>isDown</tt> method to allow CTP to know when the plugin is down. Plugins that take some time to shut down typically return from the <tt>shutdown</tt> method as soon as they have initiated the shutdown, but they don't return <tt>true</tt> from the <tt>isDown</tt> method until the the shutdown is complete. The <tt>org.rsna.ctp.plugin.AbstractPlugin</tt> class handles this handshaking, and plugins that extend the class only have to override the <tt>shutdown</tt> method if they have special things to do (commit a database, close files, etc.).

4 Examples

4.1 The Redirector Plugin


*  Copyright 2013 by the Radiological Society of North America
*  This source software is released under the terms of the

package org.rsna.ctp.stdplugins;

import org.apache.log4j.Logger;
import org.rsna.ctp.plugin.AbstractPlugin;
import org.rsna.server.HttpRequest;
import org.rsna.server.HttpResponse;
import org.rsna.service.HttpService;
import org.rsna.service.Service;
import org.rsna.util.StringUtil;
import org.w3c.dom.Element;

public class Redirector extends AbstractPlugin {

	static final Logger logger = Logger.getLogger(Redirector.class);

	int httpPort;
	String httpsHost;
	int httpsPort;
	HttpService monitor = null;
	Service handler = null;

	 * Construct a plugin implementing a Redirector.
	 * @param element the XML element from the configuration file
	 * specifying the configuration of the plugin.
	public Redirector(Element element) {
		try {
			handler = new RedirectionHandler();
			monitor = new HttpService(false, httpPort, handler);
			logger.info("Redirector Plugin instantiated");
		catch (Exception ex) {

	 * Start the plugin.
	public void start() {
		if (monitor != null) {

	 * Stop the plugin.
	public void shutdown() {
		stop = true;
		if (monitor != null) {
			logger.info("Redirector Plugin stopped");

	class RedirectionHandler implements Service {

		public RedirectionHandler() { }

		public void process(HttpRequest req, HttpResponse res) {
			String host = httpsHost;
			if (host.equals("")) {
				int k = host.indexOf(":");
			host += ":" + httpsPort;
			String query = req.getQueryString();