activiti流程部署代码走读

activiti 流程部署

  1. activiti流程部署调用RepositoryService.createDeployment().deploy()

RepositoryService.createDeployment()返回DeploymentBuilder对象,DeploymentBuilder是部署管理接口。

DeploymentBuilder.deploy()是部署接口,返回DeploymentDeployment里面包含部署ID、名字、部署时间。DeploymentBuilder部分代码如下所示:

  public interface DeploymentBuilder {
    /**
     * Deploys all provided sources to the Activiti engine.
     */
    Deployment deploy();

  }
  • DeploymentBuilderImpl实现了接口DeploymentBuilderDeploymentBuilderImpl.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之前,切入了拦截器LogInterceptorSpringTransactionInterceptorCommandContextInterceptorLogInterceptor是日志拦截器,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管理部署接口DeployerDeployer实现类有BpmnDeployerRulesDeployerBpmnDeployer负责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图片,最后将它们存入到数据库中,完成整个流程的部署。流程部署主要的调用顺序如下:

调用顺序

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • Engine解析 1. org.activiti.engine 定义了流程管理服务的接口:RepositorySe...
    西普士阅读 8,109评论 0 24
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,779评论 18 399
  • 最近做了一次对企业/云平台级工作流引擎Activiti的调查: TA,系出名门——由JBoss公司jBPM4引擎的...
    天空之诚阅读 25,484评论 7 93
  • 我愿双手托起明天的太阳 明天的太阳普照万丈光芒 万丈光芒洒在故乡的土地上 故乡的土地上充满了鸟语花香 鸟语花香构成...
    八代目阅读 170评论 0 0