public static ExternalTaskEntity createAndInsert(ExecutionEntity execution, String topic, long priority) { ExternalTaskEntity externalTask = new ExternalTaskEntity(); externalTask.setTopicName(topic); externalTask.setExecutionId(execution.getId()); externalTask.setProcessInstanceId(execution.getProcessInstanceId()); externalTask.setProcessDefinitionId(execution.getProcessDefinitionId()); externalTask.setActivityId(execution.getActivityId()); externalTask.setActivityInstanceId(execution.getActivityInstanceId()); externalTask.setTenantId(execution.getTenantId()); externalTask.setPriority(priority); ProcessDefinitionEntity processDefinition = execution.getProcessDefinition(); externalTask.setProcessDefinitionKey(processDefinition.getKey()); externalTask.insert(); externalTask.produceHistoricExternalTaskCreatedEvent(); return externalTask; }
public void setRetriesAndManageIncidents(int retries) { if (areRetriesLeft() && retries <= 0) { createIncident(); } else if (!areRetriesLeft() && retries > 0) { removeIncident(); } setRetries(retries); }
@Override public void execute(ExternalTaskEntity externalTask) { externalTask.bpmnError(errorCode, errorMessage, variables); } }
public void delete() { deleteFromExecutionAndRuntimeTable(); produceHistoricExternalTaskDeletedEvent(); }
/** * process failed state, make sure that binary entity is created for the errorMessage, shortError * message does not exceed limit, handle properly retry counts and incidents * * @param errorMessage - short error message text * @param errorDetails - full error details * @param retries - updated value of retries left * @param retryDuration - used for lockExpirationTime calculation */ public void failed(String errorMessage, String errorDetails, int retries, long retryDuration) { ensureActive(); this.setErrorMessage(errorMessage); if (errorDetails != null) { setErrorDetails(errorDetails); } this.lockExpirationTime = new Date(ClockUtil.getCurrentTime().getTime() + retryDuration); setRetriesAndManageIncidents(retries); produceHistoricExternalTaskFailedEvent(); }
public void complete(Map<String, Object> variables, Map<String, Object> localVariables) { ensureActive(); ExecutionEntity associatedExecution = getExecution(); if (variables != null) { associatedExecution.setVariables(variables); } if (localVariables != null) { associatedExecution.setVariablesLocal(localVariables); } deleteFromExecutionAndRuntimeTable(); produceHistoricExternalTaskSuccessfulEvent(); associatedExecution.signal(null, null); }
public void bpmnError(String errorCode, String errorMessage, Map<String, Object> variables) { ensureActive(); ActivityExecution activityExecution = getExecution(); BpmnError bpmnError = null; if (errorMessage != null) { bpmnError = new BpmnError(errorCode, errorMessage); } else { bpmnError = new BpmnError(errorCode); } try { ExternalTaskActivityBehavior behavior = ((ExternalTaskActivityBehavior) activityExecution.getActivity().getActivityBehavior()); if (variables != null && !variables.isEmpty()) { activityExecution.setVariables(variables); } behavior.propagateBpmnError(bpmnError, activityExecution); } catch (Exception ex) { throw ProcessEngineLogger.CMD_LOGGER.exceptionBpmnErrorPropagationFailed(errorCode, ex); } }
protected void createIncident() { IncidentHandler incidentHandler = Context .getProcessEngineConfiguration() .getIncidentHandler(Incident.EXTERNAL_TASK_HANDLER_TYPE); incidentHandler.handleIncident(createIncidentContext(), errorMessage); }
protected void removeExternalTasks() { for (ExternalTaskEntity externalTask : getExternalTasks()) { externalTask.delete(); } }
@Override public void execute(ActivityExecution execution) throws Exception { ExecutionEntity executionEntity = (ExecutionEntity) execution; PriorityProvider<ExternalTaskActivityBehavior> provider = Context.getProcessEngineConfiguration().getExternalTaskPriorityProvider(); long priority = provider.determinePriority(executionEntity, this, null); String topic = (String) topicNameValueProvider.getValue(executionEntity); ExternalTaskEntity.createAndInsert(executionEntity, topic, priority); }
public void extendLock(long newLockExpirationTime) { ensureActive(); long newTime = ClockUtil.getCurrentTime().getTime() + newLockExpirationTime; this.lockExpirationTime = new Date(newTime); }
@Override public void execute(ExternalTaskEntity externalTask) { externalTask.complete(variables, localVariables); } }
/** * process failed state, make sure that binary entity is created for the errorMessage, shortError * message does not exceed limit, handle properly retry counts and incidents * * @param errorMessage - short error message text * @param errorDetails - full error details * @param retries - updated value of retries left * @param retryDuration - used for lockExpirationTime calculation */ public void failed(String errorMessage, String errorDetails, int retries, long retryDuration) { ensureActive(); this.setErrorMessage(errorMessage); if (errorDetails != null) { setErrorDetails(errorDetails); } this.lockExpirationTime = new Date(ClockUtil.getCurrentTime().getTime() + retryDuration); setRetriesAndManageIncidents(retries); produceHistoricExternalTaskFailedEvent(); }
public void complete(Map<String, Object> variables, Map<String, Object> localVariables) { ensureActive(); ExecutionEntity associatedExecution = getExecution(); if (variables != null) { associatedExecution.setVariables(variables); } if (localVariables != null) { associatedExecution.setVariablesLocal(localVariables); } deleteFromExecutionAndRuntimeTable(); produceHistoricExternalTaskSuccessfulEvent(); associatedExecution.signal(null, null); }
public void delete() { deleteFromExecutionAndRuntimeTable(); produceHistoricExternalTaskDeletedEvent(); }
public void bpmnError(String errorCode, String errorMessage, Map<String, Object> variables) { ensureActive(); ActivityExecution activityExecution = getExecution(); BpmnError bpmnError = null; if (errorMessage != null) { bpmnError = new BpmnError(errorCode, errorMessage); } else { bpmnError = new BpmnError(errorCode); } try { ExternalTaskActivityBehavior behavior = ((ExternalTaskActivityBehavior) activityExecution.getActivity().getActivityBehavior()); if (variables != null && !variables.isEmpty()) { activityExecution.setVariables(variables); } behavior.propagateBpmnError(bpmnError, activityExecution); } catch (Exception ex) { throw ProcessEngineLogger.CMD_LOGGER.exceptionBpmnErrorPropagationFailed(errorCode, ex); } }
protected void removeIncident() { IncidentHandler handler = Context .getProcessEngineConfiguration() .getIncidentHandler(Incident.EXTERNAL_TASK_HANDLER_TYPE); handler.resolveIncident(createIncidentContext()); }
protected void removeExternalTasks() { for (ExternalTaskEntity externalTask : getExternalTasks()) { externalTask.delete(); } }
@Override public void execute(ActivityExecution execution) throws Exception { ExecutionEntity executionEntity = (ExecutionEntity) execution; PriorityProvider<ExternalTaskActivityBehavior> provider = Context.getProcessEngineConfiguration().getExternalTaskPriorityProvider(); long priority = provider.determinePriority(executionEntity, this, null); String topic = (String) topicNameValueProvider.getValue(executionEntity); ExternalTaskEntity.createAndInsert(executionEntity, topic, priority); }
public void extendLock(long newLockExpirationTime) { ensureActive(); long newTime = ClockUtil.getCurrentTime().getTime() + newLockExpirationTime; this.lockExpirationTime = new Date(newTime); }