Interface BackgroundJobMonitor

  • All Known Implementing Classes:
    CompositeBackgroundJob.SubJobMonitor

    public interface BackgroundJobMonitor
    Used by 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
    • 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 the BackgroundJob by 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.

        The BackgroundJob should 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.

        The BackgroundJob can 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.

        The BackgroundJob can 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.