Interface BackgroundJobMonitor
-
- All Known Implementing Classes:
CompositeBackgroundJob.SubJobMonitor
public interface BackgroundJobMonitorUsed byBackgroundJobto communicate with the scheduler. TheBackgroundJobSchedulerpasses an instance of this type toBackgroundJob.work(BackgroundJobMonitor), effectively providing the job with a feedback channel to report progress information. TheBackgroundJobalso 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 Modifier and Type Interface Description static classBackgroundJobMonitor.Severity
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidannounceTotal(int totalItems)Announce the total amount of work to be done.java.lang.StringgetScheduledJobId()Get the identifier assigned to theBackgroundJobby the scheduler.booleanisAborting()Whether the cancellation of the job was requested.voidlog(BackgroundJobMonitor.Severity severity, java.lang.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 Detail
-
log
void log(BackgroundJobMonitor.Severity severity, java.lang.Object message)
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
java.lang.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.
-
-