|
||||||||||
| 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.
The GNU Lesser General Public License for details.| 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 String |
jobID
|
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 |
|---|
CREATE_INDEX, DOWNLOAD_SEARCH_INDEX, INSTALL_BOOK, RELOAD_BOOK_LIST, UNKNOWN |
| Constructor Summary | |
|---|---|
protected |
Job(String jobID,
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 |
getJobID()
The Job ID associated with this job |
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 final String jobID
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 jobID,
String jobName,
Thread worker)
jobID - the job identifierjobName - Short description of this jobworker - Optional thread to use in request to stop worker| Method Detail |
|---|
public void beginJob(String sectionName)
Progress
beginJob in interface ProgresssectionName - the initial name of the job.
public void beginJob(String sectionName,
int totalWork)
Progress
beginJob in interface ProgresssectionName - 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 ProgresssectionName - 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 Progresspublic ProgressMode getProgressMode()
Progress
getProgressMode in interface Progresspublic int getTotalWork()
getTotalWork in interface Progresspublic void setTotalWork(int totalWork)
Progress
setTotalWork in interface ProgresstotalWork - the total amount of work to be done in units that make sense
to the caller.public int getWork()
Progress
getWork in interface Progresspublic void setWork(int work)
Progress
setWork in interface Progresswork - a part of the whole.public int getWorkDone()
getWorkDone in interface Progresspublic void setWorkDone(int work)
Progress
setWorkDone in interface Progresswork - a part of the whole.public void incrementWorkDone(int step)
Progress
incrementWorkDone in interface Progressstep - the amount of work done since the last call.public String getSectionName()
Progress
getSectionName in interface Progresspublic void setSectionName(String sectionName)
Progress
setSectionName in interface ProgresssectionName - the name of the sectionpublic void done()
Progress
done in interface Progresspublic void cancel()
Progress
cancel in interface Progresspublic boolean isFinished()
Progress
isFinished in interface Progresspublic boolean isCancelable()
Progress
isCancelable in interface Progresspublic void setCancelable(boolean newInterruptable)
Progress
setCancelable in interface ProgressnewInterruptable - The state to set.public void addWorkListener(WorkListener li)
li - the interested listenerpublic void removeWorkListener(WorkListener li)
li - the disinterested listenerprotected void fireStateChanged()
protected boolean updateProgress(long now)
now - the current point in progress
private int loadPredictions()
private void savePredictions()
private void ignoreTimings()
public String getJobID()
getJobID in interface Progress
|
Copyright ยจ 2003-2015 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||