comparison 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
comparison
equal deleted inserted replaced
1126:da4d8631fc46 1127:6b9877a9f6c1
1 package de.intevation.flys.wsplgen;
2
3 import java.io.InputStream;
4 import java.io.IOException;
5 import java.io.File;
6
7 import org.apache.log4j.Logger;
8
9 import de.intevation.flys.artifacts.model.WSPLGENJob;
10
11
12 public class JobExecutor {
13
14 public static final String WSPLGEN_PARAMETER_FILE =
15 "wsplgen.par";
16
17 public static final String WSPLGEN_BIN_PATH =
18 System.getProperty("wsplgen.bin.path");
19
20
21 private Logger logger = Logger.getLogger(JobExecutor.class);
22
23 private Process process;
24
25 protected WSPLGENJob job;
26
27 protected JobObserver observer;
28
29
30 public JobExecutor(WSPLGENJob job) {
31 this.job = job;
32 this.observer = new JobObserver(job);
33 }
34
35
36 public void execute() {
37 File dir = job.getWorkingDir();
38 File parameter = new File(dir, WSPLGEN_PARAMETER_FILE);
39
40 String[] args = new String[] {
41 WSPLGEN_BIN_PATH,
42 "-PAR=\"" + parameter.getAbsolutePath() + "\""
43 };
44
45 execute(args, dir, observer);
46 }
47
48
49 public void execute(String[] args, File dir, JobObserver observer) {
50 logger.info("Start JobExecutor for artifact: " + dir.getName());
51
52 String errorMsg = null;
53
54 try {
55 synchronized (this) {
56 process = Runtime.getRuntime().exec(args, null, dir);
57
58 InputStream out = process.getInputStream();
59 observer.setInputStream(out);
60
61 observer.start();
62
63 try {
64 process.waitFor();
65 }
66 catch (InterruptedException ie) {
67 logger.error("WSPLGEN job interrupted: " + ie.getMessage());
68 }
69
70 try {
71 observer.join();
72 }
73 catch (InterruptedException iee) { /* do nothing */ }
74
75 logger.info("WSPLGEN exit value: " + process.exitValue());
76
77 return;
78 }
79 }
80 catch (SecurityException se) {
81 errorMsg = se.getMessage();
82 }
83 catch (IOException ioe) {
84 errorMsg = ioe.getMessage();
85 }
86 catch (NullPointerException npe) {
87 errorMsg = npe.getMessage();
88 }
89 catch (IndexOutOfBoundsException ioobe) {
90 errorMsg = ioobe.getMessage();
91 }
92
93 logger.error("An error occured while starting WSPLGEN: " + errorMsg);
94 }
95 }
96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org