public class DefaultBatchEngine extends BaseBatchProcessingListenerOwner implements BatchEngine, org.mule.runtime.core.api.context.MuleContextAware, org.mule.runtime.api.lifecycle.Initialisable, org.mule.runtime.api.lifecycle.Stoppable, org.mule.runtime.api.lifecycle.Startable
BatchEngine| Constructor and Description |
|---|
DefaultBatchEngine() |
| Modifier and Type | Method and Description |
|---|---|
static String |
buildExceptionLogMessage(Throwable t)
Attempts top get meaningful information from an exception and build a message from it.
|
void |
cancel(BatchJobInstanceAdapter jobInstance)
Stops the jobInstance if it's executing (by delegating into
BatchEngine.stopExecution(BatchJobInstanceAdapter, boolean). |
void |
cancelAllRunningInstance()
Invokes
BatchEngine.cancel(BatchJobInstanceAdapter) on every running instance of any job |
org.mule.runtime.core.api.event.CoreEvent.Builder |
createEventBuilder(Record record,
BatchJobInstanceAdapter jobInstance)
Creates a new
CoreEvent.Builder with the base attributes set for a CoreEvent to process the given record for the given
jobInstance. |
org.mule.runtime.core.api.event.CoreEvent.Builder |
createEventBuilder(Record record,
BatchJobInstanceAdapter jobInstance,
CompletableFuture<Void> externalCompletion)
Creates a new
CoreEvent.Builder with the base attributes set for a CoreEvent to process the given record for the given
jobInstance. |
BatchJobInstanceAdapter |
createNewJobInstance(BatchJobAdapter job,
org.mule.runtime.core.api.event.CoreEvent event)
Creates and initialises a new
BatchJobInstanceAdapter related to the given job. |
BatchTransactionContext |
createTransactionContext(BatchJobInstanceAdapter jobInstance)
Creates a new BatchTransactionContext referencing the given {@link BatchJobInstanceAdapter}
|
BatchJobInstanceAdapter |
finishExecution(BatchJobInstanceAdapter jobInstance,
boolean shouldRefresh)
Finishes execution of the
BatchJobInstanceAdapter in a successful way and makes it no longer eligible for execution
by the steps. |
Collection<BatchJob> |
getBatchJobs()
Returns all defined
BatchJobs |
BatchQueueManager |
getBatchQueueManager()
Returns the
BatchQueueManager in which queueing operations are
delegated |
BatchTransactionContextFactory |
getBatchTransactionContextFactory()
For monitoring and testing purposes only
|
List<Record> |
getBlockFrom(BatchTransactionContext context)
Returns the records in the stepping queue which corresponds to the
BatchJobInstance referenced by the given
context |
int |
getBlockSize(com.mulesoft.mule.runtime.module.batch.api.BatchJobInstance jobInstance)
|
Optional<BatchJob> |
getJob(String jobName) |
BatchJobAdapter |
getJobFor(com.mulesoft.mule.runtime.module.batch.api.BatchJobInstance jobInstance)
Returns the owning
BatchJobAdapter for the given BatchJobInstance |
BatchJobInstanceStore |
getJobInstanceStore()
Returns the
BatchJobInstanceStore in which persistence operations are delegated on |
Lock |
getLock(BatchJobInstanceAdapter jobInstance)
Obtains a
Lock for the given jobInstance. |
long |
getSteppingQueueSize(BatchTransactionContext context)
Returns the amount of records in the stepping queue which corresponds to the
BatchJobInstance referenced by the given
context |
void |
initialise() |
BatchJobInstanceAdapter |
load(BatchJobInstanceAdapter jobInstance,
org.mule.runtime.core.api.event.CoreEvent event)
Splits the
CoreEvent payload and loads it into the BatchJobInstanceAdapter queue. |
void |
registerBatchJob(BatchJobAdapter batchJob) |
void |
releaseResources(BatchJobInstanceAdapter jobInstance,
boolean includeFailedRecords)
Releases the resources still allocated to the given
BatchJobInstanceAdapter, including queues and storage |
void |
resumeExecution(BatchJobInstanceAdapter jobInstance)
Resumes execution of a
BatchJobInstance which was stopped through the
BatchEngine.stopExecution(BatchJobInstanceAdapter, boolean) method. |
void |
setBatchQueueManager(BatchQueueManager batchQueueManager) |
void |
setHistoryExpirationFrequency(long historyExpirationFrequency) |
void |
setJobInstanceStore(BatchJobInstanceStore jobInstanceFactory) |
void |
setMuleContext(org.mule.runtime.core.api.MuleContext context) |
void |
start() |
void |
startExecution(BatchJobInstanceAdapter jobInstance)
Starts asynchronous execution of the given
BatchJobInstanceAdapter. |
void |
stop() |
void |
stopExecution(BatchJobInstanceAdapter jobInstanceAdapter,
boolean markAsFailed)
Stops the execution of the given
BatchJobInstanceAdapter. |
BatchJobInstanceAdapter |
updateStatisticsAndRoute(BatchTransactionContext ctx,
List<Record> records) |
addBatchProcessingListener, addBatchProcessingListener, getListeners, removeBatchProcessingListener, removeBatchProcessingListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddBatchProcessingListener, addBatchProcessingListener, removeBatchProcessingListener, removeBatchProcessingListenerpublic void initialise()
throws org.mule.runtime.api.lifecycle.InitialisationException
initialise in interface org.mule.runtime.api.lifecycle.Initialisableorg.mule.runtime.api.lifecycle.InitialisationExceptionpublic void stop()
throws org.mule.runtime.api.exception.MuleException
stop in interface org.mule.runtime.api.lifecycle.Stoppableorg.mule.runtime.api.exception.MuleExceptionpublic BatchJobInstanceAdapter createNewJobInstance(BatchJobAdapter job, org.mule.runtime.core.api.event.CoreEvent event) throws org.mule.runtime.api.exception.MuleException
BatchJobInstanceAdapter related to the given job. The returned instance will be already
persistedcreateNewJobInstance in interface BatchEnginejob - the BatchJobAdapter being executedevent - the CoreEvent that triggered the job's executionBatchJobInstanceAdapterorg.mule.runtime.api.exception.MuleExceptionpublic BatchTransactionContext createTransactionContext(BatchJobInstanceAdapter jobInstance)
createTransactionContext in interface BatchEnginejobInstance - a not null BatchJobInstanceAdapterBatchTransactionContextpublic BatchJobInstanceAdapter load(BatchJobInstanceAdapter jobInstance, org.mule.runtime.core.api.event.CoreEvent event) throws org.mule.runtime.api.exception.MuleException
CoreEvent payload and loads it into the BatchJobInstanceAdapter queue. If this process fails, the
job instance's resources are released.load in interface BatchEnginejobInstance - a BatchJobInstanceAdapterevent - a CoreEvent which payload is splittableBatchJobInstanceAdapter which state has been updated to reflect this operation's resultorg.mule.runtime.api.exception.MuleExceptionpublic void startExecution(BatchJobInstanceAdapter jobInstance) throws org.mule.runtime.api.exception.MuleException
BatchJobInstanceAdapter. The instance will be persisted at this point and
will become elegible for execution by the steps. It also fires a BatchNotification.JOB_PROCESS_RECORDS_BEGIN
notificationstartExecution in interface BatchEnginejobInstance - the BatchJobInstanceAdapter to be executedorg.mule.runtime.api.exception.MuleExceptionpublic BatchJobInstanceAdapter finishExecution(BatchJobInstanceAdapter jobInstance, boolean shouldRefresh) throws org.mule.runtime.api.exception.MuleException
BatchJobInstanceAdapter in a successful way and makes it no longer eligible for execution
by the steps. If the owning BatchJob has an onComplete phase then it's executed. Resources associated to the
jobInstance are released by invoking BatchEngine.releaseResources(BatchJobInstanceAdapter, boolean). Finally, it
fires a BatchNotification.JOB_SUCCESSFULfinishExecution in interface BatchEnginejobInstance - an instance ofBatchJobInstanceAdapter}shouldRefresh - if true then the jobInstance is refreshed before actually performing the logicjobInstance, refreshed if shouldRefresh was trueorg.mule.runtime.api.exception.MuleExceptionpublic void releaseResources(BatchJobInstanceAdapter jobInstance, boolean includeFailedRecords)
BatchJobInstanceAdapter, including queues and storagereleaseResources in interface BatchEnginejobInstance - a BatchJobInstanceAdapterincludeFailedRecords - if true, the stored failed records will also be wiped out.public org.mule.runtime.core.api.event.CoreEvent.Builder createEventBuilder(Record record, BatchJobInstanceAdapter jobInstance)
CoreEvent.Builder with the base attributes set for a CoreEvent to process the given record for the given
jobInstance. This method will create a copy of the original event that generated the jobInstance, will set the record's
payload as the message payload and will put the record in an invocation property under the key in
BatchProperties.RECORD_VARIABLE_NAMEcreateEventBuilder in interface BatchEnginerecord - an instance of RecordjobInstance - an instance of BatchJobInstanceAdapterCoreEvent.Builderpublic org.mule.runtime.core.api.event.CoreEvent.Builder createEventBuilder(Record record, BatchJobInstanceAdapter jobInstance, CompletableFuture<Void> externalCompletion)
CoreEvent.Builder with the base attributes set for a CoreEvent to process the given record for the given
jobInstance. This method will create a copy of the original event that generated the jobInstance, will set the record's
payload as the message payload and will put the record in an invocation property under the key in
BatchProperties.RECORD_VARIABLE_NAMEcreateEventBuilder in interface BatchEnginerecord - an instance of RecordjobInstance - an instance of BatchJobInstanceAdapterexternalCompletion - A custom completion callback for the event context. If null, then default completion will
be usedCoreEvent.Builderpublic void stopExecution(BatchJobInstanceAdapter jobInstanceAdapter, boolean markAsFailed) throws org.mule.runtime.api.exception.MuleException
BatchJobInstanceAdapter. This doesn't mean that all threads processing records will
immediately stop. It means that no more records will be taken out of the queue and start processing. All records currently
being processed will complete their normal execution. if markAsFailed is true the jobInstance status will be set
to BatchJobInstanceStatus.FAILED_PROCESS_RECORDS and a BatchNotification.JOB_PROCESS_RECORDS_FAILED
notification will be fired. Otherwise, the status will be set to BatchJobInstanceStatus.STOPPED and a
BatchNotification.JOB_STOPPED notification is fired instead.stopExecution in interface BatchEnginejobInstanceAdapter - a BatchJobInstanceAdaptermarkAsFailed - if true the jobInstance status will be set to
BatchJobInstanceStatus.FAILED_PROCESS_RECORDS. Otherwise it will be set to
BatchNotification.JOB_STOPPEDorg.mule.runtime.api.exception.MuleExceptionpublic void resumeExecution(BatchJobInstanceAdapter jobInstance) throws org.mule.runtime.api.exception.MuleException
BatchJobInstance which was stopped through the
BatchEngine.stopExecution(BatchJobInstanceAdapter, boolean) method.
Execution is resumed by setting the job instance status back to BatchJobInstanceStatus.EXECUTING. The
BatchNotification.JOB_PROCESS_RECORDS_BEGIN notification will be fired again.resumeExecution in interface BatchEnginejobInstance - the BatchJobInstanceAdapter to be resmedorg.mule.runtime.api.exception.MuleException - in case of unhandled errorpublic void cancel(BatchJobInstanceAdapter jobInstance) throws org.mule.runtime.api.exception.MuleException
BatchEngine.stopExecution(BatchJobInstanceAdapter, boolean). Finally, the instance's resources are released (by
delegating into BatchEngine.releaseResources(BatchJobInstanceAdapter, boolean) and a
BatchNotification.JOB_CANCELLED notification is firedcancel in interface BatchEnginejobInstance - a BatchJobInstanceAdapterorg.mule.runtime.api.exception.MuleExceptionpublic void cancelAllRunningInstance()
throws org.mule.runtime.api.exception.MuleException
BatchEngine.cancel(BatchJobInstanceAdapter) on every running instance of any jobcancelAllRunningInstance in interface BatchEngineorg.mule.runtime.api.exception.MuleExceptionpublic long getSteppingQueueSize(BatchTransactionContext context)
BatchEngineBatchJobInstance referenced by the given
contextgetSteppingQueueSize in interface BatchEnginecontext - the context for a current transactionpublic List<Record> getBlockFrom(BatchTransactionContext context)
BatchEngineBatchJobInstance referenced by the given
contextgetBlockFrom in interface BatchEnginecontext - the context for a current transactionpublic BatchJobInstanceAdapter updateStatisticsAndRoute(BatchTransactionContext ctx, List<Record> records) throws org.mule.runtime.api.exception.MuleException
updateStatisticsAndRoute in interface BatchEngineorg.mule.runtime.api.exception.MuleExceptionpublic Lock getLock(BatchJobInstanceAdapter jobInstance)
Lock for the given jobInstance. Invoking this method with difference instances which share the same
id, will always return the same lockgetLock in interface BatchEnginejobInstance - a BatchJobInstanceAdapterLockpublic BatchJobAdapter getJobFor(com.mulesoft.mule.runtime.module.batch.api.BatchJobInstance jobInstance)
BatchJobAdapter for the given BatchJobInstancegetJobFor in interface BatchEnginejobInstance - a BatchJobInstanceBatchJobAdapterpublic void registerBatchJob(BatchJobAdapter batchJob)
registerBatchJob in interface BatchEnginepublic Collection<BatchJob> getBatchJobs()
BatchJobsgetBatchJobs in interface BatchEngineCollection of BatchJob. The collection might be empty but will never be nullpublic Optional<BatchJob> getJob(String jobName)
getJob in interface BatchEnginepublic BatchJobInstanceStore getJobInstanceStore()
BatchJobInstanceStore in which persistence operations are delegated ongetJobInstanceStore in interface BatchEngineBatchJobInstancepublic void setJobInstanceStore(BatchJobInstanceStore jobInstanceFactory)
public BatchQueueManager getBatchQueueManager()
BatchQueueManager in which queueing operations are
delegatedgetBatchQueueManager in interface BatchEngineBatchQueueManagerpublic void setBatchQueueManager(BatchQueueManager batchQueueManager)
public void setMuleContext(org.mule.runtime.core.api.MuleContext context)
setMuleContext in interface org.mule.runtime.core.api.context.MuleContextAwarepublic int getBlockSize(com.mulesoft.mule.runtime.module.batch.api.BatchJobInstance jobInstance)
getBlockSize in interface BatchEnginejobInstance - a BatchJobInstancepublic BatchTransactionContextFactory getBatchTransactionContextFactory()
getBatchTransactionContextFactory in interface BatchEngineBatchTransactionContextFactorypublic void setHistoryExpirationFrequency(long historyExpirationFrequency)
public static String buildExceptionLogMessage(Throwable t)
t - the exception to build a log-able message for.public void start()
throws org.mule.runtime.api.exception.MuleException
start in interface org.mule.runtime.api.lifecycle.Startableorg.mule.runtime.api.exception.MuleExceptionCopyright © 2006–2022 MuleSoft, Inc.. All rights reserved.