Interface BatchAdapter
- All Known Implementing Classes:
NullAdapter
BatchAdapter
allows an instance to be notified by the BatchManager of execution events
of a BatchJob.-
Method Summary
Modifier and TypeMethodDescriptiondefault void
afterCompletion
(BatchJob job, boolean commit) The afterCompletion method notifies a BatchAdapter that a batchjob has completed.default void
afterCreation
(BatchJob job) The afterCreation method notifies a batch adapter that a batchjob has been created.default void
beforeCompletion
(BatchJob job) The beforeCompletion method notifies a BatchAdapter that a BatchJob is about to complete.default void
doCompensate
(BatchJob job) Will be called when a GoBack() action on the process is being performed and the goBack path crosses the corresponding batch step.default void
The doPoll method is being used by the executing (timer) thread to determine if a batchjob has been finished.void
The doStart Method is responsible for starting the batch job.getErrorCode
(BatchJob bj, Throwable ex) Can be used to map exceptions to error codes.default void
Will be called when a batch step is aborted.default void
onReactivate
(BatchJob bj) Will be called when a step for an aborted batch job is reactivated via process reactivation.default void
startup()
Startup is called when the adapter is instantiated by the BatchManager.
-
Method Details
-
startup
Startup is called when the adapter is instantiated by the BatchManager. It can be used to setup the execution context for the BatchJobs.- Throws:
Exception
-
afterCreation
The afterCreation method notifies a batch adapter that a batchjob has been created.This usually happens via a
Batchmanager.submitJob()
call. It can be used to collect parameters from the process context. If it makes any changes to thejob
,job.update()
must be called.It is typically executed from a preprocessing method of a
Task
and is expected to complete quickly.If an Exception is thrown by afterCreation, this exception is not catched and will manifest in the context of the caller (usually a preprocessing method).
- Parameters:
job
- a BatchJob- Throws:
Exception
-
doStart
The doStart Method is responsible for starting the batch job.It has to start the batch job in some external execution context. If it runs in the JVM itself, it is expected to complete quickly. The method is executed via the Batch Timer for each BatchJob, which is in state BatchJob.CREATED and whose starttime is either null or not in the future.
If an exception is thrown by doStart, the behaviour depends on whether retrystart is specified for the job or not. Jobs without retrystart are placed in state BatchJob.STARTERROR and a ROLLBACK is done! No further action is carried out by the system with this BatchJob. So either doStart itself has to take appropriate actions, or an administrator must check for jobs in this state manually.
Jobs with retrystart remain in state created and a new start attempt will be made in the future.
doStart can make use of one of the methods BatchManager.markJobError(), BatchManager.markJobFinished() and BatchManager.markSuspendRetry() to mark the job as being erroneous, as being finished or to suspend further start attempts.
- Parameters:
job
- a BatchJob- Throws:
Exception
-
doPoll
The doPoll method is being used by the executing (timer) thread to determine if a batchjob has been finished. It will be called periodically by the executing timer if the Batchjob has pollfinish set.If doPoll returns or throws an exception, the state of the job remains unchanged. doPoll can make use of one of the methods BatchManager.markJobError(), BatchManager.markJobFinished() and BatchManager.markJobSuspendPoll() to mark the job as being erroneous, as being finished or to suspend further poll attempts.
- Parameters:
job
- a BatchJob- Throws:
Exception
-
beforeCompletion
The beforeCompletion method notifies a BatchAdapter that a BatchJob is about to complete. This method is called before the Task in which the BatchJob originated is finished;- either by the BatchManager (for each BatchJob with jobstate
BatchJob.FINISHED
), - or via explicit call to
BatchManager.completeJob(BatchJob)
for a BatchJob with jobstateBatchJob.STARTED
The method can be used to transfer results from the execution context of the finished jobs to the process context.
If an exception is thrown by beforeCompletion, the BatchManager places the job in state BatchJob.FINISHERROR. No further action is carried out by the system with this BatchJob. So either beforeCompletion itself takes appropriate actions, or handling is done in afterCompletion, or an administrator must check for jobs in this state manually.
- Parameters:
job
- a BatchJob- Throws:
Exception
- either by the BatchManager (for each BatchJob with jobstate
-
afterCompletion
The afterCompletion method notifies a BatchAdapter that a batchjob has completed. It also tells the adapter whether the completion was successful or not. If an exception occurs, a ROLLBACK is done!- Parameters:
job
- a BatchJobcommit
- True if the job has been completed, false if there were errors.- Throws:
Exception
-
doCompensate
Will be called when a GoBack() action on the process is being performed and the goBack path crosses the corresponding batch step.- Parameters:
job
- a BatchJob- Throws:
Exception
-
getErrorCode
Can be used to map exceptions to error codes.- Parameters:
bj
- the batchjobex
- the exception- Returns:
- a pair of an Integer and a String. The Integer will be the result code of the BatchJob and the String will be its result value. The default implementation returns null (which will be interpreted as Pair(0,null)).
-
onAbort
Will be called when a batch step is aborted. Either from the admin gui or via process abort. Is only called when the process batch job is in a non error state. The current state of the batch job is still available. Afterwards the state will be set to BatchJob.ABORTED.- Parameters:
bj
- the batchjob- Throws:
Exception
-
onReactivate
Will be called when a step for an aborted batch job is reactivated via process reactivation.- Parameters:
bj
- the batchjob- Throws:
Exception
-