1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
5 | * library suite from the New Zealand Digital Library Project at the
|
---|
6 | * University of Waikato, New Zealand.
|
---|
7 | *
|
---|
8 | * <BR><BR>
|
---|
9 | *
|
---|
10 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
11 | *
|
---|
12 | * <BR><BR>
|
---|
13 | *
|
---|
14 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
15 | *
|
---|
16 | * <BR><BR>
|
---|
17 | *
|
---|
18 | * This program is free software; you can redistribute it and/or modify
|
---|
19 | * it under the terms of the GNU General Public License as published by
|
---|
20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
21 | * (at your option) any later version.
|
---|
22 | *
|
---|
23 | * <BR><BR>
|
---|
24 | *
|
---|
25 | * This program is distributed in the hope that it will be useful,
|
---|
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | * GNU General Public License for more details.
|
---|
29 | *
|
---|
30 | * <BR><BR>
|
---|
31 | *
|
---|
32 | * You should have received a copy of the GNU General Public License
|
---|
33 | * along with this program; if not, write to the Free Software
|
---|
34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
35 | *########################################################################
|
---|
36 | */
|
---|
37 | package org.greenstone.gatherer.shell;
|
---|
38 |
|
---|
39 | import java.awt.Component;
|
---|
40 | import java.util.ArrayList;
|
---|
41 | import org.greenstone.gatherer.Configuration;
|
---|
42 | import org.greenstone.gatherer.DebugStream;
|
---|
43 | import org.greenstone.gatherer.Dictionary;
|
---|
44 | import org.greenstone.gatherer.Gatherer;
|
---|
45 | import org.greenstone.gatherer.cdm.CollectionDesignManager;
|
---|
46 | import org.greenstone.gatherer.gui.GProgressBar;
|
---|
47 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
48 | /** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a buildcol.pl call.
|
---|
49 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
50 | * @version 2.3
|
---|
51 | */
|
---|
52 | public class GBuildProgressMonitor
|
---|
53 | implements GShellProgressMonitor {
|
---|
54 | /** The minimum value = 0 */
|
---|
55 | static final private int MIN = 0;
|
---|
56 | /** In order to get a smoothish progress bar, set the maximum to a large number = 1000000 */
|
---|
57 | static final private int MAX = 1000000;
|
---|
58 | /** The various states the build progress state machine can be in, starting at the base state. */
|
---|
59 | static final int BASE = -1;
|
---|
60 | static final int BUILD = 0;
|
---|
61 | static final int COMPRESSTEXT = 10;
|
---|
62 | static final int COMPRESSTEXT_COLLECTTEXTSTATS = 11;
|
---|
63 | static final int COMPRESSTEXT_CREATINGCOMPRESS = 12;
|
---|
64 | static final int COMPRESSTEXT_COMPRESSINGTEXT = 13;
|
---|
65 | static final int INDEX = 20;
|
---|
66 | static final int INDEX_CREATINGINDEXDIC = 21;
|
---|
67 | static final int INDEX_INVERTINGTEXT = 22;
|
---|
68 | static final int INDEX_CREATETHEWEIGHTS = 23;
|
---|
69 | static final int INDEX_CREATESTEMMEDDIC = 24;
|
---|
70 | static final int INDEX_CREATINGSTEMINDX = 25;
|
---|
71 | static final int CREATEINFODATA = 30;
|
---|
72 | static final int PHIND = 40;
|
---|
73 | static final int PHIND_EXTRACTINGVOCAB = 41;
|
---|
74 | static final int PHIND_EXTRACTINGPHRASE = 42;
|
---|
75 | static final int PHIND_SORTANDRENUMBER = 43;
|
---|
76 | static final int PHIND_PHRASEDATABASES = 44;
|
---|
77 | static final int PHIND_WORDLEVELINDEXES = 45;
|
---|
78 | static final int PHIND_DOCINFODATABASES = 46;
|
---|
79 | static final int CREATINGAUXILARY = 50;
|
---|
80 | /** Now the language independant sentinel strings. */
|
---|
81 | static final String BADARGUMENT_ELEMENT = "BadArgument";
|
---|
82 | static final String BADARGUMENTVALUE_ELEMENT = "BadArgumentValue";
|
---|
83 | static final String BADCLASSIFIER_ELEMENT = "BadClassifier";
|
---|
84 | static final String BADPLUGIN_ELEMENT = "BadPlugin";
|
---|
85 | static final String BUILD_ELEMENT = "Build";
|
---|
86 | static final String COLLECTTEXTSTATS_VALUE = "CollectTextStats";
|
---|
87 | static final String COMPRESSINGTEXT_VALUE = "CompressingText";
|
---|
88 | static final String COMPRESSTEXT_VALUE = "CompressText";
|
---|
89 | static final String CREATINGAUXILARY_VALUE = "CreatingAuxilary";
|
---|
90 | static final String CREATINGCOMPRESS_VALUE = "CreatingCompress";
|
---|
91 | static final String CREATINGINDEXDIC_VALUE = "CreatingIndexDic";
|
---|
92 | static final String CREATINGSTEMINDX_VALUE = "CreatingStemIndx";
|
---|
93 | static final String CREATEINFODATA_VALUE = "CreateInfoData";
|
---|
94 | static final String CREATESTEMMEDDIC_VALUE = "CreateStemmedDic";
|
---|
95 | static final String CREATETHEWEIGHTS_VALUE = "CreateTheWeights";
|
---|
96 | static final String DOCINFODATABASES_VALUE = "DocInfoDatabases";
|
---|
97 | static final String EXTRACTINGPHRASE_VALUE = "ExtractingPhrase";
|
---|
98 | static final String EXTRACTINGVOCAB_VALUE = "ExtractingVocab";
|
---|
99 | static final String FATALERROR_ELEMENT = "FatalError";
|
---|
100 | static final String INDEX_VALUE = "Index";
|
---|
101 | static final String INVERTINGTEXT_VALUE = "InvertingText";
|
---|
102 | static final String NAME_ATTRIBUTE = "name";
|
---|
103 | static final String PHASE_ELEMENT = "Phase";
|
---|
104 | static final String PHIND_VALUE = "Phind";
|
---|
105 | static final String PHRASEDATABASES_VALUE = "PhraseDatabases";
|
---|
106 | static final String SKIPCREATINGCOMP_VALUE = "SkipCreatingComp";
|
---|
107 | static final String SORTANDRENUMBER_VALUE = "SortAndRenumber";
|
---|
108 | static final String SOURCE_ATTRIBUTE = "source";
|
---|
109 | static final String STAGE_ELEMENT = "Stage";
|
---|
110 | static final String WARNING_ELEMENT = "Warning";
|
---|
111 | static final String WORDLEVELINDEXES_VALUE = "WordLevelIndexes";
|
---|
112 |
|
---|
113 | static final private String ARGUMENT_ATTRIBUTE = "a";
|
---|
114 | static final private String CLASSIFIER_ATTRIBUTE = "c";
|
---|
115 | static final private String PLUGIN_ATTRIBUTE = "p";
|
---|
116 |
|
---|
117 | /** Indicates if the GUI has asked the process this object monitors to stop. */
|
---|
118 | private boolean stop = false;
|
---|
119 | /** The current number of stages we have completed. */
|
---|
120 | private int current_stages = 0;
|
---|
121 | /** The number of stages we are expecting to complete. */
|
---|
122 | private int expected_stages = 0;
|
---|
123 |
|
---|
124 | private int threshold = Configuration.SYSTEMS_MODE;
|
---|
125 | /** The current state we are in. The state will change depending on the next flag recieved. */
|
---|
126 | private int state = BASE;
|
---|
127 | /** The progress bar this monitor updates. */
|
---|
128 | private GProgressBar progress_bar;
|
---|
129 | /** A progress bar that is shared between this this listener and the Import monitor. */
|
---|
130 | private GProgressBar shared_progress_bar;
|
---|
131 |
|
---|
132 | /** Construct a new GBuildProgressMonitor. */
|
---|
133 | public GBuildProgressMonitor(GProgressBar shared_progress_bar) {
|
---|
134 | this.shared_progress_bar = shared_progress_bar;
|
---|
135 | progress_bar = new GProgressBar();
|
---|
136 | progress_bar.setMaximum(MAX);
|
---|
137 | progress_bar.setMinimum(MIN);
|
---|
138 | progress_bar.setString(null);
|
---|
139 | progress_bar.setStringPainted(true);
|
---|
140 | setValue(MIN);
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** Method to register a new progress bar with this monitor.
|
---|
144 | * @param progress_bar The new <strong>GProgressBar</strong>.
|
---|
145 | */
|
---|
146 | public void addProgressBar(GProgressBar progress_bar) {
|
---|
147 | this.progress_bar = progress_bar;
|
---|
148 | progress_bar.setMaximum(MAX);
|
---|
149 | progress_bar.setMinimum(MIN);
|
---|
150 | progress_bar.setStringPainted(false);
|
---|
151 | progress_bar.setString(null);
|
---|
152 | setValue(MIN);
|
---|
153 | }
|
---|
154 |
|
---|
155 | /** Determine the script exit value according to the progress monitor. This gets around a problem where several script failures actually result with a successful exit value.
|
---|
156 | * @return A <i>int</i> with a value of zero if and only if the script was successful.
|
---|
157 | */
|
---|
158 | public int exitValue() {
|
---|
159 | if(state == BASE) {
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 | return 1;
|
---|
163 | }
|
---|
164 | /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>GProgressBar</strong> but there may be others implemented later.
|
---|
165 | * @return A <strong>Component</strong> on which the progress of the process is being displayed.
|
---|
166 | */
|
---|
167 | public Component getProgress() {
|
---|
168 | return progress_bar;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public GProgressBar getSharedProgress() {
|
---|
172 | return shared_progress_bar;
|
---|
173 | }
|
---|
174 |
|
---|
175 | public void messageOnProgressBar(String message)
|
---|
176 | {
|
---|
177 | if (message!=null && !message.equals("")) {
|
---|
178 | progress_bar.setString(message);
|
---|
179 | shared_progress_bar.setString(message);
|
---|
180 | }
|
---|
181 | else {
|
---|
182 | progress_bar.setString(null);
|
---|
183 | shared_progress_bar.setString(null);
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
|
---|
188 | * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
|
---|
189 | */
|
---|
190 | public synchronized boolean hasSignalledStop() {
|
---|
191 | return stop;
|
---|
192 | }
|
---|
193 | /** Inform the progress bar that it should programatically increment progress by one step. */
|
---|
194 | public void increment() {
|
---|
195 | // There is no reason this should be called for a build.
|
---|
196 | }
|
---|
197 |
|
---|
198 | /** This method is used to 'feed in' a line of text captured from the process.
|
---|
199 | * @param queue a queue which at the moment should contain a single GShellEvent
|
---|
200 | */
|
---|
201 | public void process(ArrayList queue) {
|
---|
202 | GShellEvent event = (GShellEvent) queue.get(0);
|
---|
203 | // Remove 'build.pl> ' bit
|
---|
204 | String line = event.getMessage();
|
---|
205 | line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1);
|
---|
206 | line = line.trim();
|
---|
207 | // We are only really interested in processing pseudo-XML tags
|
---|
208 | if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) {
|
---|
209 | // All events are vetoed
|
---|
210 | event.veto();
|
---|
211 |
|
---|
212 | // Create a new element from it
|
---|
213 | GShellElement element = new GShellElement(line);
|
---|
214 | // Now change states within the state machine as appropriate. A state change may subsequently incur a progress update.
|
---|
215 | String name = null;
|
---|
216 | String value = null;
|
---|
217 | switch(state) {
|
---|
218 | case BASE:
|
---|
219 | // The only thing we would expect is a build message
|
---|
220 | name = element.getElementName();
|
---|
221 | if(name.equals(BUILD_ELEMENT)) {
|
---|
222 | progress_bar.setIndeterminate(false);
|
---|
223 | state = BUILD;
|
---|
224 | // Produce a lower detail message if required
|
---|
225 | if(Configuration.getMode() <= threshold && !stop) {
|
---|
226 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildBegun1"), event.getStatus()));
|
---|
227 | }
|
---|
228 | }
|
---|
229 | else {
|
---|
230 | // Unknown command, go indeterminate
|
---|
231 | DebugStream.println("Unknown name: " + name);
|
---|
232 | progress_bar.setIndeterminate(true);
|
---|
233 | }
|
---|
234 | name = null;
|
---|
235 | break;
|
---|
236 | case BUILD:
|
---|
237 | // The only thing we would expect is a stage element or a
|
---|
238 | // bad classifier arg name
|
---|
239 | name = element.getElementName();
|
---|
240 |
|
---|
241 | if(name.equals(STAGE_ELEMENT)) {
|
---|
242 | progress_bar.setIndeterminate(false);
|
---|
243 | // Now we determine what stage we are moving to
|
---|
244 | value = element.getAttribute(NAME_ATTRIBUTE);
|
---|
245 | if(value.equals(COMPRESSTEXT_VALUE)) {
|
---|
246 | state = COMPRESSTEXT;
|
---|
247 | if(Configuration.getMode() <= threshold) {
|
---|
248 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.CompressText"), event.getStatus()));
|
---|
249 | }
|
---|
250 | }
|
---|
251 | else if(value.equals(INDEX_VALUE)) {
|
---|
252 | state = INDEX;
|
---|
253 | if(Configuration.getMode() <= threshold) {
|
---|
254 | String args[] = new String[1];
|
---|
255 | args[0] = element.getAttribute(SOURCE_ATTRIBUTE);
|
---|
256 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Index", args), event.getStatus()));
|
---|
257 | args = null;
|
---|
258 | }
|
---|
259 | }
|
---|
260 | else if(value.equals(CREATEINFODATA_VALUE)) {
|
---|
261 | state = CREATEINFODATA;
|
---|
262 | if(Configuration.getMode() <= threshold) {
|
---|
263 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.InfoDatabase"), event.getStatus()));
|
---|
264 | }
|
---|
265 | }
|
---|
266 | else if(value.equals(PHIND_VALUE)) {
|
---|
267 | state = PHIND;
|
---|
268 | if(Configuration.getMode() <= threshold) {
|
---|
269 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Phind"), event.getStatus()));
|
---|
270 | }
|
---|
271 | }
|
---|
272 | else if(value.equals(CREATINGAUXILARY_VALUE)) {
|
---|
273 | state = CREATINGAUXILARY;
|
---|
274 | if(Configuration.getMode() <= threshold) {
|
---|
275 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Auxilary"), event.getStatus()));
|
---|
276 | }
|
---|
277 | }
|
---|
278 | else {
|
---|
279 | // Unknown command, go indeterminate
|
---|
280 | DebugStream.println("Unknown value: " + value);
|
---|
281 | progress_bar.setIndeterminate(true);
|
---|
282 | }
|
---|
283 | value = null;
|
---|
284 | }
|
---|
285 | // The build end message indicates a successfulish build.
|
---|
286 | else if(name.equals(BUILD_ELEMENT) && element.isClosed()) {
|
---|
287 | progress_bar.setIndeterminate(false);
|
---|
288 | setValue(MAX);
|
---|
289 | state = BASE;
|
---|
290 | if(Configuration.getMode() <= threshold) {
|
---|
291 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildComplete1"), event.getStatus()));
|
---|
292 | }
|
---|
293 | }
|
---|
294 | // We had a bad argument to a plugin/classifier
|
---|
295 | else if (name.equals(BADARGUMENT_ELEMENT)) {
|
---|
296 | if(Configuration.getMode() <= threshold) {
|
---|
297 | String args[] = new String[1];
|
---|
298 | args[0] = element.getAttribute(ARGUMENT_ATTRIBUTE);
|
---|
299 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadArgument", args), event.getStatus()));
|
---|
300 | args = null;
|
---|
301 | }
|
---|
302 | }
|
---|
303 | // We had a bad argument value to a plugin/clasifier
|
---|
304 | else if (name.equals(BADARGUMENTVALUE_ELEMENT)) {
|
---|
305 | if(Configuration.getMode() <= threshold) {
|
---|
306 | String args[] = new String[1];
|
---|
307 | args[0] = element.getAttribute(ARGUMENT_ATTRIBUTE);
|
---|
308 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadArgumentValue", args), event.getStatus()));
|
---|
309 | args = null;
|
---|
310 | }
|
---|
311 | }
|
---|
312 | // And this one tellsa us the plugin
|
---|
313 | else if (name.equals(BADPLUGIN_ELEMENT)) {
|
---|
314 | if(Configuration.getMode() <= threshold) {
|
---|
315 | String args[] = new String[1];
|
---|
316 | args[0] = element.getAttribute(PLUGIN_ATTRIBUTE);
|
---|
317 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadPluginOptions", args), event.getStatus()));
|
---|
318 | args = null;
|
---|
319 | }
|
---|
320 | }
|
---|
321 | // or the classifier
|
---|
322 | else if (name.equals(BADCLASSIFIER_ELEMENT)) {
|
---|
323 | if(Configuration.getMode() <= threshold) {
|
---|
324 | String args[] = new String[1];
|
---|
325 | args[0] = element.getAttribute(CLASSIFIER_ATTRIBUTE);
|
---|
326 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadClassifierOptions", args), event.getStatus()));
|
---|
327 | args = null;
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | else {
|
---|
332 | // Unknown command, go indeterminate
|
---|
333 | DebugStream.println("Unknown name: " + name);
|
---|
334 | progress_bar.setIndeterminate(true);
|
---|
335 | }
|
---|
336 | name = null;
|
---|
337 | break;
|
---|
338 | case COMPRESSTEXT:
|
---|
339 | // We are either dealing with a phase, aa fatal error or an end stage
|
---|
340 | name = element.getElementName();
|
---|
341 | if(name.equals(PHASE_ELEMENT)) {
|
---|
342 | // There are three phases within compressing text (or of four possible ones)
|
---|
343 | value = element.getAttribute(NAME_ATTRIBUTE);
|
---|
344 | if(value.equals(COLLECTTEXTSTATS_VALUE)) {
|
---|
345 | // Nothing to do
|
---|
346 | }
|
---|
347 | else if(value.equals(CREATINGCOMPRESS_VALUE) || value.equals(SKIPCREATINGCOMP_VALUE)) {
|
---|
348 | // One third complete
|
---|
349 | progress_bar.setIndeterminate(false);
|
---|
350 | setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages);
|
---|
351 | }
|
---|
352 | else if(value.equals(COMPRESSINGTEXT_VALUE)) {
|
---|
353 | // Two thirds complete
|
---|
354 | progress_bar.setIndeterminate(false);
|
---|
355 | setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
|
---|
356 | }
|
---|
357 | else {
|
---|
358 | // Unknown command, go indeterminate
|
---|
359 | DebugStream.println("Unknown value: " + value);
|
---|
360 | progress_bar.setIndeterminate(true);
|
---|
361 | }
|
---|
362 | value = null;
|
---|
363 | }
|
---|
364 | // Note that a fatal error is always followed by an end-stage, but not an end build. Thus the final state will be build (not base) and calls to exitValue() with indicate failure.
|
---|
365 | else if(name.equals(FATALERROR_ELEMENT)) {
|
---|
366 | // On simplier modes produce a meaningful message
|
---|
367 | queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.FatalError"), event.getStatus()));
|
---|
368 | }
|
---|
369 | else if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
|
---|
370 | // Increase progress so that stage is complete.
|
---|
371 | current_stages++;
|
---|
372 | progress_bar.setIndeterminate(false);
|
---|
373 | setValue((current_stages * MAX) / expected_stages);
|
---|
374 | state = BUILD;
|
---|
375 | }
|
---|
376 | else {
|
---|
377 | // Unknown command, go indeterminate
|
---|
378 | DebugStream.println("Unknown name: " + name);
|
---|
379 | progress_bar.setIndeterminate(true);
|
---|
380 | }
|
---|
381 | name = null;
|
---|
382 | break;
|
---|
383 | case INDEX:
|
---|
384 | /** @todo - If on lower modes output a meaningful message. */
|
---|
385 | name = element.getElementName();
|
---|
386 | if(name.equals(PHASE_ELEMENT)) {
|
---|
387 | value = element.getAttribute(NAME_ATTRIBUTE);
|
---|
388 | if(value.equals(CREATINGINDEXDIC_VALUE)) {
|
---|
389 | // Nothing to do
|
---|
390 | }
|
---|
391 | else if(value.equals(INVERTINGTEXT_VALUE)) {
|
---|
392 | // One fifth complete
|
---|
393 | progress_bar.setIndeterminate(false);
|
---|
394 | setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages);
|
---|
395 | }
|
---|
396 | else if(value.equals(CREATETHEWEIGHTS_VALUE)) {
|
---|
397 | // Two fifths complete
|
---|
398 | progress_bar.setIndeterminate(false);
|
---|
399 | setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages);
|
---|
400 | }
|
---|
401 | else if(value.equals(CREATESTEMMEDDIC_VALUE)) {
|
---|
402 | // Three fifths complete
|
---|
403 | progress_bar.setIndeterminate(false);
|
---|
404 | setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
|
---|
405 | }
|
---|
406 | else if(value.equals(CREATINGSTEMINDX_VALUE)) {
|
---|
407 | // Four fifths complete
|
---|
408 | progress_bar.setIndeterminate(false);
|
---|
409 | setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages);
|
---|
410 | }
|
---|
411 | else {
|
---|
412 | // Unknown command, go indeterminate
|
---|
413 | DebugStream.println("Unknown value: " + value);
|
---|
414 | progress_bar.setIndeterminate(true);
|
---|
415 | }
|
---|
416 | value = null;
|
---|
417 | }
|
---|
418 | else if(name.equals(WARNING_ELEMENT)) {
|
---|
419 | /** @todo - If on lower modes output a meaningful message. */
|
---|
420 | }
|
---|
421 | // Note that a fatal error is always followed by an end-stage, but not an end build. Thus the final state will be build (not base) and calls to exitValue() with indicate failure.
|
---|
422 | else if(name.equals(FATALERROR_ELEMENT)) {
|
---|
423 | // On lower modes output a meaningful message.
|
---|
424 |
|
---|
425 | }
|
---|
426 | else if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
|
---|
427 | // Increase progress so that stage is complete.
|
---|
428 | current_stages++;
|
---|
429 | progress_bar.setIndeterminate(false);
|
---|
430 | setValue((current_stages * MAX) / expected_stages);
|
---|
431 | state = BUILD;
|
---|
432 | }
|
---|
433 | else {
|
---|
434 | // Unknown command, go indeterminate
|
---|
435 | DebugStream.println("Unknown name: " + name);
|
---|
436 | progress_bar.setIndeterminate(true);
|
---|
437 | }
|
---|
438 | name = null;
|
---|
439 | break;
|
---|
440 | case PHIND:
|
---|
441 | name = element.getElementName();
|
---|
442 | if(name.equals(PHASE_ELEMENT)) {
|
---|
443 | value = element.getAttribute(NAME_ATTRIBUTE);
|
---|
444 | if(value.equals(EXTRACTINGVOCAB_VALUE)) {
|
---|
445 | // Nothing to do
|
---|
446 | }
|
---|
447 | else if(value.equals(EXTRACTINGPHRASE_VALUE)) {
|
---|
448 | // One sixth complete
|
---|
449 | progress_bar.setIndeterminate(false);
|
---|
450 | setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages);
|
---|
451 | }
|
---|
452 | else if(value.equals(SORTANDRENUMBER_VALUE)) {
|
---|
453 | // Two sixths complete
|
---|
454 | progress_bar.setIndeterminate(false);
|
---|
455 | setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages);
|
---|
456 | }
|
---|
457 | else if(value.equals(PHRASEDATABASES_VALUE)) {
|
---|
458 | // Three sixths complete
|
---|
459 | progress_bar.setIndeterminate(false);
|
---|
460 | setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages);
|
---|
461 | }
|
---|
462 | else if(value.equals(WORDLEVELINDEXES_VALUE)) {
|
---|
463 | // Four sixths complete
|
---|
464 | progress_bar.setIndeterminate(false);
|
---|
465 | setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages);
|
---|
466 | }
|
---|
467 | else if(value.equals(DOCINFODATABASES_VALUE)) {
|
---|
468 | // Five sixths complete
|
---|
469 | progress_bar.setIndeterminate(false);
|
---|
470 | setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages);
|
---|
471 | }
|
---|
472 | else {
|
---|
473 | // Unknown command, go indeterminate
|
---|
474 | DebugStream.println("Unknown value: " + value);
|
---|
475 | progress_bar.setIndeterminate(true);
|
---|
476 | }
|
---|
477 | value = null;
|
---|
478 | }
|
---|
479 | else if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
|
---|
480 | // Increase progress so that stage is complete.
|
---|
481 | current_stages++;
|
---|
482 | progress_bar.setIndeterminate(false);
|
---|
483 | setValue((current_stages * MAX) / expected_stages);
|
---|
484 | state = BUILD;
|
---|
485 | }
|
---|
486 | else {
|
---|
487 | // Unknown command, go indeterminate
|
---|
488 | DebugStream.println("Unknown name: " + name);
|
---|
489 | progress_bar.setIndeterminate(true);
|
---|
490 | }
|
---|
491 | name = null;
|
---|
492 | break;
|
---|
493 | case CREATEINFODATA:
|
---|
494 | case CREATINGAUXILARY:
|
---|
495 | name = element.getElementName();
|
---|
496 | if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
|
---|
497 | // Another stage complete
|
---|
498 | current_stages++;
|
---|
499 | progress_bar.setIndeterminate(false);
|
---|
500 | setValue((current_stages * MAX) / expected_stages);
|
---|
501 | state = BUILD;
|
---|
502 | }
|
---|
503 | else {
|
---|
504 | // Unknown command, go indeterminate
|
---|
505 | DebugStream.println("Unknown name: " + name);
|
---|
506 | progress_bar.setIndeterminate(true);
|
---|
507 | }
|
---|
508 | name = null;
|
---|
509 | break;
|
---|
510 | default:
|
---|
511 | // Unknown command, go indeterminate
|
---|
512 | DebugStream.println("Unknown name: " + name);
|
---|
513 | progress_bar.setIndeterminate(true);
|
---|
514 | }
|
---|
515 | }
|
---|
516 | // If we are dealing with lower detail modes then veto any other messages. We do this here as the progress monitors are garuenteed to recieve this message before anything else
|
---|
517 | else if(Configuration.getMode() <= threshold) {
|
---|
518 | event.veto();
|
---|
519 | }
|
---|
520 | }
|
---|
521 |
|
---|
522 | public void reset() {
|
---|
523 | current_stages = 0;
|
---|
524 | expected_stages = 0;
|
---|
525 | progress_bar.setIndeterminate(false);
|
---|
526 | progress_bar.setString(null);
|
---|
527 | setValue(MIN);
|
---|
528 | state = BASE;
|
---|
529 | progress_bar.updateUI();
|
---|
530 | }
|
---|
531 |
|
---|
532 | public void saving() {
|
---|
533 | }
|
---|
534 |
|
---|
535 | public void setSharedProgressBar(GProgressBar shared_progress_bar) {
|
---|
536 | this.shared_progress_bar = shared_progress_bar;
|
---|
537 | }
|
---|
538 |
|
---|
539 | /** Since the creator of this process monitor is actually in the GUI, this class provides the simpliest way to send a cancel process message between the two.
|
---|
540 | * @param state The desired state of the stop flag as a <strong>boolean</strong>.
|
---|
541 | */
|
---|
542 | public synchronized void setStop(boolean state) {
|
---|
543 | this.stop = state;
|
---|
544 | progress_bar.setIndeterminate(false);
|
---|
545 | }
|
---|
546 | /** This method resets this monitor to the start, reseting the process parsing and progress bar.
|
---|
547 | * TODO Everthing.
|
---|
548 | */
|
---|
549 | public void start() {
|
---|
550 | stop = false;
|
---|
551 | setValue(MIN);
|
---|
552 | expected_stages = 3; // Always compress text, create info database and auxiliary creation
|
---|
553 | // Retrieve cdm.
|
---|
554 | CollectionDesignManager cdm = Gatherer.c_man.getCollection().cdm;
|
---|
555 | // If we are using MGPP the number of indexes is always 1
|
---|
556 | if(cdm.index_manager.isMGPP()) {
|
---|
557 | expected_stages = expected_stages + 1;
|
---|
558 | } else if (cdm.index_manager.isLucene()) {
|
---|
559 | // lucene no of indexes == number of levels
|
---|
560 | int num_levels = cdm.index_manager.getNumLevels();
|
---|
561 | if (num_levels == 0) num_levels = 1;
|
---|
562 | expected_stages = expected_stages + num_levels;
|
---|
563 | }
|
---|
564 | else {
|
---|
565 | int num_indexes = cdm.index_manager.getNumIndexes();
|
---|
566 | int num_partitions = cdm.subcollectionindex_manager.getSize();
|
---|
567 | if(num_partitions > 0) {
|
---|
568 | num_indexes = num_indexes * num_partitions;
|
---|
569 | }
|
---|
570 | int num_languages = cdm.language_manager.getSize();
|
---|
571 | if(num_languages > 0) {
|
---|
572 | num_indexes = num_indexes * num_languages;
|
---|
573 | }
|
---|
574 | expected_stages = expected_stages + num_indexes;
|
---|
575 | }
|
---|
576 | // And if we have a phind classifier, we have one further index
|
---|
577 | if(cdm.classifier_manager.isPhindClassifierAssigned()) {
|
---|
578 | expected_stages = expected_stages + 1;
|
---|
579 | }
|
---|
580 | cdm = null;
|
---|
581 | }
|
---|
582 | /** This method indicates the process is complete.
|
---|
583 | * TODO Everthing.
|
---|
584 | */
|
---|
585 | public void stop() {
|
---|
586 | progress_bar.setIndeterminate(false);
|
---|
587 | setValue(MAX);
|
---|
588 | }
|
---|
589 |
|
---|
590 | private void setValue(int value) {
|
---|
591 | progress_bar.setValue(value);
|
---|
592 | // Incrementing the shared progress bar is a little more problematic as we may very well be trying to set it to MIN but instead set it to halfway if we're not careful.
|
---|
593 | if(value > MIN) {
|
---|
594 | shared_progress_bar.setValue(MAX + value);
|
---|
595 | }
|
---|
596 | }
|
---|
597 | }
|
---|
598 |
|
---|