org.crosswire.common.progress
Class Job

java.lang.Object
  extended by org.crosswire.common.progress.Job

public final class Job
extends Object

A Generic method of keeping track of Threads and monitoring their progress.

Author:
Joe Walker [joe at eireneh dot com]
See Also:
for license details. The copyright to this program is held by it's authors.

Nested Class Summary
private  class Job.PredictAction
          So we can fake progress for Jobs that don't tell us how they are doing
 
Field Summary
private  Map current
          The timings as measured this time
private  boolean finished
          Have we just finished?
private  int guessedpc
          The guessed progress
private  boolean interruptable
          Does this job allow interruptions?
private  String jobdesc
          A short descriptive phrase
private  PropertyChangeSupport listeners
          People that want to know about "interruptable" changes
private static Logger log
          The log stream
private  int percentend
          The percentage at the end of this section
private  Map predicted
          The timings loaded from where they were saved after the last run
private  int predictedlen
          How long to we predict this job is going to last?
private  URL predicturl
          The URL to which we load and save timings
private  int reportedpc
          The officially reported progress
private  long sectionend
          When do we expect this section to end
private  long sectionstart
          When did this section start?
private  long start
          When did this job start?
private  String statedesc
          Description of what we are doing
private  Timer updater
          The swing timer that lets us post fake progress events
private  Thread work
          Optional thread to monitor progress
 
Constructor Summary
protected Job(String description, URL predicturl, Thread work, boolean fakeupdates)
          Create a new Job.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener li)
          Interface for people to be notified of changes to the current Font.
 void done()
          Called to indicate that we are finished with the dialog
private  int getAgeFromMap(Map props, String message)
          Predict a percentage complete
 String getJobDescription()
          Get a short descriptive phrase
 int getPercent()
          Get estimated the percent progress, extrapolating between sections
 int getReportedPercent()
          Get the last reported total percent progress
 String getStateDescription()
          Accessor for the job description
protected  void guessProgress()
          Get estimated the percent progress, extrapolating between sections
 void ignoreTimings()
          Typically called from in a catch block, this ensures that we don't save the timing file because we have a messed up run.
 void interrupt()
          Interrupt the job (if possible)
 boolean isFinished()
          Shortcut to check if percent == 100
 boolean isInterruptable()
          Might the job be interruptable?
private  void loadPredictions()
          Load the predictive timings if any
private  void predictSection(String message)
          Predict a percentage complete
 void removePropertyChangeListener(PropertyChangeListener li)
          Interface for people to be notified of changes to the current Font.
private  void savePredictions()
          Save the known timings to a properties file.
 void setInterruptable(boolean newInterruptable)
           
 void setProgress(int percent, String statedesc)
          We have moved onto another section so update the percentage complete and the section title.
 void setProgress(String statedesc)
          We have moved onto another section so update the section title and if available used previous runs to predict timings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interruptable

private boolean interruptable
Does this job allow interruptions?


finished

private boolean finished
Have we just finished?


reportedpc

private int reportedpc
The officially reported progress


guessedpc

private int guessedpc
The guessed progress


sectionend

private long sectionend
When do we expect this section to end


sectionstart

private long sectionstart
When did this section start?


percentend

private int percentend
The percentage at the end of this section


jobdesc

private String jobdesc
A short descriptive phrase


work

private Thread work
Optional thread to monitor progress


statedesc

private String statedesc
Description of what we are doing


start

private long start
When did this job start?


current

private Map current
The timings as measured this time


predicted

private Map predicted
The timings loaded from where they were saved after the last run


predictedlen

private int predictedlen
How long to we predict this job is going to last?


predicturl

private URL predicturl
The URL to which we load and save timings


updater

private Timer updater
The swing timer that lets us post fake progress events


listeners

private PropertyChangeSupport listeners
People that want to know about "interruptable" changes


log

private static final Logger log
The log stream

Constructor Detail

Job

protected Job(String description,
              URL predicturl,
              Thread work,
              boolean fakeupdates)
Create a new Job. This will automatically fire a workProgressed event to all WorkListeners, with the percent property of this job set to 0.

Parameters:
description - Short description of this job
predicturl - Optional URL to save/load prediction times from
work - Optional thread to use in request to stop work
Method Detail

setProgress

public void setProgress(String statedesc)
We have moved onto another section so update the section title and if available used previous runs to predict timings.


setProgress

public void setProgress(int percent,
                        String statedesc)
We have moved onto another section so update the percentage complete and the section title.


done

public void done()
Called to indicate that we are finished with the dialog


ignoreTimings

public void ignoreTimings()
Typically called from in a catch block, this ensures that we don't save the timing file because we have a messed up run.


getStateDescription

public String getStateDescription()
Accessor for the job description


interrupt

public void interrupt()
Interrupt the job (if possible)


isInterruptable

public boolean isInterruptable()
Might the job be interruptable?


setInterruptable

public void setInterruptable(boolean newInterruptable)
Parameters:
newInterruptable - The interruptable to set.

isFinished

public boolean isFinished()
Shortcut to check if percent == 100


getPercent

public int getPercent()
Get estimated the percent progress, extrapolating between sections

Returns:
The estimated progress

getReportedPercent

public int getReportedPercent()
Get the last reported total percent progress

Returns:
The last reported progress

getJobDescription

public String getJobDescription()
Get a short descriptive phrase

Returns:
The description

getAgeFromMap

private int getAgeFromMap(Map props,
                          String message)
Predict a percentage complete


guessProgress

protected void guessProgress()
Get estimated the percent progress, extrapolating between sections


predictSection

private void predictSection(String message)
Predict a percentage complete


loadPredictions

private void loadPredictions()
Load the predictive timings if any


savePredictions

private void savePredictions()
Save the known timings to a properties file.


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener li)
Interface for people to be notified of changes to the current Font.

Parameters:
li - The new listener class

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener li)
Interface for people to be notified of changes to the current Font.

Parameters:
li - The listener class to be deleted

Copyright ยจ 2003-2005