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)
Progress
public void beginJob(String sectionName, int totalWork)
Progress
public void beginJob(String sectionName, URI predictURI)
Progress
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
public void setWork(int work)
Progress
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
public void cancel()
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)
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()