org.camunda.bpm.engine.impl
Class ExternalTaskServiceImpl

java.lang.Object
  extended by org.camunda.bpm.engine.impl.ServiceImpl
      extended by org.camunda.bpm.engine.impl.ExternalTaskServiceImpl
All Implemented Interfaces:
ExternalTaskService

public class ExternalTaskServiceImpl
extends ServiceImpl
implements ExternalTaskService

Author:
Thorben Lindhauer, Christopher Zell, Askar Akhmerov

Field Summary
 
Fields inherited from class org.camunda.bpm.engine.impl.ServiceImpl
commandExecutor
 
Constructor Summary
ExternalTaskServiceImpl()
           
 
Method Summary
 void complete(String externalTaskId, String workerId)
          Completes an external task on behalf of a worker.
 void complete(String externalTaskId, String workerId, Map<String,Object> variables)
          Completes an external task on behalf of a worker and submits variables to the process instance before continuing execution.
 ExternalTaskQuery createExternalTaskQuery()
           Queries for tasks that the currently authenticated user has at least one of the following permissions for: Permissions.READ on Resources.PROCESS_INSTANCE Permissions.READ_INSTANCE on Resources.PROCESS_DEFINITION
 void extendLock(String externalTaskId, String workerId, long lockDuration)
          Extends a lock of an external task on behalf of a worker.
 ExternalTaskQueryBuilder fetchAndLock(int maxTasks, String workerId)
          Calls method fetchAndLock(maxTasks, workerId, usePriority), where usePriority is false.
 ExternalTaskQueryBuilder fetchAndLock(int maxTasks, String workerId, boolean usePriority)
          Defines fetching of external tasks by using a fluent builder.
 String getExternalTaskErrorDetails(String externalTaskId)
          Returns the full error details that occurred while running external task with the given id.
 void handleBpmnError(String externalTaskId, String workerId, String errorCode)
          Signals that an business error appears, which should be handled by the process engine.
 void handleFailure(String externalTaskId, String workerId, String errorMessage, int retries, long retryDuration)
          Signals that an external task could not be successfully executed.
 void handleFailure(String externalTaskId, String workerId, String errorMessage, String errorDetails, int retries, long retryDuration)
          Signals that an external task could not be successfully executed.
 void setPriority(String externalTaskId, long priority)
          Sets the priority for an external task.
 void setRetries(List<String> externalTaskIds, int retries)
          Sets the retries for external tasks.
 void setRetries(String externalTaskId, int retries)
          Sets the retries for an external task.
 void setRetries(String externalTaskId, int retries, boolean writeUserOperationLog)
           
 Batch setRetriesAsync(List<String> externalTaskIds, ExternalTaskQuery externalTaskQuery, int retries)
          Sets the retries for external tasks asynchronously as batch.
 void unlock(String externalTaskId)
          Unlocks an external task instance.
 UpdateExternalTaskRetriesSelectBuilder updateRetries()
          Sets the retries for external tasks using a fluent builder.
 
Methods inherited from class org.camunda.bpm.engine.impl.ServiceImpl
getCommandExecutor, setCommandExecutor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExternalTaskServiceImpl

public ExternalTaskServiceImpl()
Method Detail

fetchAndLock

public ExternalTaskQueryBuilder fetchAndLock(int maxTasks,
                                             String workerId)
Description copied from interface: ExternalTaskService
Calls method fetchAndLock(maxTasks, workerId, usePriority), where usePriority is false.

Specified by:
fetchAndLock in interface ExternalTaskService
Parameters:
maxTasks - the maximum number of tasks to return
workerId - the id of the worker to lock the tasks for
Returns:
a builder to define and execute an external task fetching operation
See Also:
ExternalTaskService#fetchAndLock(int, java.lang.String, boolean)}.

fetchAndLock

public ExternalTaskQueryBuilder fetchAndLock(int maxTasks,
                                             String workerId,
                                             boolean usePriority)
Description copied from interface: ExternalTaskService

