您的位置:首页 > 其它

Activiti源码跟踪之流程部署

2017-09-07 21:51 501 查看
部署涉及到的表:ACT_GE_BYTEARRAY、ACT_RE_MODEL、ACT_RE_PROCDEF

参考:http://www.jianshu.com/p/0aeb725c1c9a

1、流程部署调用:

RepositoryService.createDeployment().deploy();




RepositoryServiceImpl的createDeployment方法返回DeploymentBuilder对象,该对象是一个部署管理接口,含有deploy()等方法。

public DeploymentBuilder createDeployment() {
return commandExecutor.execute(new Command<DeploymentBuilder>() {
@Override
public DeploymentBuilder execute(CommandContext commandContext) {
return new DeploymentBuilderImpl(RepositoryServiceImpl.this);
}
});
}


DeploymentBuilderImpl的deploy方法调用repositoryService的deploy方法:

public Deployment deploy() {
return repositoryService.deploy(this);
}


2、RepositoryServiceImpl的deploy方法通过命令模式调用
LogInterceptor
SpringTransactionInterceptor
CommandContextInterceptor
拦截器之后,最后
CommandContextInterceptor
会调用DeployCmd.execute()方法

public Deployment deploy(DeploymentBuilderImpl deploymentBuilder) {
return commandExecutor.execute(new DeployCmd<Deployment>(deploymentBuilder));
}

3、DeployCmd.execute():

部署使用DeploymentEntity对象。

public Deployment execute(CommandContext commandContext) {
......

deployment.setNew(true);

// Save the data
commandContext
.getDeploymentEntityManager()
.insertDeployment(deployment);

if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, deployment));
}

// Deployment settings
Map<String, Object> deploymentSettings = new HashMap<String, Object>();
deploymentSettings.put(DeploymentSettings.IS_BPMN20_XSD_VALIDATION_ENABLED, deploymentBuilder.isBpmn20XsdValidationEnabled());
deploymentSettings.put(DeploymentSettings.IS_PROCESS_VALIDATION_ENABLED, deploymentBuilder.isProcessValidationEnabled());

// Actually deploy
commandContext
.getProcessEngineConfiguration()
.getDeploymentManager()
.deploy(deployment, deploymentSettings);

......

}

deployment.setNew(true):第一次部署

insertDeployment(deployment):insert的是DeploymentEntity对象,存入表

deploymentSettings进行设置参数

deploy(deployment, deploymentSettings):部署

重点看下部署的方法:BpmnDeployer.deploy(deployment, deploymentSettings):方法很长,涉及到对Bpmn解析,对ProcessDefinitionEntity对象赋值,生成processDefinitionId并insert入库等一系列操作。其中最后几行代码:

public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {

4000
......

// Add to cache
DeploymentManager deploymentManager = processEngineConfiguration.getDeploymentManager();
deploymentManager.getProcessDefinitionCache().add(processDefinition.getId(), processDefinition);
addDefinitionInfoToCache(processDefinition, processEngineConfiguration, commandContext);
 ......

}


分别将processDefinition放入DeploymentCache和ProcessDefinitionInfoCache

因为流程定义的数据不会改变,为了避免每次使用流程定义时都访问数据库,所以在流程进行部署之后,生成的流程定义会放在缓存中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