Interface BackgroundJobMonitor
- All Known Implementing Classes:
CompositeBackgroundJob.SubJobMonitor
public interface BackgroundJobMonitor
Used by
The scheduler creates an instance of this type exclusively for one particular job. It is not shared between jobs, and it is not reused.
BackgroundJob to communicate with the scheduler.
The BackgroundJobScheduler passes an instance of this type to
BackgroundJob.work(BackgroundJobMonitor), effectively providing the
job with a feedback channel to report progress information.
The BackgroundJob also should use this monitor for all logging and to
periodically poll for cancellation requests. The scheduler creates an instance of this type exclusively for one particular job. It is not shared between jobs, and it is not reused.
- Author:
- lukas
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidannounceTotal(int totalItems) Announce the total amount of work to be done.Get the identifier assigned to theBackgroundJobby the scheduler.booleanWhether the cancellation of the job was requested.voidlog(BackgroundJobMonitor.Severity severity, Object message) write to the (job-specific) log.voidreportProgressAbsolute(int items) Report units of work completed since the begining of the job.voidreportProgressIncrement(int items) Report units of work completed since the last progress report.
-
Method Details
-
log
write to the (job-specific) log.- Parameters:
severity-message-
-
isAborting
boolean isAborting()Whether the cancellation of the job was requested.
When true is returned, the scheduler has already tried set the interrupt flag on the thread executing the job.BackgroundJobs should poll this method in regular intervals and exit as quickly as possible if true is returned.- Returns:
- true, if the job should abort its execution.
-
getScheduledJobId
String getScheduledJobId()Get the identifier assigned to theBackgroundJobby the scheduler.
This ID uniquely identifies the job instance among all jobs managed by the scheduler. Since a single job instance is never executed more than once, it equivalently identifies that particular execution.- Returns:
- the id.
-
announceTotal
void announceTotal(int totalItems) Announce the total amount of work to be done.
TheBackgroundJobshould call this method at the beginning of its execution, as soon as it knows what lies ahead. It is ok to call this method multiple times with different values to update an initial assessment as new/more detailed information about the work to be done becomes available.- Parameters:
totalItems- the total units of work to be done.
-
reportProgressIncrement
void reportProgressIncrement(int items) Report units of work completed since the last progress report.
TheBackgroundJobcan use this method to report relative increments.- Parameters:
items- number of units of work completed since the last call.
-
reportProgressAbsolute
void reportProgressAbsolute(int items) Report units of work completed since the begining of the job.
TheBackgroundJobcan use this method to report the absolute amount of work that was tackled since the execution started.- Parameters:
items- number of units of work completed since execution started.
-