|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.common.progress.Job
public final class Job
A Generic method of keeping track of Threads and monitoring their progress.
for license details.
The copyright to this program is held by it's authors.
Nested Class Summary | |
---|---|
(package private) class |
Job.PredictTask
So we can fake progress for Jobs that don't tell us how they are doing |
Field Summary | |
---|---|
private boolean |
cancelable
Does this job allow interruptions? |
private Map |
current
The timings as measured this time |
private boolean |
finished
Have we just finished? |
private String |
jobName
A short descriptive phrase |
private List |
listeners
People that want to know about "cancelable" 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 |
predictedLength
How long to we predict this job is going to last? |
private URI |
predictURI
The URI to which we load and save timings |
private long |
sectionEnd
When do we expect this section to end |
private String |
sectionName
Description of what we are doing |
private long |
sectionStart
When did this section start? |
private long |
start
When did this job start? |
private int |
totalWork
Total amount of work to do. |
private Timer |
updater
The timer that lets us post fake progress events |
private int |
work
The officially reported progress |
private Thread |
workerThread
Optional thread to monitor progress |
Fields inherited from interface org.crosswire.common.progress.Progress |
---|
UNKNOWN |
Constructor Summary | |
---|---|
protected |
Job(String description,
URI predictURI,
Thread worker,
int totalWork)
Create a new Job. |
Method Summary | |
---|---|
void |
addWorkListener(WorkListener li)
Add a listener to the list |
void |
beginJob(String name,
int workToDo)
Start the task. |
void |
cancel()
Cancel the job (if possible). |
void |
done()
Called to indicate that we are finished doing work. |
protected void |
fireStateChanged()
|
private int |
getAgeFromMap(Map props,
String message)
Predict a percentage complete |
String |
getJobName()
|
String |
getSectionName()
We have moved onto another section so update the section title. |
int |
getTotalWork()
|
int |
getWork()
|
protected void |
guessProgress()
Get estimated the percent progress, extrapolating between sections |
private 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. |
boolean |
isCancelable()
Might the job be cancelable? |
boolean |
isFinished()
Used to determine whether job is done or cancelled or reached totalWork. |
private void |
loadPredictions()
Load the predictive timings if any |
private void |
predictSection(String message)
Predict a percentage complete |
void |
removeWorkListener(WorkListener li)
Remote a listener from the list |
private void |
savePredictions()
Save the known timings to a properties file. |
void |
setCancelable(boolean newInterruptable)
Indicates whether the job is cancelable or not. |
void |
setProgress(int work,
String statedesc)
We have moved onto another section so update the percentage complete and the section title. |
void |
setSectionName(String statedesc)
We have moved onto another section so update the section title. |
void |
setWork(int work)
Indicate progress toward the whole. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private int totalWork
private boolean cancelable
private boolean finished
private int work
private long sectionEnd
private long sectionStart
private int percentEnd
private String jobName
private Thread workerThread
private String sectionName
private long start
private Map current
private Map predicted
private int predictedLength
private URI predictURI
private Timer updater
private List listeners
private static final Logger log
Constructor Detail |
---|
protected Job(String description, URI predictURI, Thread worker, int totalWork)
description
- Short description of this jobpredictURI
- Optional URI to save/load prediction times fromworker
- Optional thread to use in request to stop workertotalWork
- the size of the work to doMethod Detail |
---|
public void beginJob(String name, int workToDo)
Progress
beginJob
in interface Progress
name
- the initial name of the job.workToDo
- the total amount that is to be worked. If UNKNOWN then the progress is to be guessed.public int getTotalWork()
getTotalWork
in interface Progress
public void setSectionName(String statedesc)
Progress
setSectionName
in interface Progress
statedesc
- the name of the sectionpublic void setWork(int work)
Progress
setWork
in interface Progress
work
- a part of the whole.public void setProgress(int work, String statedesc)
public void done()
Progress
done
in interface Progress
public String getSectionName()
Progress
getSectionName
in interface Progress
public void cancel()
Progress
cancel
in interface Progress
public boolean isCancelable()
Progress
isCancelable
in interface Progress
public void setCancelable(boolean newInterruptable)
Progress
setCancelable
in interface Progress
newInterruptable
- The state to set.public boolean isFinished()
Progress
isFinished
in interface Progress
public int getWork()
getWork
in interface Progress
public String getJobName()
getJobName
in interface Progress
private void ignoreTimings()
public void addWorkListener(WorkListener li)
public void removeWorkListener(WorkListener li)
protected void fireStateChanged()
private int getAgeFromMap(Map props, String message)
protected void guessProgress()
private void predictSection(String message)
private void loadPredictions()
private void savePredictions()
|
Copyright ยจ 2003-2007 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |