Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java @ 1127:6b9877a9f6c1
Added infrastructure to start WSPLGEN calculations - the FloodMapState already start such calculations.
flys-artifacts/trunk@2639 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 02 Sep 2011 13:12:05 +0000 |
parents | |
children | 727c53fd0dc7 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java Fri Sep 02 13:12:05 2011 +0000 @@ -0,0 +1,96 @@ +package de.intevation.flys.wsplgen; + +import java.io.InputStream; +import java.io.IOException; +import java.io.File; + +import org.apache.log4j.Logger; + +import de.intevation.flys.artifacts.model.WSPLGENJob; + + +public class JobExecutor { + + public static final String WSPLGEN_PARAMETER_FILE = + "wsplgen.par"; + + public static final String WSPLGEN_BIN_PATH = + System.getProperty("wsplgen.bin.path"); + + + private Logger logger = Logger.getLogger(JobExecutor.class); + + private Process process; + + protected WSPLGENJob job; + + protected JobObserver observer; + + + public JobExecutor(WSPLGENJob job) { + this.job = job; + this.observer = new JobObserver(job); + } + + + public void execute() { + File dir = job.getWorkingDir(); + File parameter = new File(dir, WSPLGEN_PARAMETER_FILE); + + String[] args = new String[] { + WSPLGEN_BIN_PATH, + "-PAR=\"" + parameter.getAbsolutePath() + "\"" + }; + + execute(args, dir, observer); + } + + + public void execute(String[] args, File dir, JobObserver observer) { + logger.info("Start JobExecutor for artifact: " + dir.getName()); + + String errorMsg = null; + + try { + synchronized (this) { + process = Runtime.getRuntime().exec(args, null, dir); + + InputStream out = process.getInputStream(); + observer.setInputStream(out); + + observer.start(); + + try { + process.waitFor(); + } + catch (InterruptedException ie) { + logger.error("WSPLGEN job interrupted: " + ie.getMessage()); + } + + try { + observer.join(); + } + catch (InterruptedException iee) { /* do nothing */ } + + logger.info("WSPLGEN exit value: " + process.exitValue()); + + return; + } + } + catch (SecurityException se) { + errorMsg = se.getMessage(); + } + catch (IOException ioe) { + errorMsg = ioe.getMessage(); + } + catch (NullPointerException npe) { + errorMsg = npe.getMessage(); + } + catch (IndexOutOfBoundsException ioobe) { + errorMsg = ioobe.getMessage(); + } + + logger.error("An error occured while starting WSPLGEN: " + errorMsg); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :