Information Technology Reference
In-Depth Information
public <T> T execute(Command<T> command) {
String userId = getUserId(command);
String operation = getOperationName(command);
if (userId != null) {
logs.add(new OperationLog(userId, operation));
}
return executeNext(command);
}
Later on, in the HumanTaskInterceptorTest class, we can see that we register it
and check its logs after every user action to see that they are correctly populated. The Hu-
manTaskServiceFactory class provides a method to configure interceptor objects
inside your task service's implementation. The code to configure them looks like the fol-
lowing code snippet:
TaskService taskService = HumanTaskServiceFactory.
newTaskServiceConfigurator().
entityManagerFactory(emf).
userGroupCallback(ugCallback).
interceptor(priority, new UserLogInterceptor()).
getTaskService();
In the preceding code, the priority variable is an integer that defines in what place this
interceptor will be in the chain of interceptors that a task service instance could have.
Note
It is not recommended to add a new interceptor to an already existing task service, due to
it being an internal component of the implementation of the TaskService interface.
When to use task event listeners or interceptors
Whether to use interceptors or task life cycle event listeners is a tough discussion, but the
best rule of thumb to make a decision in that aspect is to consider transaction manage-
ment.
Task life cycle event listeners provide a simple connection point. However, this extension
point is usually detached from the invocation stack. It will be solely invoked from inside
the task service when the task service finds a change in a task. It is great to connect ex-
Search WWH ::




Custom Search