comparison flys-artifacts/src/main/java/org/dive4elements/river/wsplgen/WSPLGENCallable.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/wsplgen/WSPLGENCallable.java@b87073a05f9d
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.wsplgen;
2
3 import org.dive4elements.artifacts.CallContext;
4 import org.dive4elements.river.artifacts.model.map.WSPLGENJob;
5
6 import java.io.File;
7 import java.io.IOException;
8 import java.util.concurrent.Callable;
9
10 import org.apache.log4j.Logger;
11
12
13 /**
14 * A Callable that is used to start and observe an external Process for WSPLGEN.
15 *
16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
17 */
18 public class WSPLGENCallable implements Callable {
19
20 public static final String WSPLGEN_PARAMETER_FILE =
21 "wsplgen.par";
22
23 public static final String WSPLGEN_BIN_PATH =
24 System.getProperty("wsplgen.bin.path");
25
26
27 private Logger logger = Logger.getLogger(WSPLGENCallable.class);
28
29 private Process process;
30
31 protected Scheduler scheduler;
32
33 protected WSPLGENJob job;
34
35 protected JobObserver logObserver;
36 protected ProblemObserver errorObserver;
37
38
39 public WSPLGENCallable(Scheduler scheduler, WSPLGENJob job) {
40 this.scheduler = scheduler;
41 this.job = job;
42 this.logObserver = new JobObserver(job);
43 this.errorObserver = new ProblemObserver(job);
44 }
45
46
47 @Override
48 public WSPLGENJob call() {
49 File dir = job.getWorkingDir();
50 File parameter = new File(dir, WSPLGEN_PARAMETER_FILE);
51
52 String[] args = new String[] {
53 WSPLGEN_BIN_PATH,
54 "-PAR=\"" + parameter.getAbsolutePath() + "\""
55 };
56
57 execute(args, dir);
58
59 return job;
60 }
61
62
63 protected void execute(String[] args, File dir) {
64 logger.info("Start JobExecutor for artifact: " + dir.getName());
65
66 try {
67 synchronized (this) {
68 process = Runtime.getRuntime().exec(args, null, dir);
69
70 logObserver.setInputStream(process.getInputStream());
71 errorObserver.setInputStream(process.getErrorStream());
72
73 logObserver.start();
74 errorObserver.start();
75
76 try {
77 process.waitFor();
78 }
79 catch (InterruptedException ie) {
80 logger.warn("WSPLGEN job interrupted: " + ie.getMessage());
81 }
82
83 try {
84 logObserver.join();
85 errorObserver.join();
86 }
87 catch (InterruptedException iee) { /* do nothing */ }
88
89 logger.info("WSPLGEN exit value: " + process.exitValue());
90 logger.info(
91 "WSPLGEN throw " +
92 errorObserver.numErrors() + " errors.");
93 logger.info(
94 "WSPLGEN throw " +
95 errorObserver.numWarnings() + " warnings.");
96
97 if (process.exitValue() < 2 && errorObserver.numErrors() == 0) {
98 FacetCreator fc = job.getFacetCreator();
99 fc.createWSPLGENFacet();
100 fc.finish();
101 }
102
103 job.getCallContext().afterBackground(CallContext.STORE);
104
105 scheduler.removeJob(getJob().getArtifact().identifier());
106
107 return;
108 }
109 }
110 catch (SecurityException se) {
111 logger.error(se);
112 }
113 catch (IOException ioe) {
114 logger.error(ioe);
115 }
116 catch (NullPointerException npe) {
117 logger.error(npe, npe);
118 }
119 catch (IndexOutOfBoundsException ioobe) {
120 logger.error(ioobe, ioobe);
121 }
122 }
123
124
125 public void cancelWSPLGEN() {
126 if (process != null) {
127 logger.debug("Cancel running WSPLGEN process.");
128 process.destroy();
129 }
130 }
131
132
133 public WSPLGENJob getJob() {
134 return job;
135 }
136 }
137 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org