工作流系列--CommandContextInterceptor分析

Posted by 张伟真 on 2024-11-03
Estimated Reading Time 1 Minutes
Words 309 In Total
Viewed Times

#工作流系列–CommandContextInterceptor分析
上一篇分析 ProcessEngineAutoConfiguration时,在流程初始化的时候有加载的拦截器链中,加载了拦截器CommandContextInterceptor
今天我们就来讲讲CommandContextInterceptor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public Collection<? extends CommandInterceptor> getDefaultCommandInterceptors() {
List<CommandInterceptor> interceptors = new ArrayList<CommandInterceptor>();
interceptors.add(new LogInterceptor());

CommandInterceptor transactionInterceptor = createTransactionInterceptor();
if (transactionInterceptor != null) {
interceptors.add(transactionInterceptor);
}

if (commandContextFactory != null) {
interceptors.add(new CommandContextInterceptor(commandContextFactory, this));
}

if (transactionContextFactory != null) {
interceptors.add(new TransactionContextInterceptor(transactionContextFactory));
}

return interceptors;
}

默认拦截器链里面new 了一个CommandContextInterceptor, 执行时做了几件事

  1. 会设置一个CommandContext, 当CommandContext不存在则new一个,不为空则设置reused为true
  2. 将刚取到的CommandContext压入栈中
  3. 将当前processEngineConfiguration压入下一个栈中
  4. 执行调用下一个拦截器
    也就是说,每个命令执行前,都会经过当前执行,并且都拥有了CommandContext
    CommandContextInterceptor
    CommandContextInterceptor
    CommandContext中有有对应的命令,还有一个ActivitiEngineAgenda, agenda是流程流转的核心类
    CommandContextInterceptor

Command命令模式

activiti使用命令模式,将操作以及与之相关的信息都封装成命令,所以在源码里面会看到非常多的Command实现类,这说明我们在开发或者定制一些操作的时候也可以封装一个命令去执行
CommandContextInterceptor


如果您喜欢此博客或发现它对您有用,则欢迎对此发表评论。 也欢迎您共享此博客,以便更多人可以参与。 如果博客中使用的图像侵犯了您的版权,请与作者联系以将其删除。 谢谢 !