protected ProcessDefinitionEntity findByKey(DeploymentCache deploymentCache, String processDefinitionKey) { if (isTenantIdSet) { return deploymentCache.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, processDefinitionTenantId); } else { return deploymentCache.findDeployedLatestProcessDefinitionByKey(processDefinitionKey); } }
protected void ensureCaseDefinitionInitialized() { if ((caseDefinition == null) && (caseDefinitionId != null)) { CaseDefinitionEntity deployedCaseDefinition = Context .getProcessEngineConfiguration() .getDeploymentCache() .getCaseDefinitionById(caseDefinitionId); setCaseDefinition(deployedCaseDefinition); } }
protected void initDeployers() { if (this.deployers == null) { this.deployers = new ArrayList<Deployer>(); if (customPreDeployers != null) { this.deployers.addAll(customPreDeployers); } this.deployers.addAll(getDefaultDeployers()); if (customPostDeployers != null) { this.deployers.addAll(customPostDeployers); } } if (deploymentCache == null) { List<Deployer> deployers = new ArrayList<Deployer>(); if (customPreDeployers != null) { deployers.addAll(customPreDeployers); } deployers.addAll(getDefaultDeployers()); if (customPostDeployers != null) { deployers.addAll(customPostDeployers); } initCacheFactory(); deploymentCache = new DeploymentCache(cacheFactory, cacheCapacity); deploymentCache.setDeployers(deployers); } }
public CachePurgeReport purgeCache() { Cache<String, ProcessDefinitionEntity> processDefinitionCache = getProcessDefinitionCache(); if (!processDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.PROCESS_DEF_CACHE, processDefinitionCache.keySet()); Cache<String, BpmnModelInstance> bpmnModelInstanceCache = getBpmnModelInstanceCache(); if (!bpmnModelInstanceCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.BPMN_MODEL_INST_CACHE, bpmnModelInstanceCache.keySet()); Cache<String, CaseDefinitionEntity> caseDefinitionCache = getCaseDefinitionCache(); if (!caseDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.CASE_DEF_CACHE, caseDefinitionCache.keySet()); Cache<String, CmmnModelInstance> cmmnModelInstanceCache = getCmmnModelInstanceCache(); if (!cmmnModelInstanceCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.CASE_MODEL_INST_CACHE, cmmnModelInstanceCache.keySet()); Cache<String, DecisionDefinitionEntity> decisionDefinitionCache = getDecisionDefinitionCache(); if (!decisionDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.DMN_DEF_CACHE, decisionDefinitionCache.keySet()); Cache<String, DmnModelInstance> dmnModelInstanceCache = getDmnDefinitionCache(); if (!dmnModelInstanceCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.DMN_MODEL_INST_CACHE, dmnModelInstanceCache.keySet()); Cache<String, DecisionRequirementsDefinitionEntity> decisionRequirementsDefinitionCache = getDecisionRequirementsDefinitionCache(); if (!decisionRequirementsDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.DMN_REQ_DEF_CACHE, decisionRequirementsDefinitionCache.keySet());
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml", "org/camunda/bpm/engine/test/repository/one.cmmn"}) public void testDeleteDeploymentClearsCache() { // fetch definition ids String processDefinitionId = repositoryService.createProcessDefinitionQuery().singleResult().getId(); String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId(); // fetch CMMN model to be placed to in the cache repositoryService.getCmmnModelInstance(caseDefinitionId); DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); // ensure definitions and models are part of the cache assertNotNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNotNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); assertNotNull(deploymentCache.getCaseDefinitionCache().get(caseDefinitionId)); assertNotNull(deploymentCache.getCmmnModelInstanceCache().get(caseDefinitionId)); // when the deployment is deleted repositoryService.deleteDeployment(deploymentId, true); // then the definitions and models are removed from the cache assertNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); assertNull(deploymentCache.getCaseDefinitionCache().get(caseDefinitionId)); assertNull(deploymentCache.getCmmnModelInstanceCache().get(caseDefinitionId)); }
@Test public void testPlugInOwnCacheImplementation() { // given DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); // when Cache<String, ProcessDefinitionEntity> cache = deploymentCache.getProcessDefinitionCache(); // then assertThat(cache, instanceOf(MyCacheImplementation.class)); }
@Test public void testDeleteProcessDefinitionClearsCache() { // given process definition and a process instance BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done(); deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", bpmnModel) .deploy(); String processDefinitionId = repositoryService.createProcessDefinitionQuery() .processDefinitionKey("process") .singleResult() .getId(); DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); // ensure definitions and models are part of the cache assertNotNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNotNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); repositoryService.deleteProcessDefinition(processDefinitionId, true); // then the definitions and models are removed from the cache assertNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); }
@Test public void testDeleteProcessDefinitionAndRefillDeploymentCache() { // given a deployment with two process definitions in one xml model file deployment = repositoryService.createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/repository/twoProcesses.bpmn20.xml") .deploy(); ProcessDefinition processDefinitionOne = repositoryService.createProcessDefinitionQuery().processDefinitionKey("one").singleResult(); ProcessDefinition processDefinitionTwo = repositoryService.createProcessDefinitionQuery().processDefinitionKey("two").singleResult(); String idOne = processDefinitionOne.getId(); //one is deleted from the deployment repositoryService.deleteProcessDefinition(idOne); //when clearing the deployment cache processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); //then creating process instance from the existing process definition ProcessInstanceWithVariables procInst = runtimeService.createProcessInstanceByKey("two").executeWithVariablesInReturn(); assertNotNull(procInst); assertTrue(procInst.getProcessDefinitionId().contains("two")); //should refill the cache Cache cache = processEngineConfiguration.getDeploymentCache().getProcessDefinitionCache(); assertNotNull(cache.get(processDefinitionTwo.getId())); //The deleted process definition should not be recreated after the cache is refilled assertNull(cache.get(processDefinitionOne.getId())); }
@Override public ProcessDefinitionEntity execute(CommandContext commandContext) { return Context.getProcessEngineConfiguration() .getDeploymentCache() .findDeployedLatestProcessDefinitionByKey("myProcess"); } });
@Test public void testDisableQueryOfProcessDefinitionAddModelInstancesToDeploymentCache() { // given deploy(ProcessModels.ONE_TASK_PROCESS_WITH_DOCUMENTATION); ProcessInstance pi = runtimeService.startProcessInstanceByKey(ProcessModels.PROCESS_KEY); // when repositoryService.createProcessDefinitionQuery() .processDefinitionKey(ProcessModels.PROCESS_KEY) .singleResult() .getId(); // then DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); BpmnModelInstance modelInstance = deploymentCache.getBpmnModelInstanceCache().get(pi.getProcessDefinitionId()); assertNull(modelInstance); }
@Override protected void addDefinitionToDeploymentCache(DeploymentCache deploymentCache, DecisionRequirementsDefinitionEntity definition) { if (isDecisionRequirementsDefinitionPersistable(definition)) { deploymentCache.addDecisionRequirementsDefinition(definition); } }
@Override protected void addDefinitionToDeploymentCache(DeploymentCache deploymentCache, CaseDefinitionEntity definition) { deploymentCache.addCaseDefinition(definition); }
@Override protected void addDefinitionToDeploymentCache(DeploymentCache deploymentCache, DecisionDefinitionEntity definition) { deploymentCache.addDecisionDefinition(definition); }
public CachePurgeReport purgeCache() { Cache<String, ProcessDefinitionEntity> processDefinitionCache = getProcessDefinitionCache(); if (!processDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.PROCESS_DEF_CACHE, processDefinitionCache.keySet()); Cache<String, BpmnModelInstance> bpmnModelInstanceCache = getBpmnModelInstanceCache(); if (!bpmnModelInstanceCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.BPMN_MODEL_INST_CACHE, bpmnModelInstanceCache.keySet()); Cache<String, CaseDefinitionEntity> caseDefinitionCache = getCaseDefinitionCache(); if (!caseDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.CASE_DEF_CACHE, caseDefinitionCache.keySet()); Cache<String, CmmnModelInstance> cmmnModelInstanceCache = getCmmnModelInstanceCache(); if (!cmmnModelInstanceCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.CASE_MODEL_INST_CACHE, cmmnModelInstanceCache.keySet()); Cache<String, DecisionDefinitionEntity> decisionDefinitionCache = getDecisionDefinitionCache(); if (!decisionDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.DMN_DEF_CACHE, decisionDefinitionCache.keySet()); Cache<String, DmnModelInstance> dmnModelInstanceCache = getDmnDefinitionCache(); if (!dmnModelInstanceCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.DMN_MODEL_INST_CACHE, dmnModelInstanceCache.keySet()); Cache<String, DecisionRequirementsDefinitionEntity> decisionRequirementsDefinitionCache = getDecisionRequirementsDefinitionCache(); if (!decisionRequirementsDefinitionCache.isEmpty()) { result.addPurgeInformation(CachePurgeReport.DMN_REQ_DEF_CACHE, decisionRequirementsDefinitionCache.keySet());
@Deployment(resources = { "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml", "org/camunda/bpm/engine/test/repository/one.cmmn"}) public void testDeleteDeploymentClearsCache() { // fetch definition ids String processDefinitionId = repositoryService.createProcessDefinitionQuery().singleResult().getId(); String caseDefinitionId = repositoryService.createCaseDefinitionQuery().singleResult().getId(); // fetch CMMN model to be placed to in the cache repositoryService.getCmmnModelInstance(caseDefinitionId); DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); // ensure definitions and models are part of the cache assertNotNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNotNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); assertNotNull(deploymentCache.getCaseDefinitionCache().get(caseDefinitionId)); assertNotNull(deploymentCache.getCmmnModelInstanceCache().get(caseDefinitionId)); // when the deployment is deleted repositoryService.deleteDeployment(deploymentId, true); // then the definitions and models are removed from the cache assertNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); assertNull(deploymentCache.getCaseDefinitionCache().get(caseDefinitionId)); assertNull(deploymentCache.getCmmnModelInstanceCache().get(caseDefinitionId)); }
protected ActivityImpl findActivityInDeployedProcessDefinition(String activityId) { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertNotNull(processDefinition); ProcessDefinitionEntity cachedProcessDefinition = processEngineConfiguration.getDeploymentCache() .getProcessDefinitionCache() .get(processDefinition.getId()); return cachedProcessDefinition.findActivity(activityId); }
@Test public void testDeleteProcessDefinitionClearsCache() { // given process definition and a process instance BpmnModelInstance bpmnModel = Bpmn.createExecutableProcess("process").startEvent().userTask().endEvent().done(); deployment = repositoryService.createDeployment() .addModelInstance("process.bpmn", bpmnModel) .deploy(); String processDefinitionId = repositoryService.createProcessDefinitionQuery() .processDefinitionKey("process") .singleResult() .getId(); DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); // ensure definitions and models are part of the cache assertNotNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNotNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); repositoryService.deleteProcessDefinition(processDefinitionId, true); // then the definitions and models are removed from the cache assertNull(deploymentCache.getProcessDefinitionCache().get(processDefinitionId)); assertNull(deploymentCache.getBpmnModelInstanceCache().get(processDefinitionId)); }
processEngineConfiguration.getDeploymentCache().discardProcessDefinitionCache(); Cache cache = processEngineConfiguration.getDeploymentCache().getProcessDefinitionCache(); assertNotNull(cache.get(version2.getId())); assertNull(cache.get(version1.getId()));
@Override public ProcessDefinitionEntity execute(CommandContext commandContext) { return Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedLatestProcessDefinitionByKey("myProcess"); } });
@Test public void testEnableQueryOfProcessDefinitionAddModelInstancesToDeploymentCache() { // given deploy(ProcessModels.ONE_TASK_PROCESS_WITH_DOCUMENTATION); processEngineConfiguration.setEnableFetchProcessDefinitionDescription(true); ProcessInstance pi = runtimeService.startProcessInstanceByKey(ProcessModels.PROCESS_KEY); // when repositoryService.createProcessDefinitionQuery() .processDefinitionKey(ProcessModels.PROCESS_KEY) .singleResult() .getId(); // then DeploymentCache deploymentCache = processEngineConfiguration.getDeploymentCache(); BpmnModelInstance modelInstance = deploymentCache.getBpmnModelInstanceCache().get(pi.getProcessDefinitionId()); assertNotNull(modelInstance); }