Defines fetching of external tasks by using a fluent builder. The following parameters must be specified: A worker id, a maximum number of tasks to fetch and a flag that indicates whether priority should be regarded or not. The builder allows to specify multiple topics to fetch tasks for and individual lock durations. For every topic, variables can be fetched in addition.Is the priority enabled the tasks with the highest priority are fetched.

Returned tasks are locked for the given worker until now + lockDuration expires. Locked tasks cannot be fetched or completed by other workers. When the lock time has expired, a task may be fetched and locked by other workers.

Returns at most maxTasks tasks. The tasks are arbitrarily distributed among the specified topics. Example: Fetching 10 tasks of topics "a"/"b"/"c" may return 3/3/4 tasks, or 10/0/0 tasks, etc.

May return less than maxTasks tasks, if there exist not enough unlocked tasks matching the provided topics or if parallel fetching by other workers results in locking failures.

Returns only tasks that the currently authenticated user has at least one permission out of all of the following groups for:

Specified by:
fetchAndLock in interface ExternalTaskService
Parameters:
maxTasks - the maximum number of tasks to return
workerId - the id of the worker to lock the tasks for
usePriority - the flag to enable the priority fetching mechanism
Returns:
a builder to define and execute an external task fetching operation

complete

public void complete(String externalTaskId,
                     String workerId)
Description copied from interface: ExternalTaskService

Completes an external task on behalf of a worker. The given task must be assigned to the worker.

Specified by:
complete in interface ExternalTaskService
Parameters:
externalTaskId - the id of the external to complete
workerId - the id of the worker that completes the task

complete

public void complete(String externalTaskId,
                     String workerId,
                     Map<String,Object> variables)
Description copied from interface: ExternalTaskService

Completes an external task on behalf of a worker and submits variables to the process instance before continuing execution. The given task must be assigned to the worker.

Specified by:
complete in interface ExternalTaskService
Parameters:
externalTaskId - the id of the external to complete
workerId - the id of the worker that completes the task
variables - a map of variables to set on the execution (non-local) the external task is assigned to

handleFailure

public void handleFailure(String externalTaskId,
                          String workerId,
                          String errorMessage,
                          int retries,
                          long retryDuration)
Description copied from interface: ExternalTaskService

Signals that an external task could not be successfully executed. The task must be assigned to the given worker. The number of retries left can be specified. In addition, a timeout can be provided, such that the task cannot be fetched before now + retryTimeout again.

If retries is 0, an incident with the given error message is created. The incident gets resolved, once the number of retries is increased again.

Specified by:
handleFailure in interface ExternalTaskService
Parameters:
externalTaskId - the id of the external task to report a failure for
workerId - the id of the worker that reports the failure
errorMessage - short error message related to this failure. This message can be retrieved via ExternalTask.getErrorMessage() and is used as the incident message in case retries is null. May be null.
retries - the number of retries left. External tasks with 0 retries cannot be fetched anymore unless the number of retries is increased via API. Must be >= 0.
retryDuration - the timeout before the task can be fetched again. Must be >= 0.

handleFailure

public void handleFailure(String externalTaskId,
                          String workerId,
                          String errorMessage,
                          String errorDetails,
                          int retries,
                          long retryDuration)
Description copied from interface: ExternalTaskService

Signals that an external task could not be successfully executed. The task must be assigned to the given worker. The number of retries left can be specified. In addition, a timeout can be provided, such that the task cannot be fetched before now + retryTimeout again.

If retries is 0, an incident with the given error message is created. The incident gets resolved, once the number of retries is increased again.

Specified by:
handleFailure in interface ExternalTaskService
Parameters:
externalTaskId - the id of the external task to report a failure for
workerId - the id of the worker that reports the failure
errorMessage - short error message related to this failure. This message can be retrieved via ExternalTask.getErrorMessage() and is used as the incident message in case retries is null. May be null.
errorDetails - full error message related to this failure. This message can be retrieved via ExternalTaskService.getExternalTaskErrorDetails(String) ()}
retries - the number of retries left. External tasks with 0 retries cannot be fetched anymore unless the number of retries is increased via API. Must be >= 0.
retryDuration - the timeout before the task can be fetched again. Must be >= 0.

handleBpmnError

public void handleBpmnError(String externalTaskId,
                            String workerId,
                            String errorCode)
