activiti 流程部署
- activiti流程部署调用
RepositoryService.createDeployment().deploy()
。
RepositoryService.createDeployment()
返回DeploymentBuilder
对象,DeploymentBuilder
是部署管理接口。
DeploymentBuilder.deploy()
是部署接口,返回Deployment
,Deployment
里面包含部署ID、名字、部署时间。DeploymentBuilder
部分代码如下所示:
public interface DeploymentBuilder {
/**
* Deploys all provided sources to the Activiti engine.
*/
Deployment deploy();
}
-
DeploymentBuilderImpl
实现了接口DeploymentBuilder
,DeploymentBuilderImpl.deploy()
方法调用了RepositoryServiceImpl.deploy()
方法。
public class DeploymentBuilderImpl implements DeploymentBuilder, Serializable {
protected transient RepositoryServiceImpl repositoryService;
public Deployment deploy() {
return repositoryService.deploy(this);
}
}
RepositoryServiceImpl.deploy()
通过命令模式调用DeployCmd.execute()
,类DeployCmd
实现了流程的部署。
public class RepositoryServiceImpl extends ServiceImpl implements RepositoryService {
public Deployment deploy(DeploymentBuilderImpl deploymentBuilder) {
return commandExecutor.execute(new DeployCmd<Deployment>(deploymentBuilder));
}
}
commandExecutor.execute
调用DeployCmd
之前,切入了拦截器LogInterceptor
、 SpringTransactionInterceptor
、 CommandContextInterceptor
。LogInterceptor
是日志拦截器,SpringTransactionInterceptor
是事务拦截器,CommandContextInterceptor
是命令拦截器,只有命令拦截器会调用DeployCmd.execute
,完成DeployCmd.execute调用之后,再将事务提交到数据库。
- 类
DeployCmd
实现Command
接口。DeployCmd
将部署文件解析成DeploymentEntity
对象,存入部署表;然后调用DeploymentManager.deploy()
方法对流程定义,资源文件进行部署。DeployCmd
的部分代码如下所示:
public class DeployCmd<T> implements Command<Deployment>, Serializable {
public Deployment execute(CommandContext commandContext) {
DeploymentEntity deployment = deploymentBuilder.getDeployment();
...
// Save the data
commandContext
.getDeploymentEntityManager()
.insertDeployment(deployment);
...
// Actually deploy
commandContext
.getProcessEngineConfiguration()
.getDeploymentManager()
.deploy(deployment, deploymentSettings);
...
}
}
- 类
DeploymentManager
管理部署接口Deployer
,Deployer
实现类有BpmnDeployer
、RulesDeployer
,BpmnDeployer
负责BPMN文件的部署,RulesDeployer
负责drl规则文件的部署。DeploymentManager
的部分代码如下所示:
public class DeploymentManager {
protected DeploymentCache<ProcessDefinitionEntity> processDefinitionCache;
protected DeploymentCache<Object> knowledgeBaseCache; // Needs to be object to avoid an import to Drools in this core class
protected List<Deployer> deployers;
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
for (Deployer deployer: deployers) {
deployer.deploy(deployment, deploymentSettings);
}
}
}
只有业务规则任务(bussinessRuleTask)才会用到drools规则,其它情况都是部署BPMN文件。BpmnDeployer
首先调用BpmnParse.execute
验证流程元素的合法性,然后解析出流程定义对象ProcessDefinitionEntity
、xml文件流、流程png图片,最后将它们存入到数据库中,完成整个流程的部署。流程部署主要的调用顺序如下: