Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/wsplgen/JobExecutor.java @ 1147:e7d5452a7381
Added a 'ProblemObserver' that analyses WSPLGEN's error stream for errors and warnings.
flys-artifacts/trunk@2677 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 08 Sep 2011 11:24:27 +0000 |
parents | e6dd52342eb7 |
children | aaf8d32f85bd |
comparison
equal
deleted
inserted
replaced
1146:66d98964f2df | 1147:e7d5452a7381 |
---|---|
1 package de.intevation.flys.wsplgen; | 1 package de.intevation.flys.wsplgen; |
2 | 2 |
3 import java.io.InputStream; | |
4 import java.io.IOException; | 3 import java.io.IOException; |
5 import java.io.File; | 4 import java.io.File; |
6 | 5 |
7 import org.apache.log4j.Logger; | 6 import org.apache.log4j.Logger; |
8 | 7 |
26 | 25 |
27 private Process process; | 26 private Process process; |
28 | 27 |
29 protected WSPLGENJob job; | 28 protected WSPLGENJob job; |
30 | 29 |
31 protected JobObserver observer; | 30 protected JobObserver logObserver; |
31 protected ProblemObserver errorObserver; | |
32 | 32 |
33 | 33 |
34 public JobExecutor(WSPLGENJob job) { | 34 public JobExecutor(WSPLGENJob job) { |
35 this.job = job; | 35 this.job = job; |
36 this.observer = new JobObserver(job); | 36 this.logObserver = new JobObserver(job); |
37 this.errorObserver = new ProblemObserver(job); | |
37 } | 38 } |
38 | 39 |
39 | 40 |
40 public void execute() { | 41 public void execute() { |
41 File dir = job.getWorkingDir(); | 42 File dir = job.getWorkingDir(); |
44 String[] args = new String[] { | 45 String[] args = new String[] { |
45 WSPLGEN_BIN_PATH, | 46 WSPLGEN_BIN_PATH, |
46 "-PAR=\"" + parameter.getAbsolutePath() + "\"" | 47 "-PAR=\"" + parameter.getAbsolutePath() + "\"" |
47 }; | 48 }; |
48 | 49 |
49 execute(args, dir, observer); | 50 execute(args, dir); |
50 } | 51 } |
51 | 52 |
52 | 53 |
53 public void execute(String[] args, File dir, JobObserver observer) { | 54 protected void execute(String[] args, File dir) { |
54 logger.info("Start JobExecutor for artifact: " + dir.getName()); | 55 logger.info("Start JobExecutor for artifact: " + dir.getName()); |
55 | 56 |
56 String errorMsg = null; | 57 String errorMsg = null; |
57 | 58 |
58 try { | 59 try { |
59 synchronized (this) { | 60 synchronized (this) { |
60 process = Runtime.getRuntime().exec(args, null, dir); | 61 process = Runtime.getRuntime().exec(args, null, dir); |
61 | 62 |
62 InputStream out = process.getInputStream(); | 63 logObserver.setInputStream(process.getInputStream()); |
63 observer.setInputStream(out); | 64 errorObserver.setInputStream(process.getErrorStream()); |
64 | 65 |
65 observer.start(); | 66 logObserver.start(); |
67 errorObserver.start(); | |
66 | 68 |
67 try { | 69 try { |
68 process.waitFor(); | 70 process.waitFor(); |
69 } | 71 } |
70 catch (InterruptedException ie) { | 72 catch (InterruptedException ie) { |
71 logger.error("WSPLGEN job interrupted: " + ie.getMessage()); | 73 logger.error("WSPLGEN job interrupted: " + ie.getMessage()); |
72 } | 74 } |
73 | 75 |
74 try { | 76 try { |
75 observer.join(); | 77 logObserver.join(); |
78 errorObserver.join(); | |
76 } | 79 } |
77 catch (InterruptedException iee) { /* do nothing */ } | 80 catch (InterruptedException iee) { /* do nothing */ } |
78 | 81 |
79 job.getCallContext().afterBackground(CallContext.STORE); | 82 job.getCallContext().afterBackground(CallContext.STORE); |
80 | 83 |
81 logger.info("WSPLGEN exit value: " + process.exitValue()); | 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."); | |
82 | 91 |
83 MapfileGenerator.getInstance().update(); | 92 MapfileGenerator.getInstance().update(); |
84 | 93 |
85 return; | 94 return; |
86 } | 95 } |