public synchronized boolean cancelWorkflowRun() { if (getState().equals(State.completed)) { return false; } boolean result = Stop.cancelWorkflow(getWorkflowRunId()); if (result) { setState(State.cancelled); logger.info("Cancelled workflow runId=" + getWorkflowRunId() + " processId=" + instanceOwningProcessId); List<FailureListener> copyOfListeners = null; synchronized (failureListeners) { copyOfListeners = new ArrayList<FailureListener>(failureListeners); } for (FailureListener failureListener : copyOfListeners) { try { failureListener.workflowFailed("Workflow was cancelled", new WorkflowRunCancellation(getWorkflowRunId())); } catch (RuntimeException ex) { logger.warn("Could not notify failure listener " + failureListener, ex); } } processorsToComplete = 0; portsToComplete = 0; checkWorkflowFinished(); } return result; }