Class ConcurrentJobMonitor

Object
ConcurrentJobMonitor
All Implemented Interfaces:
Iterable<SubmittedJob>

public class ConcurrentJobMonitor extends Object implements Iterable<SubmittedJob>
Monitors all submitted jobs and their current state of execution.

It provides statistics and a textual description of the aggregate state of execution across all jobs.

Author:
Owen Feehan
  • Constructor Details

    • ConcurrentJobMonitor

      public ConcurrentJobMonitor(long totalNumberJobs)
      Creates a new ConcurrentJobMonitor instance.
      Parameters:
      totalNumberJobs - The total number of submitted jobs to be executed.
  • Method Details

    • add

      public void add(SubmittedJob job)
      Adds a job to be considered in the aggregate view.
      Parameters:
      job - the job.
    • currentStateDescription

      public String currentStateDescription()
      A human-understandable string describing the aggregate state.

      It features:

      • The number of completed jobs.
      • The number of executing jobs.
      • The number of jobs, that have not yet started executing (remaining to be executed).

      The string is shortened using abbreviations to help fit in a line of console outut.

      Returns:
      the string, as per above.
    • describeUncompletedJobs

      public Optional<String> describeUncompletedJobs(int fewerThanThreshold)
      A string that describes all jobs that are not tey completed, but only if there are fewer than a certain number.

      The string shows the number and a short-name for each job, and the number of seconds for which it is has been executing.

      The string shows the jobs on one long line, without using newlines.

      Parameters:
      fewerThanThreshold - a description is only shown if the total number of executing tasks is less than this threshold.
      Returns:
      a string in the form above if the condition is fulfilled, or otherwise Optional.empty().
    • numberUncompletedJobs

      public long numberUncompletedJobs()
      The number of jobs that remain uncompleted.
      Returns:
      the number of jobs.
    • numberCompletedJobs

      public long numberCompletedJobs()
      The number of jobs that have completed, regardless of failure state.

      This includes both jobs that have completed successfully and with failure.

      Returns:
      the number of jobs.
    • numberCompletedSuccessfullyJobs

      public long numberCompletedSuccessfullyJobs()
      The number of jobs that have completed in a state of success.
      Returns:
      the number of jobs.
    • numberCompletedFailureJobs

      public long numberCompletedFailureJobs()
      The number of jobs that have completed in a state of failure.
      Returns:
      the number of jobs.
    • numberExecutingJobs

      public long numberExecutingJobs()
      The number of jobs that are currently executing.
      Returns:
      the number of jobs.
    • deriveStatistics

      public TaskStatistics deriveStatistics()
      Derive statistics on the aggregate state of jobs.
      Returns:
      a newly created TaskStatistics capturing the state at the point it was executed.
    • iterator

      public Iterator<SubmittedJob> iterator()
      Specified by:
      iterator in interface Iterable<SubmittedJob>
    • getTotalNumberJobs

      public long getTotalNumberJobs()
      The total number of submitted jobs to be executed.