public final class Job extends Object implements Progress
The GNU Lesser General Public License for details.| Modifier and Type | Class and Description |
|---|---|
(package private) class |
Job.PredictTask
So we can fake progress for Jobs that don't tell us how they are doing
|
| Modifier and Type | Field and Description |
|---|---|
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.
|
CREATE_INDEX, DOWNLOAD_SEARCH_INDEX, INSTALL_BOOK, RELOAD_BOOK_LIST, UNKNOWN| Modifier | Constructor and Description |
|---|---|
protected |
Job(String jobID,
String jobName,
Thread worker)
Create a new Job.
|
| Modifier and Type | Method and Description |
|---|---|
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
|
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 long startTime
private Timer fakingTimer
private List<WorkListener> listeners
private static final org.slf4j.Logger log
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 workerpublic void beginJob(String sectionName)
Progresspublic void beginJob(String sectionName, int totalWork)
Progresspublic void beginJob(String sectionName, URI predictURI)
Progresspublic String getJobName()
getJobName in interface Progresspublic ProgressMode getProgressMode()
ProgressgetProgressMode in interface Progresspublic int getTotalWork()
getTotalWork in interface Progresspublic void setTotalWork(int totalWork)
ProgresssetTotalWork in interface ProgresstotalWork - the total amount of work to be done in units that make sense
to the caller.public int getWork()
Progresspublic void setWork(int work)
Progresspublic int getWorkDone()
getWorkDone in interface Progresspublic void setWorkDone(int work)
ProgresssetWorkDone in interface Progresswork - a part of the whole.public void incrementWorkDone(int step)
ProgressincrementWorkDone in interface Progressstep - the amount of work done since the last call.public String getSectionName()
ProgressgetSectionName in interface Progresspublic void setSectionName(String sectionName)
ProgresssetSectionName in interface ProgresssectionName - the name of the sectionpublic void done()
Progresspublic void cancel()
Progresspublic boolean isFinished()
ProgressisFinished in interface Progresspublic boolean isCancelable()
ProgressisCancelable in interface Progresspublic void setCancelable(boolean newInterruptable)
ProgresssetCancelable 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 progressprivate int loadPredictions()
private void savePredictions()
private void ignoreTimings()