Class BatchManager

java.lang.Object
com.groiss.wf.batch.BatchManager
All Implemented Interfaces:
TimerTask

public class BatchManager extends Object implements TimerTask
Starts and Completes BatchJobs. Provides methods for changing batch jobs.
  • Field Details

  • Constructor Details

    • BatchManager

      public BatchManager()
  • Method Details

    • run

      public void run(TimerEntry te, String args)
      the TimerTask interface
      Specified by:
      run in interface TimerTask
      Parameters:
      te - the persistent timer entry
      args - the argument string defined in the timer entry.
    • markJobRetry

      public static BatchJob markJobRetry(BatchJob bj, Throwable ex)
      Mark a created BatchJob as 'startretry'. Typically used in doStart() of the BatchAdapter, if the batch job has not (yet) been marked as 'startretry' and such a retry is desired.
      Runs in the same transaction as the caller. The exception does not have any special semantics for the system, it will be used to get a resultCode and a resultValue, if the BatchAdapter overrides BatchAdapter.getErrorCode(BatchJob, Throwable).
      The BatchManager (or the assigned executor) will try to start the job on its next run.
      Parameters:
      bj - the BatchJob to mark
      Returns:
      the changed BatchJob
    • markJobRetry

      public static BatchJob markJobRetry(BatchJob bj, int resultCode, String resultValue, Throwable ex)
      Mark a created BatchJob as 'startretry'. Typically used in doStart() of the BatchAdapter, if the batch job has not (yet) been marked as 'startretry' and such a retry is desired.
      Runs in the same transaction as the caller. The exception does not have any special semantics. Resultcode and resultvalue do not have any special semantics for the system.
      The BatchManager (or the assigned executor) will try to start the job on its next run.
      Parameters:
      bj - the BatchJob to mark
      resultCode - the result code to set on the batchjob
      resultValue - the result value to set on the batchJob
      Returns:
      the changed BatchJob
    • markJobError

      public static BatchJob markJobError(BatchJob bj, Exception ex)
      Mark a BatchJob as erroneous. Typically used in doStart() or doPoll(), to avoid further start attempts or polling attempts. The batch job will be placed in state BatchJob.STARTERROR or BatchJob.FINISHERROR.
      Runs in the same transaction as the caller. The exception does not have any special semantics, it will be used to get a resultCode and a resultValue, if the BatchAdapter overrides BatchAdapter.getErrorCode(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      Returns:
      the changed BatchJob
    • markJobError

      public static BatchJob markJobError(BatchJob bj, int resultCode, String resultValue, Exception ex)
      Mark a BatchJob as erroneous. Typically used in doStart() or doPoll(), to avoid further start attempts or polling attempts. The batch job will be placed in state BatchJob.STARTERROR or BatchJob.FINISHERROR.
      Runs in the same transaction as the caller. The exception does not have any special semantics, it will be used to get a resultCode and a resultValue, if the BatchAdapter overrides BatchAdapter.getErrorCode(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      resultCode - the result code to set on the batchjob
      resultValue - the result value to set on the batchJob
      Returns:
      the changed BatchJob
    • markJobSuspendRetry

      public static BatchJob markJobSuspendRetry(BatchJob bj, Exception ex)
      Mark a created BatchJob as suspended from further start attempts. Typically used in doStart() of the BatchAdapter, if the batch job has been marked as 'startretry' and such a retry is not desired anymore.
      Runs in the same transaction as the caller. The exception does not have any special semantics, it will be used to get a resultCode and a resultValue, if the BatchAdapter overrides BatchAdapter.getErrorCode(BatchJob, Throwable).
      The batch job will be in state BatchJob.CREATED afterwards. The BatchManager (or the assigned executor) will not try to start the job in subsequent runs.
      The start attempts can be resumed again by marking the batch job via markJobRetry(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      Returns:
      the changed BatchJob
    • markJobSuspendRetry

      public static BatchJob markJobSuspendRetry(BatchJob bj, int resultCode, String resultValue, Exception ex)
      Mark a created BatchJob as suspended from further start attempts. Typically used in doStart() of the BatchAdapter, if the batch job has been marked as 'startretry' and such a retry is not desired anymore.
      Runs in the same transaction as the caller. The exception does not have any special semantics. Resultcode and resultvalue do not have any special semantics for the system.
      The batch job will be in state BatchJob.CREATED afterwards. The BatchManager (or the assigned executor) will not try to start the job in subsequent runs.
      The start attempts can be resumed again by marking the batch job via markJobRetry(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      resultCode - the result code to set on the batchjob
      resultValue - the result value to set on the batchJob
      Returns:
      the changed BatchJob
    • markJobSuspendPoll

      public static BatchJob markJobSuspendPoll(BatchJob bj, Throwable ex)
      Mark a created BatchJob as suspended from further poll attempts. Typically used in doPoll() of the BatchAdapter, if the batch job has been marked as 'pollfinish' and such a polling is not desired anymore.
      Runs in the same transaction as the caller. The exception does not have any special semantics, it will be used to get a resultCode and a resultValue, if the BatchAdapter overrides BatchAdapter.getErrorCode(BatchJob, Throwable).
      The batch job will be in state BatchJob.STARTED afterwards. The BatchManager (or the assigned executor) will not try to poll for job completion in subsequent runs.
      The poll attempts can be resumed again by marking the batch job via markJobPoll(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      Returns:
      the changed BatchJob
    • markJobSuspendPoll

      public static BatchJob markJobSuspendPoll(BatchJob bj, int resultCode, String resultValue, Throwable ex)
      Mark a created BatchJob as suspended from further poll attempts. Typically used in doPoll() of the BatchAdapter, if the batch job has been marked as 'pollfinish' and such a polling is not desired anymore.
      Runs in the same transaction as the caller. The exception does not have any special semantics. Resultcode and resultvalue do not have any special semantics for the system.
      The batch job will be in state BatchJob.STARTED afterwards. The BatchManager (or the assigned executor) will not try to poll for job completion in subsequent runs.
      The poll attempts can be resumed again by marking the batch job via markJobPoll(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      resultCode - the result code to set on the batchjob
      resultValue - the result value to set on the batchJob
      Returns:
      the changed BatchJob
    • markJobPoll

      public static BatchJob markJobPoll(BatchJob bj, Throwable ex)
      Mark a started BatchJob as pollable. Typically used in doStart() of the BatchAdapter, if the batch job has been not been marked as 'pollfinish' and such a polling is desired.
      Runs in the same transaction as the caller. The exception does not have any special semantics, it will be used to get a resultCode and a resultValue, if the BatchAdapter overrides BatchAdapter.getErrorCode(BatchJob, Throwable).
      The BatchManager (or the assigned executor) will try to poll for job completion in subsequent runs.
      The poll attempts can be suspended again by marking the batch job via markJobSuspendPoll(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      Returns:
      the changed BatchJob
    • markJobPoll

      public static BatchJob markJobPoll(BatchJob bj, int resultCode, String resultValue, Throwable ex)
      Mark a started BatchJob as pollable. Typically used in doStart() of the BatchAdapter, if the batch job has been not been marked as 'pollfinish' and such a polling is desired.
      Runs in the same transaction as the caller. The exception does not have any special semantics. Resultcode and resultvalue do not have any special semantics for the system.
      The BatchManager (or the assigned executor) will try to poll for job completion in subsequent runs.
      The poll attempts can be suspended again by marking the batch job via markJobSuspendPoll(BatchJob, Throwable).
      Parameters:
      bj - the BatchJob to mark
      resultCode - the result code to set on the batchjob
      resultValue - the result value to set on the batchJob
      Returns:
      the changed BatchJob
    • markJobFinished

      public static BatchJob markJobFinished(BatchJob bj) throws Exception
      Mark a a started BatchJob as finished. Typically used from an external execution context or from doPoll() in the BatchAdapter. Runs in the same transaction as the caller. Neither resultcode nor result have any special semantics for the BatchManager. Their meaning must be interpreted properly by the corresponding BatchAdapter.
      The BatchManager will complete the job on its next run.
      Parameters:
      bj - the BatchJob to mark
      Returns:
      the changed BatchJob
      Throws:
      Exception - when the BatchJob is not in state BatchJob.STARTED.
    • markJobFinished

      public static BatchJob markJobFinished(BatchJob bj, int resultCode) throws Exception
      Mark a started BatchJob as finished. Typically used from an external execution context or from doPoll() in the BatchAdapter. Runs in the same transaction as the caller. Neither resultcode nor result have any special semantics for the BatchManager. Their meaning must be interpreted properly by the corresponding BatchAdapter.
      The BatchManager will complete the job on its next run.
      Parameters:
      bj - the BatchJob to mark
      resultCode - an int to indicate a result condition
      Returns:
      the changed BatchJob throws Exception when the BatchJob is not in state BatchJob.STARTED.
      Throws:
      Exception
    • markJobFinished

      public static BatchJob markJobFinished(BatchJob bj, int resultCode, String resultvalues) throws Exception
      Mark a started BatchJob as finished. Typically used from an external execution context or from doPoll() in the BatchAdapter. Runs in the same transaction as the caller. Neither resultcode nor result have any special semantics for the BatchManager. Their meaning must be interpreted properly by the corresponding BatchAdapter.
      The BatchManager will complete the job on its next run.
      Parameters:
      bj - the BatchJob to mark
      resultCode - an int to indicate a result condition
      resultvalues - a String to transport some results
      Returns:
      the changed BatchJob
      Throws:
      Exception - when the BatchJob is not in state BatchJob.STARTED.
    • markJobAborted

      public static BatchJob markJobAborted(BatchJob bj)
    • exceptionHandlingFinished

      @Deprecated(forRemoval=true, since="11.0") public static void exceptionHandlingFinished(String id)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Called when a process exception path is finished. For internal use only. Needed for compatibility reasons.
    • completeJob

      public static BatchJob completeJob(BatchJob bj) throws Exception
      Complete a started BatchJob. Marks the Job as finished and then completes the Job. Also finishes the originating StepInstance.
      Can be used to avoid the delay between marking a job as finished and the next run of the BatchManager. Issues BeanManager.commit() or BeanManager.rollback().
      During completion, BatchAdapter.beforeCompletion(BatchJob) and BatchAdapter.afterCompletion(BatchJob, boolean) will be called. After completeJob, BatchJob.getJobstate() can be used to inquire about the outcome of the operation.
      Parameters:
      bj - the BatchJob to complete.
      Returns:
      the changed BatchJob
      Throws:
      Exception - when the BatchJob is not in state BatchJob.STARTED.
    • completeJob

      public static BatchJob completeJob(BatchJob bj, int resultCode) throws Exception
      Complete a started BatchJob. Marks the Job as finished and then completes the Job. Also finishes the originating StepInstance.
      Can be used to avoid the delay between marking a job as finished and the next run of the BatchManager. Issues BeanManager.commit() or BeanManager.rollback().
      During completion, BatchAdapter.beforeCompletion(BatchJob) and BatchAdapter.afterCompletion(BatchJob, boolean) will be called. After completeJob, BatchJob.getJobstate() can be used to inquire about the outcome of the operation.
      Parameters:
      bj - the BatchJob to complete.
      resultCode - an int to indicate a result condition
      Returns:
      the changed BatchJob
      Throws:
      Exception - when the BatchJob is not in state BatchJob.STARTED.
    • completeJob

      public static BatchJob completeJob(BatchJob bj, int resultCode, String resultvalues) throws Exception
      Complete a started BatchJob. Marks the Job as finished and then completes the Job. Also finishes the originating StepInstance.
      Can be used to avoid the delay between marking a job as finished and the next run of the BatchManager. Issues BeanManager.commit() or BeanManager.rollback().
      During completion, BatchAdapter.beforeCompletion(BatchJob) and BatchAdapter.afterCompletion(BatchJob, boolean) will be called. After completeJob, BatchJob.getJobstate() can be used to inquire about the outcome of the operation.
      Parameters:
      bj - the BatchJob to complete.
      resultCode - an int to indicate a result condition
      resultvalues - a String to transport some results
      Returns:
      the changed BatchJob
      Throws:
      Exception - when the BatchJob is not in state BatchJob.STARTED.
    • getFreshBatchJob

      public static BatchJob getFreshBatchJob(BatchJob bj)
      Gets a current copy (a fresh incarnation) of the batch job from the database.

      Can be used to get the (possibly concurrently modified) current instance of the batch job.

      Parameters:
      bj - the batch job to get a fresh copy of
      Returns:
      the current copy of the batch job