/*
* Copyright (C) 2009 by TunedIT Solutions. All rights reserved
*
*/
package org.tunedit.core;
import java.io.OutputStream;
import java.util.List;
import org.tunedit.core.exception.TunedTesterException;
/**
* Wrapper class for external process started by the ResourceLoader.
*
* The process receives all input data (training and test) from its standard input stream.
* The result should be printed out to standard output stream.
*
* Important: the process must read all input until EOF.
* Otherwise a deadlock may occur and then evaluation timeout.
*
* The process may write to the output stream at any time, either in parallel with reading input or afterwards.
*
* Typical usage:
* <pre>
* p = resourceLoader.runProcess(...);
* dataStream = p.getDataStream();
* // write all input data to 'dataStream'
* p.waitFor();
* // in loop:
* line = p.readResultLine();
* // compare 'line' with target, calculate error ...
* p.cleanUp(); // clean all resources, incl. result buffer
* </pre>
*
* @author Joanna Swietlicka
*
*/
public abstract class ExternalProcess {
/**
* Waits until the process has terminated
* @return The exit value of the process
* @throws InterruptedException
*/
public abstract int waitFor() throws InterruptedException;
/**
* Cleans all used resources and destroys the process
* @throws TunedTesterException
*/
public abstract void cleanUp();
/**
* Kills the subprocess
* @throws TunedTesterException
*/
public abstract void destroy() throws TunedTesterException;
/**
* @return The exit value of the process
*/
public abstract int exitValue();
/**
* @return The output stream connected to the normal input of the subprocess.
* Used to feed input data to the process.
*/
public abstract OutputStream getDataStream();
/**
* Reads the algorithm's output.
*
* Must be called after writing all the input data
* - otherwise a deadlock will occur.
*/
public abstract List<String> getResult();
}