ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Flowable源码注释(二十三)部署管理器

2022-02-07 20:35:49  阅读:288  来源: 互联网

标签:definition 管理器 definitionKey Flowable flowable deploymentId 源码 null public


Flowable源码地址:https://github.com/flowable/flowable-engine

Flowable-6.7.2 源码注释地址:https://github.com/solojin/flowable-6.7.2-annotated

包路径 org.flowable.dmn.engine.impl.persistence.deploy

DeploymentManager 部署管理器

package org.flowable.dmn.engine.impl.persistence.deploy;

import java.util.List;
import java.util.Map;

import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache;
import org.flowable.dmn.api.DmnDecision;
import org.flowable.dmn.engine.DmnEngineConfiguration;
import org.flowable.dmn.engine.impl.DecisionQueryImpl;
import org.flowable.dmn.engine.impl.persistence.entity.DecisionEntity;
import org.flowable.dmn.engine.impl.persistence.entity.DecisionEntityManager;
import org.flowable.dmn.engine.impl.persistence.entity.DmnDeploymentEntity;
import org.flowable.dmn.engine.impl.persistence.entity.DmnDeploymentEntityManager;
import org.flowable.dmn.engine.impl.persistence.entity.DmnResourceEntity;

/**
 * @author Tijs Rademakers
 * @author Joram Barrez
 * @author Yvo Swillens
 */
public class DeploymentManager {

    protected DmnEngineConfiguration engineConfig;
    protected DeploymentCache<DecisionCacheEntry> decisionCache;

    protected List<Deployer> deployers;
    protected DecisionEntityManager decisionEntityManager;
    protected DmnDeploymentEntityManager deploymentEntityManager;

    public DeploymentManager(DeploymentCache<DecisionCacheEntry> decisionCache, DmnEngineConfiguration engineConfig) {
        this.decisionCache = decisionCache;
        this.engineConfig = engineConfig;
    }

    public void deploy(DmnDeploymentEntity deployment) {
        deploy(deployment, null);
    }

    public void deploy(DmnDeploymentEntity deployment, Map<String, Object> deploymentSettings) {
        for (Deployer deployer : deployers) {
            deployer.deploy(deployment, deploymentSettings);
        }
    }

    public DecisionEntity findDeployedDecisionById(String decisionId) {
        if (decisionId == null) {
            // 非法决策ID值:空值
            throw new FlowableException("Invalid decision id : null");
        }

        // 首先尝试缓存
        DecisionCacheEntry cacheEntry = decisionCache.get(decisionId);
        DecisionEntity decision = cacheEntry != null ? cacheEntry.getDecisionEntity() : null;

        if (decision == null) {
            decision = engineConfig.getDecisionEntityManager().findById(decisionId);
            if (decision == null) {
                throw new FlowableObjectNotFoundException("no decision found with id '" + decisionId + "'");
            }
            decision = resolveDecision(decision).getDecisionEntity();
        }
        return decision;
    }

    public DecisionEntity findDeployedLatestDefinitionByKey(String definitionKey) {
        DecisionEntity definition = decisionEntityManager.findLatestDecisionByKey(definitionKey);

        if (definition == null) {
            throw new FlowableObjectNotFoundException("no decisions deployed with key '" + definitionKey + "'");
        }
        definition = resolveDecision(definition).getDecisionEntity();
        return definition;
    }

    public DecisionEntity findDeployedLatestDefinitionByKeyAndTenantId(String definitionKey, String tenantId) {
        DecisionEntity definition = decisionEntityManager.findLatestDecisionByKeyAndTenantId(definitionKey, tenantId);

        if (definition == null) {
            throw new FlowableObjectNotFoundException("no decisions deployed with key '" + definitionKey + "' for tenant identifier '" + tenantId + "'");
        }
        definition = resolveDecision(definition).getDecisionEntity();
        return definition;
    }

    public DecisionEntity findDeployedLatestDecisionByKeyAndDeploymentId(String definitionKey, String deploymentId) {
        DecisionEntity definition = decisionEntityManager.findDecisionByDeploymentAndKey(deploymentId, definitionKey);

        if (definition == null) {
            throw new FlowableObjectNotFoundException("no decisions deployed with key '" + definitionKey +
                            "' for deployment id '" + deploymentId + "'");
        }
        definition = resolveDecision(definition).getDecisionEntity();
        return definition;
    }

