Unified API Developer Manual / Version 2204
Table Of ContentsLong actions are very similar to actions, but they are executed in three separate phases. Only the first and the last phase are permitted to access the containing process and its variables. The second phase runs completely outside of any database transaction. Therefore, the second phase does not consume system resources and there is no need to finish it quickly. Long actions are particularly well suited for accessing remote servers that may not respond immediately.
The first phase consists of the method
Object extractParameters(Task task);
which must read all task and process variables that are needed for processing. Afterwards, all relevant data must be packaged into an object of arbitrary type, which is returned from the method. If multiple values have to be returned, either an object array or a custom class can be used for aggregating these values. Because a long action always runs in the context of an automated task, the method is passed a correctly typed task object immediately. Often you will have to retrieve the containing process before reading any variables. Afterwards the method
Object execute(Object params);
is executed. It is passed the object that was returned from extractParameters
.
It may perform arbitrary computations for an extended period before it returns its result as
an object. The method may not, however, access any objects of the workflow repository.
Finally
ActionResult storeResult(Task task, Object result);
is called with the result from execute
. It may write task and process variables
as needed. The returned action result is processed as by an ordinary action.
The class
LongActionBase
implements the
LongAction
interface and provides some convenience code. Instead of execute
and
storeResult
you simply implement the method
Object doExecute(Object params) throws Exception;
If that method throws an exception, that exception forms the basis of a failed action
result. If a value is returned, that value is wrapped in a successful action result. Note
that you must implement the extractParameters
method even if you base you
action on the
LongActionBase
class.
The method abort()
should be implemented to let all running
extractParameters
, execute
and storeResult
method
calls return early, possibly by throwing an
ActionAbortedException.
This method is called when the Workflow Server is shutting down.
Like an ordinary action, a long action must be reentrant and it must be robust against being rerun in the case of a problem.