|
|
@ -43,18 +43,21 @@ public class StateWheelExecuteThread extends Thread { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(StateWheelExecuteThread.class); |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(StateWheelExecuteThread.class); |
|
|
|
|
|
|
|
|
|
|
|
ConcurrentHashMap<Integer, ProcessInstance> processInstanceCheckList; |
|
|
|
private ConcurrentHashMap<Integer, ProcessInstance> processInstanceTimeoutCheckList; |
|
|
|
ConcurrentHashMap<Integer, TaskInstance> taskInstanceCheckList; |
|
|
|
private ConcurrentHashMap<Integer, TaskInstance> taskInstanceTimeoutCheckList; |
|
|
|
|
|
|
|
private ConcurrentHashMap<Integer, TaskInstance> taskInstanceRetryCheckList; |
|
|
|
private ProcessInstanceExecCacheManager processInstanceExecCacheManager; |
|
|
|
private ProcessInstanceExecCacheManager processInstanceExecCacheManager; |
|
|
|
|
|
|
|
|
|
|
|
private int stateCheckIntervalSecs; |
|
|
|
private int stateCheckIntervalSecs; |
|
|
|
|
|
|
|
|
|
|
|
public StateWheelExecuteThread(ConcurrentHashMap<Integer, ProcessInstance> processInstances, |
|
|
|
public StateWheelExecuteThread(ConcurrentHashMap<Integer, ProcessInstance> processInstanceTimeoutCheckList, |
|
|
|
ConcurrentHashMap<Integer, TaskInstance> taskInstances, |
|
|
|
ConcurrentHashMap<Integer, TaskInstance> taskInstanceTimeoutCheckList, |
|
|
|
|
|
|
|
ConcurrentHashMap<Integer, TaskInstance> taskInstanceRetryCheckList, |
|
|
|
ProcessInstanceExecCacheManager processInstanceExecCacheManager, |
|
|
|
ProcessInstanceExecCacheManager processInstanceExecCacheManager, |
|
|
|
int stateCheckIntervalSecs) { |
|
|
|
int stateCheckIntervalSecs) { |
|
|
|
this.processInstanceCheckList = processInstances; |
|
|
|
this.processInstanceTimeoutCheckList = processInstanceTimeoutCheckList; |
|
|
|
this.taskInstanceCheckList = taskInstances; |
|
|
|
this.taskInstanceTimeoutCheckList = taskInstanceTimeoutCheckList; |
|
|
|
|
|
|
|
this.taskInstanceRetryCheckList = taskInstanceRetryCheckList; |
|
|
|
this.processInstanceExecCacheManager = processInstanceExecCacheManager; |
|
|
|
this.processInstanceExecCacheManager = processInstanceExecCacheManager; |
|
|
|
this.stateCheckIntervalSecs = stateCheckIntervalSecs; |
|
|
|
this.stateCheckIntervalSecs = stateCheckIntervalSecs; |
|
|
|
} |
|
|
|
} |
|
|
@ -65,8 +68,9 @@ public class StateWheelExecuteThread extends Thread { |
|
|
|
logger.info("state wheel thread start"); |
|
|
|
logger.info("state wheel thread start"); |
|
|
|
while (Stopper.isRunning()) { |
|
|
|
while (Stopper.isRunning()) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
checkProcess(); |
|
|
|
checkTask4Timeout(); |
|
|
|
checkTask(); |
|
|
|
checkTask4Retry(); |
|
|
|
|
|
|
|
checkProcess4Timeout(); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("state wheel thread check error:", e); |
|
|
|
logger.error("state wheel thread check error:", e); |
|
|
|
} |
|
|
|
} |
|
|
@ -74,85 +78,96 @@ public class StateWheelExecuteThread extends Thread { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean addProcess(ProcessInstance processInstance) { |
|
|
|
public void addProcess4TimeoutCheck(ProcessInstance processInstance) { |
|
|
|
this.processInstanceCheckList.put(processInstance.getId(), processInstance); |
|
|
|
this.processInstanceTimeoutCheckList.put(processInstance.getId(), processInstance); |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean addTask(TaskInstance taskInstance) { |
|
|
|
public void addTask4TimeoutCheck(TaskInstance taskInstance) { |
|
|
|
this.taskInstanceCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
this.taskInstanceTimeoutCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkTask() { |
|
|
|
public void addTask4RetryCheck(TaskInstance taskInstance) { |
|
|
|
if (taskInstanceCheckList.isEmpty()) { |
|
|
|
this.taskInstanceRetryCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (TaskInstance taskInstance : this.taskInstanceCheckList.values()) { |
|
|
|
public void checkTask4Timeout() { |
|
|
|
|
|
|
|
if (taskInstanceTimeoutCheckList.isEmpty()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (TaskInstance taskInstance : taskInstanceTimeoutCheckList.values()) { |
|
|
|
if (TimeoutFlag.OPEN == taskInstance.getTaskDefine().getTimeoutFlag()) { |
|
|
|
if (TimeoutFlag.OPEN == taskInstance.getTaskDefine().getTimeoutFlag()) { |
|
|
|
long timeRemain = DateUtils.getRemainTime(taskInstance.getStartTime(), taskInstance.getTaskDefine().getTimeout() * Constants.SEC_2_MINUTES_TIME_UNIT); |
|
|
|
long timeRemain = DateUtils.getRemainTime(taskInstance.getStartTime(), taskInstance.getTaskDefine().getTimeout() * Constants.SEC_2_MINUTES_TIME_UNIT); |
|
|
|
if (0 >= timeRemain && processTimeout(taskInstance)) { |
|
|
|
if (0 >= timeRemain) { |
|
|
|
taskInstanceCheckList.remove(taskInstance.getId()); |
|
|
|
addTaskTimeoutEvent(taskInstance); |
|
|
|
|
|
|
|
taskInstanceTimeoutCheckList.remove(taskInstance.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void checkTask4Retry() { |
|
|
|
|
|
|
|
if (taskInstanceRetryCheckList.isEmpty()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (TaskInstance taskInstance : this.taskInstanceRetryCheckList.values()) { |
|
|
|
if (taskInstance.taskCanRetry() && taskInstance.retryTaskIntervalOverTime()) { |
|
|
|
if (taskInstance.taskCanRetry() && taskInstance.retryTaskIntervalOverTime()) { |
|
|
|
processDependCheck(taskInstance); |
|
|
|
addTaskStateChangeEvent(taskInstance); |
|
|
|
taskInstanceCheckList.remove(taskInstance.getId()); |
|
|
|
taskInstanceRetryCheckList.remove(taskInstance.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (taskInstance.isSubProcess() || taskInstance.isDependTask()) { |
|
|
|
if (taskInstance.isSubProcess() || taskInstance.isDependTask()) { |
|
|
|
processDependCheck(taskInstance); |
|
|
|
addTaskStateChangeEvent(taskInstance); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkProcess() { |
|
|
|
private void checkProcess4Timeout() { |
|
|
|
if (processInstanceCheckList.isEmpty()) { |
|
|
|
if (processInstanceTimeoutCheckList.isEmpty()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
for (ProcessInstance processInstance : this.processInstanceCheckList.values()) { |
|
|
|
for (ProcessInstance processInstance : this.processInstanceTimeoutCheckList.values()) { |
|
|
|
|
|
|
|
|
|
|
|
long timeRemain = DateUtils.getRemainTime(processInstance.getStartTime(), processInstance.getTimeout() * Constants.SEC_2_MINUTES_TIME_UNIT); |
|
|
|
long timeRemain = DateUtils.getRemainTime(processInstance.getStartTime(), processInstance.getTimeout() * Constants.SEC_2_MINUTES_TIME_UNIT); |
|
|
|
if (0 <= timeRemain && processTimeout(processInstance)) { |
|
|
|
if (0 >= timeRemain) { |
|
|
|
processInstanceCheckList.remove(processInstance.getId()); |
|
|
|
addProcessTimeoutEvent(processInstance); |
|
|
|
} |
|
|
|
processInstanceTimeoutCheckList.remove(processInstance.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void putEvent(StateEvent stateEvent) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!processInstanceExecCacheManager.contains(stateEvent.getProcessInstanceId())) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
WorkflowExecuteThread workflowExecuteThread = this.processInstanceExecCacheManager.getByProcessInstanceId(stateEvent.getProcessInstanceId()); |
|
|
|
|
|
|
|
workflowExecuteThread.addStateEvent(stateEvent); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean processDependCheck(TaskInstance taskInstance) { |
|
|
|
private boolean addTaskStateChangeEvent(TaskInstance taskInstance) { |
|
|
|
StateEvent stateEvent = new StateEvent(); |
|
|
|
StateEvent stateEvent = new StateEvent(); |
|
|
|
stateEvent.setType(StateEventType.TASK_STATE_CHANGE); |
|
|
|
stateEvent.setType(StateEventType.TASK_STATE_CHANGE); |
|
|
|
stateEvent.setProcessInstanceId(taskInstance.getProcessInstanceId()); |
|
|
|
stateEvent.setProcessInstanceId(taskInstance.getProcessInstanceId()); |
|
|
|
stateEvent.setTaskInstanceId(taskInstance.getId()); |
|
|
|
stateEvent.setTaskInstanceId(taskInstance.getId()); |
|
|
|
stateEvent.setExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); |
|
|
|
stateEvent.setExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); |
|
|
|
putEvent(stateEvent); |
|
|
|
addEvent(stateEvent); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean processTimeout(TaskInstance taskInstance) { |
|
|
|
private boolean addTaskTimeoutEvent(TaskInstance taskInstance) { |
|
|
|
StateEvent stateEvent = new StateEvent(); |
|
|
|
StateEvent stateEvent = new StateEvent(); |
|
|
|
stateEvent.setType(StateEventType.TASK_TIMEOUT); |
|
|
|
stateEvent.setType(StateEventType.TASK_TIMEOUT); |
|
|
|
stateEvent.setProcessInstanceId(taskInstance.getProcessInstanceId()); |
|
|
|
stateEvent.setProcessInstanceId(taskInstance.getProcessInstanceId()); |
|
|
|
stateEvent.setTaskInstanceId(taskInstance.getId()); |
|
|
|
stateEvent.setTaskInstanceId(taskInstance.getId()); |
|
|
|
putEvent(stateEvent); |
|
|
|
addEvent(stateEvent); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean processTimeout(ProcessInstance processInstance) { |
|
|
|
private boolean addProcessTimeoutEvent(ProcessInstance processInstance) { |
|
|
|
StateEvent stateEvent = new StateEvent(); |
|
|
|
StateEvent stateEvent = new StateEvent(); |
|
|
|
stateEvent.setType(StateEventType.PROCESS_TIMEOUT); |
|
|
|
stateEvent.setType(StateEventType.PROCESS_TIMEOUT); |
|
|
|
stateEvent.setProcessInstanceId(processInstance.getId()); |
|
|
|
stateEvent.setProcessInstanceId(processInstance.getId()); |
|
|
|
putEvent(stateEvent); |
|
|
|
addEvent(stateEvent); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addEvent(StateEvent stateEvent) { |
|
|
|
|
|
|
|
if (!processInstanceExecCacheManager.contains(stateEvent.getProcessInstanceId())) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WorkflowExecuteThread workflowExecuteThread = this.processInstanceExecCacheManager.getByProcessInstanceId(stateEvent.getProcessInstanceId()); |
|
|
|
|
|
|
|
workflowExecuteThread.addStateEvent(stateEvent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|