Description copied from interface: ExternalTaskService

Signals that an business error appears, which should be handled by the process engine. The task must be assigned to the given worker. The error will be propagated to the next error handler. Is no existing error handler for the given bpmn error the activity instance of the external task ends.

Specified by:
handleBpmnError in interface ExternalTaskService
Parameters:
externalTaskId - the id of the external task to report a bpmn error
workerId - the id of the worker that reports the bpmn error
errorCode - the error code of the corresponding bmpn error

unlock

public void unlock(String externalTaskId)
Description copied from interface: ExternalTaskService
Unlocks an external task instance.

Specified by:
unlock in interface ExternalTaskService
Parameters:
externalTaskId - the id of the task to unlock

setRetries

public void setRetries(String externalTaskId,
                       int retries,
                       boolean writeUserOperationLog)

setPriority

public void setPriority(String externalTaskId,
                        long priority)
Description copied from interface: ExternalTaskService
Sets the priority for an external task.

Specified by:
setPriority in interface ExternalTaskService
Parameters:
externalTaskId - the id of the task to set the
priority - the new priority of the task

createExternalTaskQuery

public ExternalTaskQuery createExternalTaskQuery()
Description copied from interface: ExternalTaskService

Queries for tasks that the currently authenticated user has at least one of the following permissions for:

Specified by:
createExternalTaskQuery in interface ExternalTaskService
Returns:
a new ExternalTaskQuery that can be used to dynamically query for external tasks.

getExternalTaskErrorDetails

public String getExternalTaskErrorDetails(String externalTaskId)
Description copied from interface: ExternalTaskService
Returns the full error details that occurred while running external task with the given id. Returns null when the external task has no error details.

Specified by:
getExternalTaskErrorDetails in interface ExternalTaskService
Parameters:
externalTaskId - id of the external task, cannot be null.

setRetries

public void setRetries(String externalTaskId,
                       int retries)
Description copied from interface: ExternalTaskService
Sets the retries for an external task. If the new value is 0, a new incident with a null message is created. If the old value is 0 and the new value is greater than 0, an existing incident is resolved.

Specified by:
setRetries in interface ExternalTaskService
Parameters:
externalTaskId - the id of the task to set the

setRetries

public void setRetries(List<String> externalTaskIds,
                       int retries)
Description copied from interface: ExternalTaskService
Sets the retries for external tasks. If the new value is 0, a new incident with a null message is created. If the old value is 0 and the new value is greater than 0, an existing incident is resolved.

Specified by:
setRetries in interface ExternalTaskService
Parameters:
externalTaskIds - the ids of the tasks to set the

setRetriesAsync

public Batch setRetriesAsync(List<String> externalTaskIds,
                             ExternalTaskQuery externalTaskQuery,
                             int retries)
Description copied from interface: ExternalTaskService
Sets the retries for external tasks asynchronously as batch. The returned batch can be used to track the progress. If the new value is 0, a new incident with a null message is created. If the old value is 0 and the new value is greater than 0, an existing incident is resolved.

Specified by:
setRetriesAsync in interface ExternalTaskService
Parameters:
externalTaskIds - the ids of the tasks to set the
externalTaskQuery - a query which selects the external tasks to set the retries for.
Returns:
the batch

updateRetries

public UpdateExternalTaskRetriesSelectBuilder updateRetries()
Description copied from interface: ExternalTaskService
Sets the retries for external tasks using a fluent builder. Specify the instances by calling one of the following methods, like externalTaskIds. To set the retries call UpdateExternalTaskRetriesBuilder.set(int) or UpdateExternalTaskRetriesBuilder.setAsync(int).

Specified by:
updateRetries in interface ExternalTaskService

extendLock

public void extendLock(String externalTaskId,
                       String workerId,
                       long lockDuration)
Description copied from interface: ExternalTaskService

Extends a lock of an external task on behalf of a worker. The given task must be assigned to the worker.

Specified by:
extendLock in interface ExternalTaskService
Parameters:
externalTaskId - the id of the external task
workerId - the id of the worker that extends the lock of the task


Copyright © 2017 camunda services GmbH. All rights reserved.