Creating services using WSProxy

WSProxy allows creationg of data filters and wrapping of data processing codes in order to provide 2 features. Details are given below:

WSProxy

WSProxy architecture is shown in the figure below

Architecture

Creating a filter requires extending either the cgl.hpsearch.wsproxy.RunnableProxyWebService or the cgl.hpsearch.wsproxy.WrapperProxyWebService class. The description of each of these classes and differences is given here .

Example

We show below an example of how a simple data filtering service may be created. Details on writing a script to incoporate such a filter is listed here.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.apache.log4j.Logger;

import cgl.hpsearch.wsproxy.WrapperProxyWebService;

/**
 * @author Harshawardhan Gadgil (hgadgil@grids.ucs.indiana.edu)
 */

public class PIFilterRunner extends WrapperProxyWebService {

	static Logger log = Logger.getLogger("PIFilterRunner");

	private BufferedReader br;
	private BufferedWriter bw;
	private String MinimumMagnitude;

	public void process() throws Exception {

		double MAGNITUDE_THRESHOLD = Double.parseDouble(MinimumMagnitude);
		
		// Step 1: Accumulate data
		String line;

		while (true) {
			try {
				line = br.readLine();
			}
			catch (IOException e) {
				line = null;
			}

			if (line == null) {// EOF reached...
				break;
			}
			else {
				System.out.println("READ:] " + line);
				// We do not write this line to output
				if (line.startsWith("#")) continue;
				if (line.startsWith("SOF")) continue;
				if (line.startsWith("EOF")) {
					// EOF reached... bail out...
					break;
				}

				// A sample line would look like this
				// "1932" "12" "20" "-115.990" "34.545" "3.01"
				line = line.replaceAll("\"\t\"", " ");
				line = line.substring(1, line.indexOf('"', 2));

				// Find the last token in the string. This is the magnitude !!
				String magnitude = line.substring(line.lastIndexOf(" "));
				double dbl = Double.parseDouble(magnitude);

				if (dbl >= MAGNITUDE_THRESHOLD) {
					try {
						bw.write(line + "\n");
						bw.flush();
					}
					catch (IOException e1) {
						log.error("", e1);
						return;
					}
				}
				bw.write(line + "\n");
				bw.flush();
			}

		}

		// MUST close the catalog file writer since we opened the file
		bw.close();

		// My jobz over...
		serviceFinished();
	}

	public void initService(InputStream[] arg0, OutputStream[] arg1) {

		MinimumMagnitude = getProperty("MinimumMagnitude");
		
		// Wrap streams for easy access
		br = new BufferedReader(new InputStreamReader(arg0[0]));
		bw = new BufferedWriter(new OutputStreamWriter(arg1[0]);
	}

	public String[] serviceExceptions() {
		return new String[0];
	}
}
	

NOTES


Last Updated: Feb 20, 2006

(back to Notes)