public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
//*-- create a thread to build the index and start it.
monitor.beginTask("Building Index.... please be patient...may take a while", 100);
BuildIndex buildIndex = new BuildIndex();
buildIndex.copyArgs(args);
buildIndex.start();
boolean done = false; long indexStart = new Date().getTime();
int currentBarVal = 0;
double avgTimePerDoc = 0.0; double prevAvgTimePerDoc = 0.0;
while (!done)
{
//*-- wait a second
done = true;
try { Thread.sleep(1000); } catch (InterruptedException e) { }
//*-- compute the bar increment for the initial scanning of index directories to build the task file
if (buildIndex.isScanning())
{ int numSeconds = buildIndex.getTimeScanning();
monitor.subTask("Scanning directories for files to index: " + numSeconds + " seconds elapsed.");
if ( monitor.isCanceled())
{ buildIndex.setRunning(false); done = true; monitor.done(); setJobRan(false); }
else done = false;
}
//*-- check the progress of the indexing task
else
{ int numFiles = buildIndex.getNumFiles(); int numFilesProcessed = buildIndex.getNumFilesProcessed();
int increment = ( (int) Math.floor(numFilesProcessed * 100.0) / (numFiles + 1) ) - currentBarVal;
monitor.worked(increment); currentBarVal += increment;
//*-- display a progress message
long elapsedTime = new Date().getTime() - indexStart;
avgTimePerDoc = ( elapsedTime / (numFilesProcessed + 1.0) ) + prevAvgTimePerDoc / 2.0;
long timeLeft = (long) ( avgTimePerDoc * (numFiles - numFilesProcessed) );
int percentDone = (int) Math.floor(numFilesProcessed * 100.0 / numFiles);
monitor.subTask( (percentDone < 100) ? "Finished indexing " + numFilesProcessed + " out of " + numFiles + " documents (" +
percentDone + "%). Time left: " + formatTime(timeLeft): "Cleaning up......" );
if (buildIndex.isRunning()) done = false;
if ( monitor.isCanceled())
{ buildIndex.setRunning(false); done = true; monitor.done(); setJobRan(false); }
prevAvgTimePerDoc = avgTimePerDoc;
} //*-- end of if
} //*-- end of while