|
||||||||||
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<String,Integer> |
currentPredictionMap
The timings loaded from where they were saved after the last run |
private String |
currentSectionName
Description of what we are doing |
private static int |
EXTRA_TIME
The amount of extra time if the predicted time was off and more time is needed. |
private Timer |
fakingTimer
The timer that lets us post fake progress events. |
private boolean |
finished
Have we just finished? |
private ProgressMode |
jobMode
The type of job being performed. |
private String |
jobName
A short descriptive phrase |
private List<WorkListener> |
listeners
People that want to know about "cancelable" changes |
private static org.slf4j.Logger |
log
The log stream |
private Map<String,Integer> |
nextPredictionMap
The timings as measured this time |
private int |
percent
The officially reported progress |
private URI |
predictionMapURI
The URI to which we load and save timings |
private static int |
REPORTING_INTERVAL
|
private long |
startTime
When did this job start? Measured in milliseconds since beginning of epoch. |
private int |
totalUnits
Total amount of work to do. |
private Thread |
workerThread
Optional thread to monitor progress |
private int |
workUnits
The amount of work done against the total. |
Fields inherited from interface org.crosswire.common.progress.Progress |
---|
UNKNOWN |
Constructor Summary | |
---|---|
protected |
Job(String jobName,
Thread worker)
Create a new Job. |
Method Summary | |
---|---|
void |
addWorkListener(WorkListener li)
Add a listener to the list |
void |
beginJob(String sectionName)
Start the task measured from 0 to 100. |
void |
beginJob(String sectionName,
int totalWork)
Start the task reporting progress toward total work. |
void |
beginJob(String sectionName,
URI predictURI)
Start the task using timings from a prior run as a guess for the current run. |
void |
cancel()
Cancel the job (if possible). |
void |
done()
Called to indicate that we are finished doing work. |
protected void |
fireStateChanged()
|
String |
getJobName()
|
ProgressMode |
getProgressMode()
Gets the current ProgressMode. |
String |
getSectionName()
The section name is used in reporting progress. |
int |
getTotalWork()
|
int |
getWork()
Return the computed percentage as an integer, typically from 0 to 100. |
int |
getWorkDone()
|
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. |
void |
incrementWorkDone(int step)
Indicate progress toward the whole. |
boolean |
isCancelable()
Might the job be cancelable? |
boolean |
isFinished()
Used to determine whether job is done or canceled or reached totalWork. |
private int |
loadPredictions()
Load the predictive timings if any |
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 |
setSectionName(String sectionName)
We have moved onto another section so update the section title. |
void |
setTotalWork(int totalWork)
Set the total amount of work to be done. |
void |
setWork(int work)
Indicate progress toward 100%. |
void |
setWorkDone(int work)
Indicate progress toward the whole. |
protected boolean |
updateProgress(long now)
Get estimated the percent progress |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int REPORTING_INTERVAL
private static final int EXTRA_TIME
private ProgressMode jobMode
private int totalUnits
private boolean cancelable
private boolean finished
private int workUnits
private int percent
private String jobName
private Thread workerThread
private String currentSectionName
private URI predictionMapURI
private Map<String,Integer> currentPredictionMap
private Map<String,Integer> nextPredictionMap
private long startTime
private Timer fakingTimer
private List<WorkListener> listeners
private static final org.slf4j.Logger log
Constructor Detail |
---|
protected Job(String jobName, Thread worker)
jobName
- Short description of this jobworker
- Optional thread to use in request to stop workerMethod Detail |
---|
public void beginJob(String sectionName)
Progress
beginJob
in interface Progress
sectionName
- the initial name of the job.public void beginJob(String sectionName, int totalWork)
Progress
beginJob
in interface Progress
sectionName
- the initial name of the job.totalWork
- the total amount that is to be worked.public void beginJob(String sectionName, URI predictURI)
Progress
beginJob
in interface Progress
sectionName
- the initial name of the job.predictURI
- the URI of a properties file from which past behavior is read
and the results of the current run are stored.public String getJobName()
getJobName
in interface Progress
public ProgressMode getProgressMode()
Progress
getProgressMode
in interface Progress
public int getTotalWork()
getTotalWork
in interface Progress
public void setTotalWork(int totalWork)
Progress
setTotalWork
in interface Progress
totalWork
- the total amount of work to be done in units that make sense
to the caller.public int getWork()
Progress
getWork
in interface Progress
public void setWork(int work)
Progress
setWork
in interface Progress
work
- a part of the whole.public int getWorkDone()
getWorkDone
in interface Progress
public void setWorkDone(int work)
Progress
setWorkDone
in interface Progress
work
- a part of the whole.public void incrementWorkDone(int step)
Progress
incrementWorkDone
in interface Progress
step
- the amount of work done since the last call.public String getSectionName()
Progress
getSectionName
in interface Progress
public void setSectionName(String sectionName)
Progress
setSectionName
in interface Progress
sectionName
- the name of the sectionpublic void done()
Progress
done
in interface Progress
public void cancel()
Progress
cancel
in interface Progress
public boolean isFinished()
Progress
isFinished
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 void addWorkListener(WorkListener li)
public void removeWorkListener(WorkListener li)
protected void fireStateChanged()
protected boolean updateProgress(long now)
private int loadPredictions()
private void savePredictions()
private void ignoreTimings()
|
Copyright ? 2003-2011 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |