In Activiti 5.11, the capability to suspend (and re-activate, of course) process definitions and process instances is added (the groundwork for this was done in a previous release by Daniel, so (again) many thanks for this)
On the repositoryService following methods were added:
void suspendProcessDefinitionById(String processDefinitionId); void suspendProcessDefinitionById(String processDefinitionId, boolean suspendProcessInstances, Date suspensionDate); void suspendProcessDefinitionByKey(String processDefinitionKey); void suspendProcessDefinitionByKey(String processDefinitionKey, boolean suspendProcessInstances, Date suspensionDate); void activateProcessDefinitionById(String processDefinitionId); void activateProcessDefinitionById(String processDefinitionId, boolean activateProcessInstances, Date activationDate); void activateProcessDefinitionByKey(String processDefinitionKey); void activateProcessDefinitionByKey(String processDefinitionKey, boolean activateProcessInstances, Date activationDate);
When you suspend a process definition, this means that you won’t be able to start new process instances for that process definition (an exception will be thrown). As you can see in the methods above, you can also suspend all process instances related to the process definition at once. Read on to learn what that means. And lastly, both suspend and activate take an optional date. When providing a date, this will be the point in time when the actual suspend/activation will happen. Up to that point in time, the process definition will stay in its current state.
This makes for some cool use cases, like for example an election process that is only valid a certain period of time. Or phasing out a process by not allowing new process instances to be created.
You can also suspend/activate process instances on an individual basis, using following methods on the RuntimeService:
void suspendProcessInstanceById(String processInstanceId); void activateProcessInstanceById(String processInstanceId);
When a process instance is suspended, it cannot be continued. This means that no tasks can be completed, no variables can be set and even no jobs (timers and async steps) will be executed. The process instance is simply halted where it is and it cannot be continued in any way.
As usual, it’s very easy to include these API’s in your own application. For demo purposes, we’ve enhanced the Activiti Explorer web application to show this functionality. The screencast below gives you an impression of it. Again, don’t forget to press the little quality icon in the bottom right to get the HD view of the video (Youtube doesn’t allow embedding HD directly).