    public DecisionEntity findDeployedLatestDecisionByKeyDeploymentIdAndTenantId(String definitionKey,
            String deploymentId, String tenantId) {
        DecisionEntity definition = decisionEntityManager.findDecisionByDeploymentAndKeyAndTenantId(deploymentId, definitionKey, tenantId);

        if (definition == null) {
            throw new FlowableObjectNotFoundException("no decisions deployed with key '" + definitionKey +
                            "' for deployment id '" + deploymentId + "' and tenant identifier " + tenantId);
        }
        definition = resolveDecision(definition).getDecisionEntity();
        return definition;
    }

    public DecisionEntity findDeployedDefinitionByKeyAndVersionAndTenantId(String definitionKey, int definitionVersion, String tenantId) {
        DecisionEntity definition = decisionEntityManager.findDecisionByKeyAndVersionAndTenantId(definitionKey, definitionVersion, tenantId);

        if (definition == null) {
            throw new FlowableObjectNotFoundException("no decision deployed with key = '" + definitionKey + "' and version = '" + definitionVersion + "'");
        }

        definition = resolveDecision(definition).getDecisionEntity();
        return definition;
    }

    /**
     * 解析决策获取DMN,解析它并将Dmn定义{@ link org.flowable.DMN.model.DmnDefinition }存储在内存中。
     */
    public DecisionCacheEntry resolveDecision(DmnDecision decision) {
        String decisionId = decision.getId();
        String deploymentId = decision.getDeploymentId();

        DecisionCacheEntry cachedDecision = decisionCache.get(decisionId);

        if (cachedDecision == null) {
            DmnDeploymentEntity deployment = engineConfig.getDeploymentEntityManager().findById(deploymentId);
            List<DmnResourceEntity> resources = engineConfig.getResourceEntityManager().findResourcesByDeploymentId(deploymentId);
            for (DmnResourceEntity resource : resources) {
                deployment.addResource(resource);
            }

            deployment.setNew(false);
            deploy(deployment, null);
            cachedDecision = decisionCache.get(decisionId);

            if (cachedDecision == null) {
                throw new FlowableException("deployment '" + deploymentId + "' didn't put decision '" + decisionId + "' in the cache");
            }
        }
        return cachedDecision;
    }

    public void removeDeployment(String deploymentId) {

        DmnDeploymentEntity deployment = deploymentEntityManager.findById(deploymentId);
        if (deployment == null) {
            throw new FlowableObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.");
        }

        // 从缓存中删除任何dmn定义
        List<DmnDecision> definitions = new DecisionQueryImpl().deploymentId(deploymentId).list();

        // 删除数据
        deploymentEntityManager.deleteDeployment(deploymentId);

        for (DmnDecision definition : definitions) {
            decisionCache.remove(definition.getId());
        }
    }

    public List<Deployer> getDeployers() {
        return deployers;
    }

    public void setDeployers(List<Deployer> deployers) {
        this.deployers = deployers;
    }

    public DeploymentCache<DecisionCacheEntry> getDecisionCache() {
        return decisionCache;
    }

    public void setDecisionCache(DeploymentCache<DecisionCacheEntry> decisionCache) {
        this.decisionCache = decisionCache;
    }

    public DecisionEntityManager getDecisionEntityManager() {
        return decisionEntityManager;
    }

    public void setDecisionEntityManager(DecisionEntityManager decisionEntityManager) {
        this.decisionEntityManager = decisionEntityManager;
    }

    public DmnDeploymentEntityManager getDeploymentEntityManager() {
        return deploymentEntityManager;
    }

    public void setDeploymentEntityManager(DmnDeploymentEntityManager deploymentEntityManager) {
        this.deploymentEntityManager = deploymentEntityManager;
    }
}

标签:definition,管理器,definitionKey,Flowable,flowable,deploymentId,源码,null,public
来源: https://blog.csdn.net/JinYJ2014/article/details/122814104

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有