public class JobHelper extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JobHelper.ExitCondition |
Constructor and Description |
---|
JobHelper() |
Modifier and Type | Method and Description |
---|---|
JobHelper.ExitCondition |
getExitCondition(RequestExecutionContext requestExecutionContext)
Unified API to determine if job execution has been interrupted and return the appropriate exit condition for sync java jobs.
|
State |
getState(Long requestId)
Checks if a cancel operation has been initiated for the given request.
|
void |
handleExecutionInterruption(RequestExecutionContext requestExecutionContext)
Unified API to determine if job execution has been interrupted and raise appropriate scheduler exception for sync java jobs.
|
boolean |
isExecutionInterrupted(RequestExecutionContext requestExecutionContext)
Unified API to check if job execution should be interrupted for sync java jobs.
|
boolean |
isQuiesceState() |
void |
releaseExitCondition(RequestExecutionContext requestExecutionContext)
Unified API to release a locked exit condition for a request.
|
public boolean isQuiesceState()
public State getState(Long requestId) throws RequestNotFoundException, RuntimeServiceException
The time since a cancel operation is initiated for request is tracked. The purpose is to only allow certain types of recovery operations N minutes after a cancel is invoked. However, invoking this method will reset the timer since it is seen as an indication that the job is still active.
Thus if the time limit is 30 minutes and the job checks in to ESS 28 minutes after cancel was initiated, the timer will be set back to 0, allowing 30 more minutes.
The check-in portion of this method is not currently useful for synchronous jobs, since the timer is only used for force cancel, which only applies to asynchronous jobs.
requestExecutionContext
- the execution context of the running request that is being checked.true
if a cancel operation has been initated for this request, false
otherwise.RequestNotFoundException
- if the request was not foundRuntimeServiceException
- if a RuntimeService subsystem failure occurspublic boolean isExecutionInterrupted(RequestExecutionContext requestExecutionContext)
This API checks for request cancel and server Quiesce: Cancel and quiesce checks are 'efficient' & 'in-memory' checks. Cancel check does not require job to implement Cancellable interface, so it can be used by jobs not implementing Cancellable interface as well.
If either server is in Quiesce state or if the request cancel has been initiated, this API will return true. This allows the sync java job to cleanup and exit. The getExitCondition API below can be used to figure out which exit condition has occurred. The handleExecutionInterruption API below can be used by the job to raise appropriate SchedulerException.
requestExecutionContext
- the execution context of the running request that is being checked.true
if job execution needs to be interrupted for this request, false
otherwise.public JobHelper.ExitCondition getExitCondition(RequestExecutionContext requestExecutionContext)
This API checks for request cancel and server Quiesce, similar to the isExecutionInterrupted API and returns appropriate exit condition. If request cancel has been initiated, it returns Cancel exit condition. Else if server is in Quiesce state, it returns Suspend exit condition.
requestExecutionContext
- the execution context of the running request that is being checked.public void handleExecutionInterruption(RequestExecutionContext requestExecutionContext) throws ExecutionCancelledException, ExecutionSuspendException
This API checks for request cancel and server Quiesce, similar to the isExecutionInterrupted API. If request cancel has been initiated, it will throw ExecutionCancelledException. Else if server is in Quiesce state, it will throw ExecutionSuspendException.
requestExecutionContext
- the execution context of the running request that is being checked.ExecutionCancelledException
- if request is cancelledExecutionSuspendException
- if server in Quiesce statepublic void releaseExitCondition(RequestExecutionContext requestExecutionContext)
Normally a job is expected to cleanup and exit as soon as an exit condition is detected. If there are cases, where a job may not exit despite an exit condition being found, then the releaseExitCondition can be called to release the locked exit condition, to ensure the exit conditions are examined afresh next time. It does not affect the exit conditions for the request.
requestExecutionContext
- the execution context of the running request that is being checked.