Changeset 6388
- Timestamp:
- 2004-01-09T15:00:44+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/shell
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/shell/GBasicProgressMonitor.java
r6325 r6388 48 48 49 49 import java.awt.Component; 50 import java.util.ArrayList; 50 51 import javax.swing.JProgressBar; 51 52 import org.greenstone.gatherer.shell.GShellEvent; … … 92 93 } 93 94 /** The parse method is how more complex progress bars figure out how far they have progressed. However we don't. 94 * @param event a GShellEvent containing information from the GShell95 * @param queue a queue which at the moment should contain a single GShellEvent 95 96 */ 96 public void process( GShellEvent event) {97 public void process(ArrayList queue) { 97 98 } 99 100 public void reset() {}; 98 101 99 102 public void saving() { -
trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java
r6325 r6388 38 38 39 39 import java.awt.Component; 40 import java.util.ArrayList; 40 41 import javax.swing.JProgressBar; 42 import org.greenstone.gatherer.Configuration; 43 import org.greenstone.gatherer.Dictionary; 41 44 import org.greenstone.gatherer.Gatherer; 42 45 import org.greenstone.gatherer.cdm.CollectionDesignManager; 43 46 import org.greenstone.gatherer.shell.GImportProgressMonitor; 47 import org.greenstone.gatherer.shell.GShellElement; 44 48 import org.greenstone.gatherer.shell.GShellEvent; 45 49 import org.greenstone.gatherer.shell.GShellProgressMonitor; 50 import org.greenstone.gatherer.util.StaticStrings; 46 51 /** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a buildcol.pl call. 47 52 * @author John Thompson, Greenstone Digital Library, University of Waikato 48 * @version 2. 153 * @version 2.3 49 54 */ 50 55 public class GBuildProgressMonitor 51 56 implements GShellProgressMonitor { 57 /** The minimum value = 0 */ 58 static final private int MIN = 0; 59 /** In order to get a smoothish progress bar, set the maximum to a large number = 1000000 */ 60 static final private int MAX = 1000000; 61 /** The various states the build progress state machine can be in, starting at the base state. */ 62 static final int BASE = -1; 63 static final int BUILD = 0; 64 static final int COMPRESSTEXT = 10; 65 static final int COMPRESSTEXT_COLLECTTEXTSTATS = 11; 66 static final int COMPRESSTEXT_CREATINGCOMPRESS = 12; 67 static final int COMPRESSTEXT_COMPRESSINGTEXT = 13; 68 static final int INDEX = 20; 69 static final int INDEX_CREATINGINDEXDIC = 21; 70 static final int INDEX_INVERTINGTEXT = 22; 71 static final int INDEX_CREATETHEWEIGHTS = 23; 72 static final int INDEX_CREATESTEMMEDDIC = 24; 73 static final int INDEX_CREATINGSTEMINDX = 25; 74 static final int CREATEINFODATA = 30; 75 static final int PHIND = 40; 76 static final int PHIND_EXTRACTINGVOCAB = 41; 77 static final int PHIND_EXTRACTINGPHRASE = 42; 78 static final int PHIND_SORTANDRENUMBER = 43; 79 static final int PHIND_PHRASEDATABASES = 44; 80 static final int PHIND_WORDLEVELINDEXES = 45; 81 static final int PHIND_DOCINFODATABASES = 46; 82 static final int CREATINGAUXILARY = 50; 83 /** Now the language independant sentinel strings. */ 84 static final String BUILD_ELEMENT = "Build"; 85 static final String COLLECTTEXTSTATS_VALUE = "CollectTextStats"; 86 static final String COMPRESSINGTEXT_VALUE = "CompressingText"; 87 static final String COMPRESSTEXT_VALUE = "CompressText"; 88 static final String CREATINGAUXILARY_VALUE = "CreatingAuxilary"; 89 static final String CREATINGCOMPRESS_VALUE = "CreatingCompress"; 90 static final String CREATINGINDEXDIC_VALUE = "CreatingIndexDic"; 91 static final String CREATINGSTEMINDX_VALUE = "CreatingStemIndx"; 92 static final String CREATEINFODATA_VALUE = "CreateInfoData"; 93 static final String CREATESTEMMEDDIC_VALUE = "CreateStemmedDic"; 94 static final String CREATETHEWEIGHTS_VALUE = "CreateTheWeights"; 95 static final String DOCINFODATABASES_VALUE = "DocInfoDatabases"; 96 static final String EXTRACTINGPHRASE_VALUE = "ExtractingPhrase"; 97 static final String EXTRACTINGVOCAB_VALUE = "ExtractingVocab"; 98 static final String FATALERROR_ELEMENT = "FatalError"; 99 static final String INDEX_VALUE = "Index"; 100 static final String INVERTINGTEXT_VALUE = "InvertingText"; 101 static final String NAME_ATTRIBUTE = "name"; 102 static final String PHASE_ELEMENT = "Phase"; 103 static final String PHIND_VALUE = "Phind"; 104 static final String PHRASEDATABASES_VALUE = "PhraseDatabases"; 105 static final String SKIPCREATINGCOMP_VALUE = "SkipCreatingComp"; 106 static final String SORTANDRENUMBER_VALUE = "SortAndRenumber"; 107 static final String SOURCE_ATTRIBUTE = "source"; 108 static final String STAGE_ELEMENT = "Stage"; 109 static final String WARNING_ELEMENT = "Warning"; 110 static final String WORDLEVELINDEXES_VALUE = "WordLevelIndexes"; 52 111 /** Indicates if the GUI has asked the process this object monitors to stop. */ 53 112 private boolean stop = false; 54 55 private GImportProgressMonitor import_progress = null; 56 57 private int num_docs = -1; 58 59 private int num_indexes = -1; 60 61 private int state = 0; 62 113 /** The current number of stages we have completed. */ 114 private int current_stages = 0; 115 /** The number of stages we are expecting to complete. */ 116 private int expected_stages = 0; 117 118 private int threshold = Configuration.SYSTEMS_MODE; 119 /** The current state we are in. The state will change depending on the next flag recieved. */ 120 private int state = BASE; 63 121 /** The progress bar this monitor updates. */ 64 122 private JProgressBar progress_bar; 65 123 66 static final private int MIN = 0; 67 static final private int MAX = 1000000; 68 69 static final int BASE = 0; 70 static final int CTCT = 1; // Creating the compressed text 71 static final int CTCT_CTS = 2; // Creating the compressed text - collecting text statistics 72 static final int CTCT_CTS_PS = 3; // Creating the compressed text - collecting text statistics - parsed successfully 73 static final int CTCT_CTCD = 4; // Creating the compressed text - creating the compression dictionary 74 static final int CTCT_CTT = 5; // Creating the compressed text - compressing the text 75 static final int CTCT_CTT_PS = 6; // Creating the compressed text - compressing the text - parsed successfully 76 static final int BI = 7; // Building index 77 static final int BI_CID = 8; // Building index - creating index dictionary 78 static final int BI_CID_PS = 9; // Building index - creating index dictionary - parsed successfully 79 static final int BI_ITT = 10; // Building index - inverting the text 80 static final int BI_ITT_PS = 11; // Building index - inverting the text - parsed successfully 81 static final int BI_CTWF = 12; // Building index - create the weights file 82 static final int BI_CODSD = 13; // Building index - creating 'on-disk' stemmed dictionary 83 static final int BI_CSI = 14; // Building index - creating stem indexes 84 static final int CTID = 15; // Creating the info database 85 static final int CTID_PS = 16; // Creating the info database - parsed successfully 86 static final int CAF = 17; // Creating auxiliary files 87 static final int PHIND = 18; // Running Phind 88 static final int SUFFIX = 19; // Running Suffix 89 static final int SUFFIX_DONE = 20; // Suffix Complete 90 91 static final String BI_STR = "*** building index"; 92 static final String CTS_STR = "collecting text statistics"; 93 static final String CTT_STR = "compressing the text"; 94 static final String CTWF_STR = "create the weights file"; 95 static final String CAF_STR = "creating auxiliary files"; 96 static final String CID_STR = "creating index dictionary"; 97 static final String CSI_STR = "creating stem indexes"; 98 static final String CTCT_STR = "*** creating the compressed text"; 99 static final String CTCD_STR = "creating the compression dictionary"; 100 static final String CTID_STR = "*** creating the info database and processing associated files"; 101 static final String CODSD_STR = "creating 'on-disk' stemmed dictionary"; 102 static final String ITT_STR = "inverting the text"; 103 static final String PS_STR = "hash"; 104 static final String PHIND_STR = "*** Phind.pm"; 105 static final String PHIND_SUFFIX_STR = "suffix:"; 106 static final String PHIND_DONE_STR = "Done:"; 107 108 public GBuildProgressMonitor(GImportProgressMonitor import_progress) { 109 this.import_progress = import_progress; 124 /** Construct a new GBuildProgressMonitor. */ 125 public GBuildProgressMonitor() { 110 126 progress_bar = new JProgressBar(); 111 127 progress_bar.setMaximum(MAX); … … 151 167 152 168 /** This method is used to 'feed in' a line of text captured from the process. 153 * @param event a GShellEvent containing information from the GShell 154 */ 155 public void process(GShellEvent event) { 156 String line = event.getMessage().toLowerCase(); 157 // We first check if we can parse, which depends on num_docs > 0 and num_indexes > 0. 158 if(num_docs > 0 && num_indexes > 0) { 169 * @param queue a queue which at the moment should contain a single GShellEvent 170 */ 171 public void process(ArrayList queue) { 172 GShellEvent event = (GShellEvent) queue.get(0); 173 // Remove 'build.pl> ' bit 174 String line = event.getMessage(); 175 line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1); 176 line = line.trim(); 177 // We are only really interested in processing pseudo-XML tags 178 if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) { 179 // All events are vetoed 180 event.veto(); 181 182 // Create a new element from it 183 GShellElement element = new GShellElement(line); 184 // Now change states within the state machine as appropriate. A state change may subsequently incur a progress update. 185 String name = null; 186 String value = null; 159 187 switch(state) { 160 188 case BASE: 161 // We are watching for the beginning of a phase 162 if(line.indexOf(CTCT_STR) != -1) { 163 // No progress really. 164 state = CTCT; 165 ///ystem.err.println("CTCT [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 166 } 167 else if(line.indexOf(BI_STR) != -1) { 168 // Skip the progress up to this point. 169 progress_bar.setValue(progress_bar.getValue() + (MAX / (3 + num_indexes))); 170 state = BI; 171 ///ystem.err.println("BI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 172 } 173 else if(line.indexOf(CTID_STR) != -1) { 174 // Skip the progress up to this point 175 progress_bar.setValue(progress_bar.getValue() + (((1 + num_indexes ) * MAX) / (3 + num_indexes))); 176 state = CTID; 177 ///ystem.err.println("CTID [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 178 } 179 else if(line.startsWith(PHIND_STR)) { 189 // The only thing we would expect is a build message 190 name = element.getElementName(); 191 if(name.equals(BUILD_ELEMENT)) { 192 progress_bar.setIndeterminate(false); 193 state = BUILD; 194 // Produce a lower detail message if required 195 if(Gatherer.config.getMode() <= threshold) { 196 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildBegun1"), event.getStatus())); 197 } 198 } 199 else { 200 // Unknown command, go indeterminate 201 Gatherer.println("Unknown name: " + name); 202 progress_bar.setIndeterminate(true); 203 } 204 name = null; 205 break; 206 case BUILD: 207 // The only thing we would expect is a stage element 208 name = element.getElementName(); 209 if(name.equals(STAGE_ELEMENT)) { 210 progress_bar.setIndeterminate(false); 211 // Now we determine what stage we are moving to 212 value = element.getAttribute(NAME_ATTRIBUTE); 213 if(value.equals(COMPRESSTEXT_VALUE)) { 214 state = COMPRESSTEXT; 215 if(Gatherer.config.getMode() <= threshold) { 216 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.CompressText"), event.getStatus())); 217 } 218 } 219 else if(value.equals(INDEX_VALUE)) { 220 state = INDEX; 221 if(Gatherer.config.getMode() <= threshold) { 222 String args[] = new String[1]; 223 args[0] = element.getAttribute(SOURCE_ATTRIBUTE); 224 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Index", args), event.getStatus())); 225 args = null; 226 } 227 } 228 else if(value.equals(CREATEINFODATA_VALUE)) { 229 state = CREATEINFODATA; 230 if(Gatherer.config.getMode() <= threshold) { 231 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.InfoDatabase"), event.getStatus())); 232 } 233 } 234 else if(value.equals(PHIND_VALUE)) { 235 state = PHIND; 236 if(Gatherer.config.getMode() <= threshold) { 237 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Phind"), event.getStatus())); 238 } 239 } 240 else if(value.equals(CREATINGAUXILARY_VALUE)) { 241 state = CREATINGAUXILARY; 242 if(Gatherer.config.getMode() <= threshold) { 243 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Auxilary"), event.getStatus())); 244 } 245 } 246 else { 247 // Unknown command, go indeterminate 248 Gatherer.println("Unknown value: " + value); 249 progress_bar.setIndeterminate(true); 250 } 251 value = null; 252 } 253 // The build end message indicates a successfulish build. 254 else if(name.equals(BUILD_ELEMENT) && element.isClosed()) { 255 progress_bar.setIndeterminate(false); 256 progress_bar.setValue(MAX); 257 state = BASE; 258 if(Gatherer.config.getMode() <= threshold) { 259 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildComplete1"), event.getStatus())); 260 } 261 } 262 else { 263 // Unknown command, go indeterminate 264 Gatherer.println("Unknown name: " + name); 265 progress_bar.setIndeterminate(true); 266 } 267 name = null; 268 break; 269 case COMPRESSTEXT: 270 // We are either dealing with a phase, aa fatal error or an end stage 271 name = element.getElementName(); 272 if(name.equals(PHASE_ELEMENT)) { 273 // There are three phases within compressing text (or of four possible ones) 274 value = element.getAttribute(NAME_ATTRIBUTE); 275 if(value.equals(COLLECTTEXTSTATS_VALUE)) { 276 // Nothing to do 277 } 278 else if(value.equals(CREATINGCOMPRESS_VALUE) || value.equals(SKIPCREATINGCOMP_VALUE)) { 279 // One third complete 280 progress_bar.setIndeterminate(false); 281 progress_bar.setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages); 282 } 283 else if(value.equals(COMPRESSINGTEXT_VALUE)) { 284 // Two thirds complete 285 progress_bar.setIndeterminate(false); 286 progress_bar.setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages); 287 } 288 else { 289 // Unknown command, go indeterminate 290 Gatherer.println("Unknown value: " + value); 291 progress_bar.setIndeterminate(true); 292 } 293 value = null; 294 } 295 // 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. 296 else if(name.equals(FATALERROR_ELEMENT)) { 297 // On simplier modes produce a meaningful message 298 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.FatalError"), event.getStatus())); 299 } 300 else if(name.equals(STAGE_ELEMENT) && element.isClosed()) { 301 // Increase progress so that stage is complete. 302 current_stages++; 303 progress_bar.setIndeterminate(false); 304 progress_bar.setValue((current_stages * MAX) / expected_stages); 305 state = BUILD; 306 } 307 else { 308 // Unknown command, go indeterminate 309 Gatherer.println("Unknown name: " + name); 310 progress_bar.setIndeterminate(true); 311 } 312 name = null; 313 break; 314 case INDEX: 315 /** @todo - If on lower modes output a meaningful message. */ 316 name = element.getElementName(); 317 if(name.equals(PHASE_ELEMENT)) { 318 value = element.getAttribute(NAME_ATTRIBUTE); 319 if(value.equals(CREATINGINDEXDIC_VALUE)) { 320 // Nothing to do 321 } 322 else if(value.equals(INVERTINGTEXT_VALUE)) { 323 // One fifth complete 324 progress_bar.setIndeterminate(false); 325 progress_bar.setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages); 326 } 327 else if(value.equals(CREATETHEWEIGHTS_VALUE)) { 328 // Two fifths complete 329 progress_bar.setIndeterminate(false); 330 progress_bar.setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages); 331 } 332 else if(value.equals(CREATESTEMMEDDIC_VALUE)) { 333 // Three fifths complete 334 progress_bar.setIndeterminate(false); 335 progress_bar.setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages); 336 } 337 else if(value.equals(CREATINGSTEMINDX_VALUE)) { 338 // Four fifths complete 339 progress_bar.setIndeterminate(false); 340 progress_bar.setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages); 341 } 342 else { 343 // Unknown command, go indeterminate 344 Gatherer.println("Unknown value: " + value); 345 progress_bar.setIndeterminate(true); 346 } 347 value = null; 348 } 349 else if(name.equals(WARNING_ELEMENT)) { 350 /** @todo - If on lower modes output a meaningful message. */ 351 } 352 // 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. 353 else if(name.equals(FATALERROR_ELEMENT)) { 354 // On lower modes output a meaningful message. 180 355 181 356 } 182 else if(line.indexOf(CAF_STR) != -1) { 183 // Skip the progres up to this point 184 progress_bar.setValue(progress_bar.getValue() + (((2 + num_indexes ) * MAX) / (3 + num_indexes))); 185 state = CAF; 186 ///ystem.err.println("CAF [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 187 } 357 else if(name.equals(STAGE_ELEMENT) && element.isClosed()) { 358 // Increase progress so that stage is complete. 359 current_stages++; 360 progress_bar.setIndeterminate(false); 361 progress_bar.setValue((current_stages * MAX) / expected_stages); 362 state = BUILD; 363 } 364 else { 365 // Unknown command, go indeterminate 366 Gatherer.println("Unknown name: " + name); 367 progress_bar.setIndeterminate(true); 368 } 369 name = null; 188 370 break; 189 case CTCT: 190 if(line.indexOf(CTS_STR) != -1) { 191 // No progress really. 192 state = CTCT_CTS; 193 ///ystem.err.println("CTS [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 194 } 371 case PHIND: 372 name = element.getElementName(); 373 if(name.equals(PHASE_ELEMENT)) { 374 value = element.getAttribute(NAME_ATTRIBUTE); 375 if(value.equals(EXTRACTINGVOCAB_VALUE)) { 376 // Nothing to do 377 } 378 else if(value.equals(EXTRACTINGPHRASE_VALUE)) { 379 // One sixth complete 380 progress_bar.setIndeterminate(false); 381 progress_bar.setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages); 382 } 383 else if(value.equals(SORTANDRENUMBER_VALUE)) { 384 // Two sixths complete 385 progress_bar.setIndeterminate(false); 386 progress_bar.setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages); 387 } 388 else if(value.equals(PHRASEDATABASES_VALUE)) { 389 // Three sixths complete 390 progress_bar.setIndeterminate(false); 391 progress_bar.setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages); 392 } 393 else if(value.equals(WORDLEVELINDEXES_VALUE)) { 394 // Four sixths complete 395 progress_bar.setIndeterminate(false); 396 progress_bar.setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages); 397 } 398 else if(value.equals(DOCINFODATABASES_VALUE)) { 399 // Five sixths complete 400 progress_bar.setIndeterminate(false); 401 progress_bar.setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages); 402 } 403 else { 404 // Unknown command, go indeterminate 405 Gatherer.println("Unknown value: " + value); 406 progress_bar.setIndeterminate(true); 407 } 408 value = null; 409 } 410 else if(name.equals(STAGE_ELEMENT) && element.isClosed()) { 411 // Increase progress so that stage is complete. 412 current_stages++; 413 progress_bar.setIndeterminate(false); 414 progress_bar.setValue((current_stages * MAX) / expected_stages); 415 state = BUILD; 416 } 417 else { 418 // Unknown command, go indeterminate 419 Gatherer.println("Unknown name: " + name); 420 progress_bar.setIndeterminate(true); 421 } 422 name = null; 195 423 break; 196 case CTCT_CTS: 197 if(line.indexOf(PS_STR) != -1) { 198 // We have finally found something we can increment because of. 199 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 3 * num_docs))); 200 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 3 * num_docs))); 201 } 202 else if(line.indexOf(CTCD_STR) != -1) { 203 state = CTCT_CTCD; 204 ///ystem.err.println("CTCD [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 205 } 424 case CREATEINFODATA: 425 case CREATINGAUXILARY: 426 name = element.getElementName(); 427 if(name.equals(STAGE_ELEMENT) && element.isClosed()) { 428 // Another stage complete 429 current_stages++; 430 progress_bar.setIndeterminate(false); 431 progress_bar.setValue((current_stages * MAX) / expected_stages); 432 state = BUILD; 433 } 434 else { 435 // Unknown command, go indeterminate 436 Gatherer.println("Unknown name: " + name); 437 progress_bar.setIndeterminate(true); 438 } 439 name = null; 206 440 break; 207 case CTCT_CTCD: 208 if(line.indexOf(CTT_STR) != -1) { 209 // Finished creating the compression dictionary. 210 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 3))); 211 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 3))); 212 state = CTCT_CTT; 213 ///ystem.err.println("CTT [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 214 } 215 break; 216 case CTCT_CTT: 217 if(line.indexOf(PS_STR) != -1) { 218 // We have finally found something we can increment because of. 219 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 3 * num_docs))); 220 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 3 * num_docs))); 221 } 222 else if(line.indexOf(BI_STR) != -1) { 223 state = BI; 224 ///ystem.err.println("BI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 225 } 226 break; 227 case BI: 228 if(line.indexOf(CID_STR) != -1) { 229 state = BI_CID; 230 ///ystem.err.println("CID [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 231 } 232 break; 233 case BI_CID: 234 if(line.indexOf(PS_STR) != -1) { 235 // We have finally found something we can increment because of. 236 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5 * num_docs))); 237 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5 * num_docs))); 238 } 239 else if(line.indexOf(ITT_STR) != -1) { 240 state = BI_ITT; 241 ///ystem.err.println("ITT [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 242 } 243 break; 244 case BI_ITT: 245 if(line.indexOf(PS_STR) != -1) { 246 // We have finally found something we can increment because of. 247 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5 * num_docs))); 248 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5 * num_docs))); 249 } 250 else if(line.indexOf(CTWF_STR) != -1) { 251 state = BI_CTWF; 252 ///ystem.err.println("CTWF [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 253 } 254 break; 255 case BI_CTWF: 256 if(line.indexOf(CODSD_STR) != -1) { 257 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 258 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 259 state = BI_CODSD; 260 ///ystem.err.println("CODSD [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 261 } 262 break; 263 case BI_CODSD: 264 if(line.indexOf(CSI_STR) != -1) { 265 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 266 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 267 state = BI_CSI; 268 ///ystem.err.println("CSI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 269 } 270 break; 271 case BI_CSI: 272 if(line.indexOf(BI_STR) != -1) { 273 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 274 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 275 state = BI; 276 ///ystem.err.println("BI [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 277 } 278 else if(line.indexOf(CTID_STR) != -1) { 279 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * 5))); 280 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * 5))); 281 state = CTID; 282 ///ystem.err.println("CTID [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 283 } 284 break; 285 case CTID: 286 if(line.indexOf(PS_STR) != -1) { 287 // We have finally found something we can increment because of. 288 progress_bar.setValue(progress_bar.getValue() + (MAX / ((3 + num_indexes) * num_docs))); 289 ///ystem.err.println("Increase " + (MAX / ((3 + num_indexes) * num_docs))); 290 } 291 else if(line.indexOf(CAF_STR) != -1) { 292 state = CAF; 293 ///ystem.err.println("CAF [" + state + "] - " + ((progress_bar.getValue() * 100) / MAX) + "%"); 294 } 295 break; 296 case CAF: 297 progress_bar.setValue(MAX); 298 state = BASE; 299 ///ystem.err.println("Done! 100%"); 300 break; 441 default: 442 // Unknown command, go indeterminate 443 Gatherer.println("Unknown name: " + name); 444 progress_bar.setIndeterminate(true); 301 445 } 302 446 } 303 else { 304 ///ystem.err.println("Number of documents = " + num_docs); 305 ///ystem.err.println("Number of indexes = " + num_indexes); 306 progress_bar.setIndeterminate(true); 447 // 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 448 else if(Gatherer.config.getMode() <= threshold) { 449 event.veto(); 307 450 } 308 451 } 309 452 310 453 public void reset() { 454 current_stages = 0; 455 expected_stages = 0; 456 progress_bar.setIndeterminate(false); 457 progress_bar.setString(StaticStrings.SPACE_CHARACTER); 458 progress_bar.setValue(MIN); 311 459 state = BASE; 312 progress_bar.setValue(MIN);313 num_docs = -1;314 num_indexes = -1;315 460 stop = false; 316 progress_bar. setIndeterminate(false);461 progress_bar.updateUI(); 317 462 } 318 463 … … 331 476 */ 332 477 public void start() { 478 progress_bar.setValue(MIN); 479 expected_stages = 3; // Always compress text, create info database and auxiliary creation 480 // Retrieve cdm. 333 481 CollectionDesignManager cdm = Gatherer.c_man.getCollection().cdm; 334 progress_bar.setValue(MIN); 335 num_indexes = cdm.index_manager.getSize(); 336 int num_partitions = cdm.subcollectionindex_manager.getSize(); 337 if(num_partitions > 0) { 338 num_indexes = num_indexes * num_partitions; 482 // If we are using MGPP the number of indexes is always 1 483 if(cdm.searchtype_manager.isMGPPEnabled()) { 484 expected_stages = expected_stages + 1; 339 485 } 340 int num_languages = cdm.language_manager.getSize(); 341 if(num_languages > 0) { 342 num_indexes = num_indexes * num_languages; 486 else { 487 int num_indexes = cdm.index_manager.getSize(); 488 int num_partitions = cdm.subcollectionindex_manager.getSize(); 489 if(num_partitions > 0) { 490 num_indexes = num_indexes * num_partitions; 491 } 492 int num_languages = cdm.language_manager.getSize(); 493 if(num_languages > 0) { 494 num_indexes = num_indexes * num_languages; 495 } 496 expected_stages = expected_stages + num_indexes; 343 497 } 344 num_docs = import_progress.getNumberOfDocuments(); 498 // And if we have a phind classifier, we have one further index 499 if(cdm.classifier_manager.isPhindClassifierAssigned()) { 500 expected_stages = expected_stages + 1; 501 } 345 502 cdm = null; 346 503 } … … 350 507 public void stop() { 351 508 progress_bar.setIndeterminate(false); 352 progress_bar.setValue(MAX); // Not max, or else it won't blank properly for the next build.509 progress_bar.setValue(MAX); 353 510 } 354 511 } 512 -
trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java
r6325 r6388 38 38 39 39 import java.awt.Component; 40 import java.util.ArrayList; 40 41 import java.util.StringTokenizer; 41 42 import javax.swing.JProgressBar; 43 import org.greenstone.gatherer.Configuration; 42 44 import org.greenstone.gatherer.Dictionary; 43 45 import org.greenstone.gatherer.Gatherer; 46 import org.greenstone.gatherer.shell.GShellElement; 44 47 import org.greenstone.gatherer.shell.GShellProgressMonitor; 45 48 import org.greenstone.gatherer.util.StaticStrings; … … 65 68 /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */ 66 69 private int num_docs; 70 71 private int threshold = Configuration.SYSTEMS_MODE; 67 72 /** The progress bar this monitor updates. */ 68 73 private JProgressBar progress_bar; 69 74 /** */ 70 static final private String C = "c"; 75 static final private String BLOCKED_ATTRIBUTE = "blocked"; 76 static final private String CONSIDERED_ATTRIBUTE = "considered"; 77 static final private String IGNORED_ATTRIBUTE = "ignored"; 78 static final private String IMPORT_ELEMENT = "Import"; 79 static final private String PROCESSED_ATTRIBUTE = "processed"; 71 80 /** */ 72 static final private String N = "n";81 static final private String NAME_ATTRIBUTE = "n"; 73 82 /** */ 74 static final private String P = "p";83 static final private String PLUGIN_ATTRIBUTE = "p"; 75 84 /** The fixed portion of the progress bar used for the calculating of file size and other pre-import functions. */ 76 85 static final private int CALCULATION = 50000; … … 82 91 static final private int PROCESSED = 750000; 83 92 /** The element name of a file detected message. */ 84 static final private String FILE = "File";93 static final private String FILE_ELEMENT = "File"; 85 94 /** The element name of a file processing message. */ 86 static final private String FILE _PROCESSING= "Processing";95 static final private String FILEPROCESSING_ELEMENT = "Processing"; 87 96 /** The element name of an import complete message. */ 88 static final private String IMPORT _COMPLETE= "ImportComplete";97 static final private String IMPORTCOMPLETE_ELEMENT = "ImportComplete"; 89 98 90 99 public GImportProgressMonitor() { … … 93 102 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 94 103 progress_bar.setMinimum(MIN); 104 progress_bar.setString(StaticStrings.SPACE_CHARACTER); 95 105 progress_bar.setStringPainted(true); 96 progress_bar.setValue(MIN);106 setValue(MIN); 97 107 next_progress_value = CALCULATION; 98 108 } … … 105 115 progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED); 106 116 progress_bar.setMinimum(MIN); 107 progress_bar.setValue(MIN);117 setValue(MIN); 108 118 next_progress_value = CALCULATION; 109 119 } … … 145 155 // The current progress is calculated to be: 146 156 // The fixed calculation value plus the fixed processed value plus some portion of the fixed extracted value. This portion is the extracted_file_count over the total number of documents available. Note that this breaks badly for bibliographical files (for now). 147 progress_bar.setValue(CALCULATION + PROCESSED + ((EXTRACTED * extracted_file_count) / num_docs));157 setValue(CALCULATION + PROCESSED + ((EXTRACTED * extracted_file_count) / num_docs)); 148 158 } 149 159 150 160 /** This method is used to 'feed in' a line of text captured from the process. 151 * @param event the GShellEvent containing a message or other important shell information 152 */ 153 public void process(GShellEvent event) { 154 // We're into parsing output, so we don't need the 'calculating file size' etc string. 155 if(showing_string) { 156 progress_bar.setString(""); 157 showing_string = false; 158 } 161 * @param queue a queue which at the moment should contain a single GShellEvent 162 */ 163 public void process(ArrayList queue) { 164 // Retrieve the first event. 165 GShellEvent event = (GShellEvent) queue.get(0); 159 166 // Remove 'import.pl> ' bit 160 167 String line = event.getMessage(); 161 168 line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1); 162 169 line = line.trim(); 163 ///ystem.err.println("message = " + line);164 170 if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) { 165 line = line.substring(1, line.length() - 1); 171 // No original event is passed on, even in the lower modes 172 event.veto(); 173 // Create a new element from it 174 GShellElement element = new GShellElement(line); 175 String name = element.getElementName(); 166 176 // We may be reading a file. Remember we have to offset process as we recieve this message 'before' a document is processed. Hence the use of 'next_progress_value' 167 if(line.startsWith(FILE)) { 177 if(name.equals(IMPORT_ELEMENT)) { 178 // We're into parsing output, so we don't need the 'calculating file size' etc string. 179 if(showing_string) { 180 progress_bar.setString(""); 181 showing_string = false; 182 } 183 if(Gatherer.config.getMode() <= threshold) { 184 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportBegun1"), event.getStatus())); 185 } 186 } 187 else if(name.equals(FILE_ELEMENT)) { 168 188 file_count++; 169 ///ystem.err.println("File #" + file_count);170 189 // Set the next progress 171 progress_bar.setValue(next_progress_value); 190 if(next_progress_value > 0) { 191 setValue(next_progress_value); 192 } 172 193 // Now we calculate the next progress value 173 194 next_progress_value = CALCULATION + ((PROCESSED * file_count) / num_expected_docs); 195 event.veto(); // Unconditional veto 174 196 } 175 197 // Or we're being told what plugin is actually processing the file 176 else if( line.startsWith(FILE_PROCESSING)) {198 else if(name.equals(FILEPROCESSING_ELEMENT)) { 177 199 // If we are at lower mode settings fire a new 'dumbed down' event 178 /** @todo */ 200 if(Gatherer.config.getMode() <= threshold) { 201 String args[] = new String[2]; 202 args[0] = element.getAttribute(NAME_ATTRIBUTE); 203 args[1] = element.getAttribute(PLUGIN_ATTRIBUTE); 204 if(!args[1].equals("")) { 205 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.FileProcessing", args), event.getStatus())); 206 } 207 else { 208 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.FileNotProcessed", args), event.getStatus())); 209 } 210 args = null; 211 } 179 212 } 180 213 // Or the import complete element 181 else if( line.startsWith(IMPORT_COMPLETE)) {214 else if(name.equals(IMPORTCOMPLETE_ELEMENT)) { 182 215 // Set the next progress 183 progress_bar.setValue(next_progress_value); 184 // Determine the number of documents processed by using the 'p' attribute 185 StringTokenizer tokenizer = new StringTokenizer(line); 186 boolean found = false; 187 String token = tokenizer.nextToken(); // Drop the element name 188 while(tokenizer.hasMoreTokens() && !found) { 189 token = tokenizer.nextToken(); 190 if(token.startsWith(P)) { 191 found = true; 192 try { 193 String num_docs_string = token.substring(3, token.length() - 1); 194 num_docs = Integer.parseInt(num_docs_string); 195 } 196 catch(Exception exception) { 197 Gatherer.println("Exception in GImportProgressMonitor.process() - Expected"); 198 Gatherer.printStackTrace(exception); 199 } 200 } 201 } 202 tokenizer = null; 216 setValue(next_progress_value); 203 217 // If we are at lower mode settings fire a new 'dumbed down' event 204 /** @todo */ 205 } 206 207 208 // We also veto this event to prevent other classes handling it (we ensure progress monitors are called first). 218 if(Gatherer.config.getMode() <= threshold) { 219 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete1"), event.getStatus())); 220 String args[] = new String[1]; 221 args[0] = element.getAttribute(CONSIDERED_ATTRIBUTE); 222 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete2", args), event.getStatus())); 223 // The number of documents processed 224 String processed_str = element.getAttribute(PROCESSED_ATTRIBUTE); 225 if(!processed_str.equals(StaticStrings.ZERO_CHARACTER)) { 226 args = new String[3]; 227 args[0] = element.getAttribute(PROCESSED_ATTRIBUTE); 228 if(args[0].equals(StaticStrings.ONE_CHARACTER)) { 229 args[1] = Dictionary.get("GShell.Import.Was"); 230 args[2] = Dictionary.get("GShell.Import.Is"); 231 } 232 else { 233 args[1] = Dictionary.get("GShell.Import.Were"); 234 args[2] = Dictionary.get("GShell.Import.Are"); 235 } 236 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete.Processed", args), event.getStatus())); 237 } 238 // Try to set num docs 239 try { 240 num_docs = Integer.parseInt(processed_str); 241 } 242 catch(Exception exception) { 243 num_docs = 0; 244 } 245 processed_str = null; 246 // The number of documents blocked 247 String blocked_str = element.getAttribute(BLOCKED_ATTRIBUTE); 248 if(!blocked_str.equals(StaticStrings.ZERO_CHARACTER)) { 249 args = new String[2]; 250 args[0] = element.getAttribute(BLOCKED_ATTRIBUTE); 251 if(args[0].equals(StaticStrings.ONE_CHARACTER)) { 252 args[1] = Dictionary.get("GShell.Import.Was"); 253 } 254 else { 255 args[1] = Dictionary.get("GShell.Import.Were"); 256 } 257 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete.Blocked", args), event.getStatus())); 258 } 259 blocked_str = null; 260 // The number of documents ignored 261 String ignored_str = element.getAttribute(IGNORED_ATTRIBUTE); 262 if(!ignored_str.equals(StaticStrings.ZERO_CHARACTER)) { 263 args = new String[3]; 264 args[0] = element.getAttribute(IGNORED_ATTRIBUTE); 265 if(args[0].equals(StaticStrings.ONE_CHARACTER)) { 266 args[1] = Dictionary.get("GShell.Import.Was"); 267 args[2] = Dictionary.get("GShell.Import.Is"); 268 } 269 else { 270 args[1] = Dictionary.get("GShell.Import.Were"); 271 args[2] = Dictionary.get("GShell.Import.Are"); 272 } 273 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete.Ignored", args), event.getStatus())); 274 } 275 ignored_str = null; 276 args = null; 277 // Message is finally ready 278 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Import.ImportComplete3"), event.getStatus())); 279 } 280 } 281 else { 282 // Veto it 283 event.veto(); 284 } 285 } 286 else if(Gatherer.config.getMode() <= threshold) { 209 287 event.veto(); 210 288 } 289 } 290 291 public void reset() { 292 setValue(MIN); 293 progress_bar.setString(StaticStrings.SPACE_CHARACTER); 294 progress_bar.updateUI(); 211 295 } 212 296 … … 226 310 */ 227 311 public void start() { 312 setValue(MIN); 228 313 progress_bar.setString(Dictionary.get("FileActions.Calculating_Size")); 229 314 showing_string = true; … … 238 323 */ 239 324 public void stop() { 240 progress_bar.setValue(CALCULATION + PROCESSED + EXTRACTED); 325 setValue(CALCULATION + PROCESSED + EXTRACTED); 326 } 327 328 int previous_value = -1; 329 private void setValue(int value) { 330 progress_bar.setValue(value); 331 if(value != 0 && value < previous_value) { 332 Gatherer.println("Progress is decreasing! " + previous_value + " -> " + value); 333 } 334 previous_value = value; 241 335 } 242 336 } 337 -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r6325 r6388 38 38 39 39 import java.io.*; 40 import java.util.ArrayList; 40 41 import javax.swing.*; 41 42 import javax.swing.event.*; … … 331 332 public void fireMessage(int type, String message, int status, BufferedOutputStream bos) { 332 333 GShellEvent event = new GShellEvent(this, 0, type, message, status); 333 // If there is a progress monitor attached, pass the event to it first 334 // If there is a progress monitor attached, pass the event to it first. Note that we pass a queue of messages as the processing may cause one message to be split into several. 335 ArrayList message_queue = new ArrayList(); 336 message_queue.add(event); 334 337 if(progress != null) { 335 progress.process(event); 336 } 337 // If the event hasn't been vetoed, pass it on to other listeners 338 if(!event.isVetoed()) { 339 Object[] concerned = listeners.getListenerList(); 340 for(int i = 0; i < concerned.length ; i++) { 341 if(concerned[i] == GShellListener.class) { 342 ((GShellListener)concerned[i+1]).message(event); 343 } 344 } 345 concerned = null; 346 // And if we have a buffered output stream from error messages, send the message there 347 if(bos != null) { 348 try { 349 bos.write(message.getBytes(), 0, message.length()); 350 } 351 catch(Exception exception) { 352 Gatherer.println("Exception in GShell.fireMessage() - unexpected"); 353 Gatherer.printStackTrace(exception); 354 } 355 } 356 } 338 progress.process(message_queue); 339 } 340 for(int j = 0; j < message_queue.size(); j++) { 341 GShellEvent current_event = (GShellEvent) message_queue.get(j); 342 // If the event hasn't been vetoed, pass it on to other listeners 343 if(!current_event.isVetoed()) { 344 Object[] concerned = listeners.getListenerList(); 345 for(int i = 0; i < concerned.length ; i++) { 346 if(concerned[i] == GShellListener.class) { 347 ((GShellListener)concerned[i+1]).message(current_event); 348 } 349 } 350 concerned = null; 351 } 352 } 353 // And if we have a buffered output stream from error messages, send the message there 354 if(bos != null) { 355 try { 356 bos.write(message.getBytes(), 0, message.length()); 357 } 358 catch(Exception exception) { 359 Gatherer.println("Exception in GShell.fireMessage() - unexpected"); 360 Gatherer.printStackTrace(exception); 361 } 362 } 363 message_queue = null; 357 364 event = null; 358 365 } -
trunk/gli/src/org/greenstone/gatherer/shell/GShellEvent.java
r6325 r6388 102 102 } 103 103 104 /** Change the message to be displayed by this event - usually from something technical so something easier to understand. 105 * @param message the new message as a String 106 */ 107 public void setMessage(String message) { 108 this.message = message; 109 } 110 104 111 public String toString() { 105 112 return "org.greenstone.gatherer.shell.GShellEvent[" + message + "," + status + "," + type + "]"; -
trunk/gli/src/org/greenstone/gatherer/shell/GShellProgressMonitor.java
r6325 r6388 49 49 */ 50 50 import java.awt.Component; 51 import java.util.ArrayList; 51 52 import javax.swing.JProgressBar; 52 53 import org.greenstone.gatherer.shell.GShellEvent; … … 79 80 80 81 /** This method is used to 'feed in' a line of text captured from the process. 81 * @param event a GShellEvent containing information from the GShell82 * @param queue what will be used as a queue of events, but what, at the moment, should only have one event in it 82 83 */ 83 public void process(GShellEvent event); 84 public void process(ArrayList queue); 85 86 public void reset(); 84 87 85 88 public void saving();
Note:
See TracChangeset
for help on using the changeset viewer.