Class JobStateMonitor

Object
JobStateMonitor

public class JobStateMonitor extends Object
Monitor execution-state of a job, and how long it is taking/took to execute.

The state refers to whether a job is unstarted, executed, completed etc.

It exists as a state-machine, where a job initially has an unstarted state.

Next, a call should occur to markAsExecuting() to indicate that the job has started executing.

Next, a call should occur to markAsCompleted(boolean) to indicate that the job has completed.

Author:
Owen Feehan
  • Constructor Details

    • JobStateMonitor

      public JobStateMonitor()
  • Method Details

    • isUnstarted

      public boolean isUnstarted()
      Is a job unstarted?
      Returns:
      true if a job has yet to be started, false otherwise.
    • isExecuting

      public boolean isExecuting()
      Is a job currently executing?
      Returns:
      true if a job is currently executing, false otherwise.
    • isCompleted

      public boolean isCompleted()
      Is a job completed?
      Returns:
      true if a job is currently completed, false otherwise.
    • isCompletedSuccessfully

      public boolean isCompletedSuccessfully()
      Has a job completed with a successful outcome?
      Returns:
      true if a job has completed successfully, false otherwise.
    • isCompletedFailure

      public boolean isCompletedFailure()
      Has a job completed with a failure?
      Returns:
      true if a job has completed with failure, false otherwise.
    • markAsExecuting

      public void markAsExecuting()
      Indicates that a job is currently executing.

      This method records the start-time of execution, later used to help infers the total duration of excution.

      Throws:
      OperationFailedRuntimeException - if called without the job being in an unstarted state.
    • markAsCompleted

      public void markAsCompleted(boolean successful)
      Indicates that a job has stopped executing, and has completed.

      This method records the end-time of execution, and infers the total duration of execution.

      Parameters:
      successful - whether the job completed successfully or not.
    • getExecutionDuration

      public int getExecutionDuration()
      How long the job took to execute in milliseconds.

      This method should only be called when the job is in a completed state.

      Returns:
      the duration of the job in milliseconds.
      Throws:
      OperationFailedRuntimeException - if called without the job being in a completed state.