activiti部署流程deployment实现源码实现过程

以下是流程部署的实现过程,看了一天源码了解了activiti源码是如何实现的,包括数据数据,了解activiti的架构

//根据bpmn文件部署流程
Deployment deployment = repositoryService.createDeployment().addClasspathResource("diagrams/demo2.bpmn").deploy();

 调用顺序

//RepositoryServiceImpl类的方法
public Deployment deploy(DeploymentBuilderImpl deploymentBuilder) {
        return (Deployment)this.commandExecutor.execute(new DeployCmd(deploymentBuilder));
    }


//CommandExecutorImpl类的方法
public <T> T execute(Command<T> command) {
        return this.execute(this.defaultConfig, command);
    }

public <T> T execute(CommandConfig config, Command<T> command) {
        return this.first.execute(config, command);
    }

这里的命令执行器CommandExecutorImpl属性first是接口CommandInterceptor,执行顺序是LogInterceptor、SpringTransactionInterceptor、XX、CommandInvoker。

LogInterceptor只是输出日志

SpringTransactionInterceptor是控制事务的,因为部署的时候会往表ACT_RE_PROCDEF、ACT_RE_DEPLOYMENT、ACT_GE_BYTEARRAY同时插入数据,保证事务完整性。

CommandContextInterceptor 

CommandInvoker是执行传入的command的excute方法,这里传入的是DeployCmd,所以去看DeployCmd的excute方法

public Deployment execute(CommandContext commandContext) {
    DeploymentEntity deployment = deploymentBuilder.getDeployment();

    deployment.setDeploymentTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());

    if ( deploymentBuilder.isDuplicateFilterEnabled() ) {
      DeploymentEntity existingDeployment = Context
        .getCommandContext()
        .getDeploymentEntityManager()
        .findLatestDeploymentByName(deployment.getName());
      
      if ( (existingDeployment!=null)
           && !deploymentsDiffer(deployment, existingDeployment)) {
        return existingDeployment;
      }
    }

    deployment.setNew(true);
    
    // Save the data
    Context
      .getCommandContext()
      .getDeploymentEntityManager()
      .insertDeployment(deployment);
    
    if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
	    Context.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
    Context
      .getProcessEngineConfiguration()
      .getDeploymentManager()
      .deploy(deployment, deploymentSettings);
    
    if (deploymentBuilder.getProcessDefinitionsActivationDate() != null) {
      scheduleProcessDefinitionActivation(commandContext, deployment);
    }
    
    if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
	    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
	    		ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, deployment));
    }
    
    return deployment;
  }
这里保存DeploymentEntity
Context.getCommandContext().getDeploymentEntityManager().insertDeployment(deployment);

再来看DbSqlSession里的insert方法,这里会把实体存入Map insertedObjec
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值