Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java @ 1190:f514894ec2fd
merged flys-artifacts/2.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:17 +0200 |
parents | e7d5452a7381 |
children | aaf8d32f85bd |
comparison
equal
deleted
inserted
replaced
917:b48c36076e17 | 1190:f514894ec2fd |
---|---|
1 package de.intevation.flys.wsplgen; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.File; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import de.intevation.artifacts.CallContext; | |
9 | |
10 import de.intevation.flys.artifacts.model.WSPLGENJob; | |
11 | |
12 import de.intevation.flys.utils.MapfileGenerator; | |
13 | |
14 | |
15 public class JobExecutor { | |
16 | |
17 public static final String WSPLGEN_PARAMETER_FILE = | |
18 "wsplgen.par"; | |
19 | |
20 public static final String WSPLGEN_BIN_PATH = | |
21 System.getProperty("wsplgen.bin.path"); | |
22 | |
23 | |
24 private Logger logger = Logger.getLogger(JobExecutor.class); | |
25 | |
26 private Process process; | |
27 | |
28 protected WSPLGENJob job; | |
29 | |
30 protected JobObserver logObserver; | |
31 protected ProblemObserver errorObserver; | |
32 | |
33 | |
34 public JobExecutor(WSPLGENJob job) { | |
35 this.job = job; | |
36 this.logObserver = new JobObserver(job); | |
37 this.errorObserver = new ProblemObserver(job); | |
38 } | |
39 | |
40 | |
41 public void execute() { | |
42 File dir = job.getWorkingDir(); | |
43 File parameter = new File(dir, WSPLGEN_PARAMETER_FILE); | |
44 | |
45 String[] args = new String[] { | |
46 WSPLGEN_BIN_PATH, | |
47 "-PAR=\"" + parameter.getAbsolutePath() + "\"" | |
48 }; | |
49 | |
50 execute(args, dir); | |
51 } | |
52 | |
53 | |
54 protected void execute(String[] args, File dir) { | |
55 logger.info("Start JobExecutor for artifact: " + dir.getName()); | |
56 | |
57 String errorMsg = null; | |
58 | |
59 try { | |
60 synchronized (this) { | |
61 process = Runtime.getRuntime().exec(args, null, dir); | |
62 | |
63 logObserver.setInputStream(process.getInputStream()); | |
64 errorObserver.setInputStream(process.getErrorStream()); | |
65 | |
66 logObserver.start(); | |
67 errorObserver.start(); | |
68 | |
69 try { | |
70 process.waitFor(); | |
71 } | |
72 catch (InterruptedException ie) { | |
73 logger.error("WSPLGEN job interrupted: " + ie.getMessage()); | |
74 } | |
75 | |
76 try { | |
77 logObserver.join(); | |
78 errorObserver.join(); | |
79 } | |
80 catch (InterruptedException iee) { /* do nothing */ } | |
81 | |
82 job.getCallContext().afterBackground(CallContext.STORE); | |
83 | |
84 logger.info("WSPLGEN exit value: " + process.exitValue()); | |
85 logger.info( | |
86 "WSPLGEN throw " + | |
87 errorObserver.numErrors() + " errors."); | |
88 logger.info( | |
89 "WSPLGEN throw " + | |
90 errorObserver.numWarnings() + " warnings."); | |
91 | |
92 MapfileGenerator.getInstance().update(); | |
93 | |
94 return; | |
95 } | |
96 } | |
97 catch (SecurityException se) { | |
98 logger.error(se); | |
99 } | |
100 catch (IOException ioe) { | |
101 logger.error(ioe); | |
102 } | |
103 catch (NullPointerException npe) { | |
104 logger.error(npe, npe); | |
105 } | |
106 catch (IndexOutOfBoundsException ioobe) { | |
107 logger.error(ioobe, ioobe); | |
108 } | |
109 } | |
110 } | |
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |