Class JobExecutor

java.lang.Object
java.lang.Thread
ch.nolix.base.programcontrol.flowcontrol.JobExecutor
All Implemented Interfaces:
Runnable

public final class JobExecutor extends Thread
Author:
Silvan Wyss
  • Method Details

    • forStep

      public static JobExecutor forStep(Runnable step)
      Parameters:
      step -
      Returns:
      a new JobExecutor with the given step.
      Throws:
      RuntimeException - if the given step is null.
    • forStepAndMaxStepRunCount

      public static JobExecutor forStepAndMaxStepRunCount(Runnable step, int maxStepRunCount)
      Parameters:
      step -
      maxStepRunCount -
      Returns:
      a new JobExecutor with the given step and maxStepRunCount.
      Throws:
      RuntimeException - if the given step is null.
      RuntimeException - if the given maxStepRunCount is negative.
    • forStepAndMaxStepRunCountAndDelayBetweenStepRunsInMilliseconds

      public static JobExecutor forStepAndMaxStepRunCountAndDelayBetweenStepRunsInMilliseconds(Runnable step, int maxStepRunCount, int delayBetweenStepRunsInMilliseconds)
      Parameters:
      step -
      maxStepRunCount -
      delayBetweenStepRunsInMilliseconds -
      Returns:
      a new JobExecutor with the given step, maxStepRunCount and delayBetweenStepRunsInMilliseconds.
      Throws:
      RuntimeException - if the given step is null.
      RuntimeException - if the given maxStepRunCount is negative.
      RuntimeException - if the given delayBetweenStepRunsInMilliseconds is negative.
    • forStepAndMaxStepRunCountAndNextStepRunCondition

      public static JobExecutor forStepAndMaxStepRunCountAndNextStepRunCondition(Runnable step, int maxStepRunCount, BooleanSupplier nextStepRunCondition)
      Parameters:
      step -
      maxStepRunCount -
      nextStepRunCondition -
      Returns:
      a new JobExecutor with the given step, maxStepRunCount and nextStepRunCondition.
      Throws:
      RuntimeException - if the given step is null.
      RuntimeException - if the given maxStepRunCount is negative.
      RuntimeException - if the given nextStepRunCondition is null.
    • forStepAndMaxStepRunCountAndNextStepRunConditionAndDelayBetweenStepRunsInMilliseconds

      public static JobExecutor forStepAndMaxStepRunCountAndNextStepRunConditionAndDelayBetweenStepRunsInMilliseconds(Runnable step, int maxStepRunCount, BooleanSupplier nextStepRunCondition, int delayBetweenStepRunsInMilliseconds)
      Parameters:
      step -
      maxStepRunCount -
      nextStepRunCondition -
      delayBetweenStepRunsInMilliseconds -
      Returns:
      a new JobExecutor with the given step, maxStepRunCount, nextStepRunCondition and delayBetweenStepRunsInMilliseconds.
      Throws:
      RuntimeException - if the given job is null.
      RuntimeException - if the given maxRunCount is negative.
      RuntimeException - if the given condition is null.
      RuntimeException - if the given delayBetweenStepRunsInMilliseconds is negative.
    • forStepAndNextStepRunCondition

      public static JobExecutor forStepAndNextStepRunCondition(Runnable step, BooleanSupplier nextStepRunCondition)
      Parameters:
      step -
      nextStepRunCondition -
      Returns:
      a new JobExecutor with the given step and nextStepRunCondition.
      Throws:
      RuntimeException - if the given step is null.
      RuntimeException - if the given nextStepRunCondition is null.
    • forStepAndNextStepRunConditionAndDelayBetweenStepRunsInMilliseconds

      public static JobExecutor forStepAndNextStepRunConditionAndDelayBetweenStepRunsInMilliseconds(Runnable step, BooleanSupplier nextStepRunCondition, int delayBetweenStepRunsInMilliseconds)
      Parameters:
      step -
      nextStepRunCondition -
      delayBetweenStepRunsInMilliseconds -
      Returns:
      a new JobExecutor with the given step, nextStepRunCondition and delayBetweenStepRunsInMilliseconds.
      Throws:
      RuntimeException - if the given job is null.
      RuntimeException - if the given condition is null.
      RuntimeException - if the given delayBetweenStepRunsInMilliseconds is negative.
    • forJobs

      public static JobExecutor forJobs(IContainer<Runnable> jobs)
    • forJobs

      public static JobExecutor forJobs(Runnable... jobs)
    • caughtError

      public boolean caughtError()
      Returns:
      true if the current JobExecutor has caught an error, false otherwise.
    • getError

      public Throwable getError()
      Returns:
      the error of the current JobExecutor.
      Throws:
      ArgumentDoesNotHaveAttributeException - if the current JobExecutor does not have an error.
    • getFinishedStepRunCount

      public int getFinishedStepRunCount()
      Returns:
      the number of finished steps of the current JobExecutor.
    • hasCondition

      public boolean hasCondition()
      Returns:
      true if the current JobExecutor has a condition, false otherwise.
    • hasMaxRunCount

      public boolean hasMaxRunCount()
      Returns:
      true if the current JobExecutor has a max run count, false otherwise.
    • hasTimeInterval

      public boolean hasTimeInterval()
      Returns:
      true if the current JobExecutor has a time interval, false otherwise.
    • isFinished

      public boolean isFinished()
      Returns:
      true if the current JobExecutor is finished, false otherwise.
    • isFinishedSuccessfully

      public boolean isFinishedSuccessfully()
      Returns:
      true if the current JobExecutor is finished successfully, false otherwise.
    • isRunning

      public boolean isRunning()
      Returns:
      true if the current JobExecutor is running, false otherwise.
    • run

      public void run()
      Lets the current JobExecutor run.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread