Class DefaultJobManager
- java.lang.Object
-
- org.flowable.job.service.impl.asyncexecutor.DefaultJobManager
-
- All Implemented Interfaces:
JobManager
- Direct Known Subclasses:
AbstractMessageBasedJobManager
public class DefaultJobManager extends Object implements JobManager
-
-
Field Summary
Fields Modifier and Type Field Description static StringCYCLE_TYPEprotected JobServiceConfigurationjobServiceConfiguration
-
Constructor Summary
Constructors Constructor Description DefaultJobManager(JobServiceConfiguration jobServiceConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractRuntimeJobEntityactivateSuspendedJob(SuspendedJobEntity job)Transforms aSuspendedJobEntityback to anAbstractRuntimeJobEntity(i.e.voidbulkMoveTimerJobsToExecutableJobs(List<TimerJobEntity> timerJobEntities)Moves a collection ofTimerJobEntityinstances to become asyncJobEntityinstances (the timer is deleted and a new async job is inserted).protected voidcallHistoryJobProcessors(HistoryJobProcessorContext.Phase processorType, HistoryJobEntity historyJobEntity)protected voidcallJobProcessors(JobProcessorContext.Phase processorType, AbstractJobEntity abstractJobEntity)protected HistoryJobEntitycopyHistoryJobInfo(HistoryJobEntity copyToJob, HistoryJobEntity copyFromJob)protected AbstractJobEntitycopyHistoryJobProperties(AbstractJobEntity copyToJob, AbstractJobEntity copyFromJob)AbstractRuntimeJobEntitycopyJobInfo(AbstractRuntimeJobEntity copyToJob, AbstractRuntimeJobEntity copyFromJob)Copy job info from one job to the otherprotected voidcreateAsyncHistoryHintListeners(HistoryJobEntity historyJobEntity)voidcreateAsyncJob(JobEntity jobEntity, boolean exclusive)Creates an async job so that it can be continued later in a background thread.DeadLetterJobEntitycreateDeadLetterJobFromHistoryJob(HistoryJobEntity historyJobEntity)Create a dead letter job from a history job.DeadLetterJobEntitycreateDeadLetterJobFromOtherJob(AbstractRuntimeJobEntity otherJob)Create a dead letter job from another jobJobEntitycreateExecutableJobFromOtherJob(AbstractRuntimeJobEntity job)Create an executable job from another jobprotected JobEntitycreateExecutableJobFromOtherJob(AbstractRuntimeJobEntity job, boolean lockJob)ExternalWorkerJobEntitycreateExternalWorkerJobFromOtherJob(AbstractRuntimeJobEntity otherJob)Create an external worker job from another jobprotected voidcreateHintListeners(AsyncExecutor asyncExecutor, JobInfoEntity job)SuspendedJobEntitycreateSuspendedJobFromOtherJob(AbstractRuntimeJobEntity otherJob)Create a suspended job from another jobTimerJobEntitycreateTimerJobFromOtherJob(AbstractRuntimeJobEntity otherJob)Create a timer job from another jobvoidexecute(JobInfo job)Execute a job, which means that the logic (async logic, timer that fires, etc) is executed, typically by a background thread of an executor.protected voidexecuteHistoryJob(HistoryJobEntity historyJobEntity)protected voidexecuteHistoryJobHandler(HistoryJobEntity historyJobEntity)protected voidexecuteJobHandler(JobEntity jobEntity)protected voidexecuteMessageJob(JobEntity jobEntity)protected voidexecuteTimerJob(JobEntity timerEntity)protected voidfillDefaultAsyncJobInfo(JobEntity jobEntity, boolean exclusive)protected AsyncExecutorgetAsyncExecutor()protected AsyncExecutorgetAsyncHistoryExecutor()protected StringgetBusinessCalendarName(String calendarName, org.flowable.variable.api.delegate.VariableScope variableScope)StringgetBusinessCalendarName(JobEntity timerEntity, org.flowable.variable.api.delegate.VariableScope variableScope)Get the business calendar name of the job configurationprotected CommandContextgetCommandContext()protected StringgetExceptionStacktrace(Throwable exception)JobServiceConfigurationgetJobServiceConfiguration()protected voidhintAsyncExecutor(JobEntity job)protected voidhintAsyncHistoryExecutor(HistoryJobEntity historyJobEntity)protected voidinternalCreateAsyncJob(JobEntity jobEntity, boolean exclusive)protected voidinternalCreateLockedAsyncJob(JobEntity jobEntity, boolean exclusive)protected booleanisAsyncExecutorActive()protected booleanisAsyncExecutorRemainingCapacitySufficient(int neededCapacity)protected booleanisAsyncHistoryExecutorActive()protected booleanisExecutorActive(AsyncExecutor asyncExecutor)protected booleanisValidTime(JobEntity timerEntity, Date newTimerDate, org.flowable.variable.api.delegate.VariableScope variableScope)JobmoveDeadLetterJobToExecutableJob(DeadLetterJobEntity deadLetterJobEntity, int retries)Transforms aDeadLetterJobEntityto aJob, thus making it executable again.HistoryJobEntitymoveDeadLetterJobToHistoryJob(DeadLetterJobEntity deadLetterJobEntity, int retries)Transforms aDeadLetterJobEntityto aHistoryJob, thus making it executable again (by the async history executor).JobEntitymoveExternalWorkerJobToExecutableJob(ExternalWorkerJobEntity externalWorkerJob)Moves anExternalWorkerJobEntityto become an asyncJobEntity.DeadLetterJobEntitymoveJobToDeadLetterJob(AbstractRuntimeJobEntity job)Transforms anAbstractRuntimeJobEntityto aDeadLetterJobEntity.SuspendedJobEntitymoveJobToSuspendedJob(AbstractRuntimeJobEntity job)Moves anAbstractRuntimeJobEntityto become aSuspendedJobEntity, such that theAsyncExecutorwon't pick it up anymore for execution.TimerJobEntitymoveJobToTimerJob(AbstractRuntimeJobEntity job)Moves anAbstractRuntimeJobEntityto become aTimerJobEntity.JobEntitymoveTimerJobToExecutableJob(TimerJobEntity timerJob)Moves aTimerJobEntityto become an asyncJobEntity.voidscheduleAsyncJob(JobEntity jobEntity)Schedules and async job.HistoryJobEntityscheduleHistoryJob(HistoryJobEntity historyJobEntity)schedules aHistoryJobEntity, meaning it will be scheduled (inserted in the database/put on a queue/...) to be executed at a later point in time.voidscheduleTimerJob(TimerJobEntity timerJob)Schedules a timer, meaning it will be inserted in the datastore.protected voidsendMoveToDeadletterEvent(JobInfo job)voidsetJobServiceConfiguration(JobServiceConfiguration jobServiceConfiguration)The ProcessEngineConfiguration instance will be passed when the ProcessEngine is built.protected voidsetLockTimeAndOwner(AsyncExecutor asyncExecutor, JobInfoEntity jobInfoEntity)protected voidtriggerAsyncHistoryExecutorIfNeeded(HistoryJobEntity historyJobEntity)protected voidtriggerExecutorIfNeeded(JobEntity jobEntity)voidunacquire(JobInfo job)Unacquires a job, meaning that this job was previously locked, and it is now freed to be acquired by other executor nodes.voidunacquireWithDecrementRetries(JobInfo job, Throwable exception)Unacquires a job, meaning that this job was previously locked, and it is now freed to be acquired by other executor nodes.
-
-
-
Field Detail
-
CYCLE_TYPE
public static final String CYCLE_TYPE
- See Also:
- Constant Field Values
-
jobServiceConfiguration
protected JobServiceConfiguration jobServiceConfiguration
-
-
Constructor Detail
-
DefaultJobManager
public DefaultJobManager(JobServiceConfiguration jobServiceConfiguration)
-
-
Method Detail
-
createAsyncJob
public void createAsyncJob(JobEntity jobEntity, boolean exclusive)
Description copied from interface:JobManagerCreates an async job so that it can be continued later in a background thread.- Specified by:
createAsyncJobin interfaceJobManager
-
scheduleAsyncJob
public void scheduleAsyncJob(JobEntity jobEntity)
Description copied from interface:JobManagerSchedules and async job. If theAsyncExecutoris running, it can be executed immediately after the transaction. Otherwise it can be picked up by other executors.- Specified by:
scheduleAsyncJobin interfaceJobManager
-
triggerExecutorIfNeeded
protected void triggerExecutorIfNeeded(JobEntity jobEntity)
-
scheduleTimerJob
public void scheduleTimerJob(TimerJobEntity timerJob)
Description copied from interface:JobManagerSchedules a timer, meaning it will be inserted in the datastore.- Specified by:
scheduleTimerJobin interfaceJobManager
-
moveTimerJobToExecutableJob
public JobEntity moveTimerJobToExecutableJob(TimerJobEntity timerJob)
Description copied from interface:JobManagerMoves aTimerJobEntityto become an asyncJobEntity. This happens for example when the due date of a timer is reached, the timer entity then becomes a 'regular' async job that can be picked up by theAsyncExecutor.- Specified by:
moveTimerJobToExecutableJobin interfaceJobManager
-
bulkMoveTimerJobsToExecutableJobs
public void bulkMoveTimerJobsToExecutableJobs(List<TimerJobEntity> timerJobEntities)
Description copied from interface:JobManagerMoves a collection ofTimerJobEntityinstances to become asyncJobEntityinstances (the timer is deleted and a new async job is inserted). Note that there are no revision checks happening on theTimerJobEntityinstances, this means this method should only be used when running with a global acquire lock.- Specified by:
bulkMoveTimerJobsToExecutableJobsin interfaceJobManager
-
moveExternalWorkerJobToExecutableJob
public JobEntity moveExternalWorkerJobToExecutableJob(ExternalWorkerJobEntity externalWorkerJob)
Description copied from interface:JobManagerMoves anExternalWorkerJobEntityto become an asyncJobEntity. This happens when the external worker has completed the work and the external work job then becomes a 'regular' async job that can be picked up by theAsyncExecutor.- Specified by:
moveExternalWorkerJobToExecutableJobin interfaceJobManager
-
moveJobToTimerJob
public TimerJobEntity moveJobToTimerJob(AbstractRuntimeJobEntity job)
Description copied from interface:JobManagerMoves anAbstractRuntimeJobEntityto become aTimerJobEntity. This happens for example when an async job is executed and fails. It then becomes a timer, as it needs to be retried later.- Specified by:
moveJobToTimerJobin interfaceJobManager
-
moveJobToSuspendedJob
public SuspendedJobEntity moveJobToSuspendedJob(AbstractRuntimeJobEntity job)
Description copied from interface:JobManagerMoves anAbstractRuntimeJobEntityto become aSuspendedJobEntity, such that theAsyncExecutorwon't pick it up anymore for execution.- Specified by:
moveJobToSuspendedJobin interfaceJobManager
-
activateSuspendedJob
public AbstractRuntimeJobEntity activateSuspendedJob(SuspendedJobEntity job)
Description copied from interface:JobManagerTransforms aSuspendedJobEntityback to anAbstractRuntimeJobEntity(i.e. to what it was originally). The job will now again be able to picked up by theAsyncExecutor.- Specified by:
activateSuspendedJobin interfaceJobManager
-
moveJobToDeadLetterJob
public DeadLetterJobEntity moveJobToDeadLetterJob(AbstractRuntimeJobEntity job)
Description copied from interface:JobManagerTransforms anAbstractRuntimeJobEntityto aDeadLetterJobEntity. This means that the job has been tried a configurable amount of times, but kept failing.- Specified by:
moveJobToDeadLetterJobin interfaceJobManager
-
sendMoveToDeadletterEvent
protected void sendMoveToDeadletterEvent(JobInfo job)
-
moveDeadLetterJobToExecutableJob
public Job moveDeadLetterJobToExecutableJob(DeadLetterJobEntity deadLetterJobEntity, int retries)
Description copied from interface:JobManagerTransforms aDeadLetterJobEntityto aJob, thus making it executable again. Note that a 'retries' parameter needs to be passed, as the job got into the deadletter table because of it failed and retries became 0.- Specified by:
moveDeadLetterJobToExecutableJobin interfaceJobManager
-
moveDeadLetterJobToHistoryJob
public HistoryJobEntity moveDeadLetterJobToHistoryJob(DeadLetterJobEntity deadLetterJobEntity, int retries)
Description copied from interface:JobManagerTransforms aDeadLetterJobEntityto aHistoryJob, thus making it executable again (by the async history executor). Note that a 'retries' parameter needs to be passed, as the job got into the deadletter table because of it failed and retries became 0.- Specified by:
moveDeadLetterJobToHistoryJobin interfaceJobManager
-
execute
public void execute(JobInfo job)
Description copied from interface:JobManagerExecute a job, which means that the logic (async logic, timer that fires, etc) is executed, typically by a background thread of an executor.- Specified by:
executein interfaceJobManager
-
unacquire
public void unacquire(JobInfo job)
Description copied from interface:JobManagerUnacquires a job, meaning that this job was previously locked, and it is now freed to be acquired by other executor nodes.- Specified by:
unacquirein interfaceJobManager
-
unacquireWithDecrementRetries
public void unacquireWithDecrementRetries(JobInfo job, Throwable exception)
Description copied from interface:JobManagerUnacquires a job, meaning that this job was previously locked, and it is now freed to be acquired by other executor nodes.- Specified by:
unacquireWithDecrementRetriesin interfaceJobManager
-
executeMessageJob
protected void executeMessageJob(JobEntity jobEntity)
-
executeHistoryJob
protected void executeHistoryJob(HistoryJobEntity historyJobEntity)
-
executeTimerJob
protected void executeTimerJob(JobEntity timerEntity)
-
executeJobHandler
protected void executeJobHandler(JobEntity jobEntity)
-
executeHistoryJobHandler
protected void executeHistoryJobHandler(HistoryJobEntity historyJobEntity)
-
isValidTime
protected boolean isValidTime(JobEntity timerEntity, Date newTimerDate, org.flowable.variable.api.delegate.VariableScope variableScope)
-
hintAsyncExecutor
protected void hintAsyncExecutor(JobEntity job)
-
createHintListeners
protected void createHintListeners(AsyncExecutor asyncExecutor, JobInfoEntity job)
-
getBusinessCalendarName
public String getBusinessCalendarName(JobEntity timerEntity, org.flowable.variable.api.delegate.VariableScope variableScope)
Description copied from interface:JobManagerGet the business calendar name of the job configuration- Specified by:
getBusinessCalendarNamein interfaceJobManager
-
getBusinessCalendarName
protected String getBusinessCalendarName(String calendarName, org.flowable.variable.api.delegate.VariableScope variableScope)
-
scheduleHistoryJob
public HistoryJobEntity scheduleHistoryJob(HistoryJobEntity historyJobEntity)
Description copied from interface:JobManagerschedules aHistoryJobEntity, meaning it will be scheduled (inserted in the database/put on a queue/...) to be executed at a later point in time.- Specified by:
scheduleHistoryJobin interfaceJobManager
-
triggerAsyncHistoryExecutorIfNeeded
protected void triggerAsyncHistoryExecutorIfNeeded(HistoryJobEntity historyJobEntity)
-
hintAsyncHistoryExecutor
protected void hintAsyncHistoryExecutor(HistoryJobEntity historyJobEntity)
-
createAsyncHistoryHintListeners
protected void createAsyncHistoryHintListeners(HistoryJobEntity historyJobEntity)
-
internalCreateAsyncJob
protected void internalCreateAsyncJob(JobEntity jobEntity, boolean exclusive)
-
internalCreateLockedAsyncJob
protected void internalCreateLockedAsyncJob(JobEntity jobEntity, boolean exclusive)
-
setLockTimeAndOwner
protected void setLockTimeAndOwner(AsyncExecutor asyncExecutor, JobInfoEntity jobInfoEntity)
-
fillDefaultAsyncJobInfo
protected void fillDefaultAsyncJobInfo(JobEntity jobEntity, boolean exclusive)
-
createExecutableJobFromOtherJob
public JobEntity createExecutableJobFromOtherJob(AbstractRuntimeJobEntity job)
Description copied from interface:JobManagerCreate an executable job from another job- Specified by:
createExecutableJobFromOtherJobin interfaceJobManager
-
createExecutableJobFromOtherJob
protected JobEntity createExecutableJobFromOtherJob(AbstractRuntimeJobEntity job, boolean lockJob)
-
createTimerJobFromOtherJob
public TimerJobEntity createTimerJobFromOtherJob(AbstractRuntimeJobEntity otherJob)
Description copied from interface:JobManagerCreate a timer job from another job- Specified by:
createTimerJobFromOtherJobin interfaceJobManager
-
createSuspendedJobFromOtherJob
public SuspendedJobEntity createSuspendedJobFromOtherJob(AbstractRuntimeJobEntity otherJob)
Description copied from interface:JobManagerCreate a suspended job from another job- Specified by:
createSuspendedJobFromOtherJobin interfaceJobManager
-
createDeadLetterJobFromOtherJob
public DeadLetterJobEntity createDeadLetterJobFromOtherJob(AbstractRuntimeJobEntity otherJob)
Description copied from interface:JobManagerCreate a dead letter job from another job- Specified by:
createDeadLetterJobFromOtherJobin interfaceJobManager
-
createDeadLetterJobFromHistoryJob
public DeadLetterJobEntity createDeadLetterJobFromHistoryJob(HistoryJobEntity historyJobEntity)
Description copied from interface:JobManagerCreate a dead letter job from a history job. This is different fromJobManager.createDeadLetterJobFromOtherJob(AbstractRuntimeJobEntity), because history jobs have different data and cannot become timer/suspended/executable jobs.- Specified by:
createDeadLetterJobFromHistoryJobin interfaceJobManager
-
createExternalWorkerJobFromOtherJob
public ExternalWorkerJobEntity createExternalWorkerJobFromOtherJob(AbstractRuntimeJobEntity otherJob)
Description copied from interface:JobManagerCreate an external worker job from another job- Specified by:
createExternalWorkerJobFromOtherJobin interfaceJobManager
-
copyJobInfo
public AbstractRuntimeJobEntity copyJobInfo(AbstractRuntimeJobEntity copyToJob, AbstractRuntimeJobEntity copyFromJob)
Description copied from interface:JobManagerCopy job info from one job to the other- Specified by:
copyJobInfoin interfaceJobManager
-
copyHistoryJobInfo
protected HistoryJobEntity copyHistoryJobInfo(HistoryJobEntity copyToJob, HistoryJobEntity copyFromJob)
-
copyHistoryJobProperties
protected AbstractJobEntity copyHistoryJobProperties(AbstractJobEntity copyToJob, AbstractJobEntity copyFromJob)
-
getJobServiceConfiguration
public JobServiceConfiguration getJobServiceConfiguration()
-
setJobServiceConfiguration
public void setJobServiceConfiguration(JobServiceConfiguration jobServiceConfiguration)
Description copied from interface:JobManagerThe ProcessEngineConfiguration instance will be passed when the ProcessEngine is built.- Specified by:
setJobServiceConfigurationin interfaceJobManager
-
isAsyncExecutorActive
protected boolean isAsyncExecutorActive()
-
isAsyncExecutorRemainingCapacitySufficient
protected boolean isAsyncExecutorRemainingCapacitySufficient(int neededCapacity)
-
isAsyncHistoryExecutorActive
protected boolean isAsyncHistoryExecutorActive()
-
isExecutorActive
protected boolean isExecutorActive(AsyncExecutor asyncExecutor)
-
getCommandContext
protected CommandContext getCommandContext()
-
getAsyncExecutor
protected AsyncExecutor getAsyncExecutor()
-
getAsyncHistoryExecutor
protected AsyncExecutor getAsyncHistoryExecutor()
-
callJobProcessors
protected void callJobProcessors(JobProcessorContext.Phase processorType, AbstractJobEntity abstractJobEntity)
-
callHistoryJobProcessors
protected void callHistoryJobProcessors(HistoryJobProcessorContext.Phase processorType, HistoryJobEntity historyJobEntity)
-
-