/** * Ensures that the process definition is cached in the appropriate places, including the * deployment's collection of deployed artifacts and the deployment manager's cache, as well * as caching any ProcessDefinitionInfos. */ public void updateCachingAndArtifacts(ParsedDeployment parsedDeployment) { CommandContext commandContext = Context.getCommandContext(); final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = processEngineConfiguration.getDeploymentManager().getProcessDefinitionCache(); DeploymentEntity deployment = parsedDeployment.getDeployment(); for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) { BpmnModel bpmnModel = parsedDeployment.getBpmnModelForProcessDefinition(processDefinition); Process process = parsedDeployment.getProcessModelForProcessDefinition(processDefinition); ProcessDefinitionCacheEntry cacheEntry = new ProcessDefinitionCacheEntry(processDefinition, bpmnModel, process); processDefinitionCache.add(processDefinition.getId(), cacheEntry); addDefinitionInfoToCache(processDefinition, processEngineConfiguration, commandContext); // Add to deployment for further usage deployment.addDeployedArtifact(processDefinition); } }
public static BpmnModel getBpmnModelFromCache(String processDefinitionId) { ProcessDefinitionCacheEntry cacheEntry = Context.getProcessEngineConfiguration().getProcessDefinitionCache().get(processDefinitionId); if (cacheEntry != null) { return cacheEntry.getBpmnModel(); } return null; }
protected void changeProcessDefinitionState(CommandContext commandContext, List<ProcessDefinitionEntity> processDefinitions) { for (ProcessDefinitionEntity processDefinition : processDefinitions) { SuspensionStateUtil.setSuspensionState(processDefinition, getProcessDefinitionSuspensionState()); // Evict cache commandContext.getProcessEngineConfiguration().getDeploymentManager().getProcessDefinitionCache().remove(processDefinition.getId()); // Suspend process instances (if needed) if (includeProcessInstances) { int currentStartIndex = 0; List<ProcessInstance> processInstances = fetchProcessInstancesPage(commandContext, processDefinition, currentStartIndex); while (!processInstances.isEmpty()) { for (ProcessInstance processInstance : processInstances) { AbstractSetProcessInstanceStateCmd processInstanceCmd = getProcessInstanceChangeStateCmd(processInstance); processInstanceCmd.execute(commandContext); } // Fetch new batch of process instances currentStartIndex += processInstances.size(); processInstances = fetchProcessInstancesPage(commandContext, processDefinition, currentStartIndex); } } } }
public Object getInstance(String deploymentId, String resource) { // First find in cache DeploymentCache<Object> deploymentCache = cacheInstance.get(deploymentId); if (deploymentCache == null) { deploymentCache = new DefaultDeploymentCache<Object>(); cacheInstance.put(deploymentId, deploymentCache); } Object instance = deploymentCache.get(resource); if (instance == null) { @SuppressWarnings("rawtypes") ProjectEngineFactory projectEngineFactory = get(deploymentId, resource); try { instance = projectEngineFactory.newInstance(); } catch (Exception e) { throw new ResourceCompileException( "Resource with name '" + resource + "' in deployment with id '" + deploymentId + "' compilation has been failed"); } deploymentCache.add(resource, instance); } return instance; }
protected ClassLoader resolveProcessArchiveClassLoader() { final DeploymentCache deploymentCache = Context.getProcessEngineConfiguration().getDeploymentCache(); final ExecutionContext executionContext = getExecutionContext(); if (executionContext != null) { String processDefinitionId = executionContext.getProcessInstance().getProcessDefinitionId(); // check whether the process definition is deployed to the cache. // if the process definition is not deployed to the cache, we do not attempt // to resolve the deploymentClassloader since the process archive is undeployed. if (deploymentCache.getProcessDefinitionCache().containsKey(processDefinitionId)) { String processDefinitionKey = executionContext.getProcessDefinition().getKey(); // look up the classloader for that processDefinition: return deploymentClassloaderMap.get(processDefinitionKey); } } return null; }
.removeProcessDefinition(definitionToSuspend.getId());
deploymentCache.findDeployedProcessDefinitionById(processDefinition.getId());
public Object getInstance(String deploymentId, String resource) { // First find in cache DeploymentCache<Object> deploymentCache = cacheInstance.get(deploymentId); if (deploymentCache == null) { deploymentCache = new DefaultDeploymentCache<Object>(); cacheInstance.put(deploymentId, deploymentCache); } Object instance = deploymentCache.get(resource); if (instance == null) { @SuppressWarnings("rawtypes") ProjectEngineFactory projectEngineFactory = get(deploymentId, resource); try { instance = projectEngineFactory.newInstance(); } catch (Exception e) { throw new ResourceCompileException( "Resource with name '" + resource + "' in deployment with id '" + deploymentId + "' compilation has been failed"); } deploymentCache.add(resource, instance); } return instance; }
public ProcessArchive getProcessArchiveByProcessDefinitionId(final String processDefinitionId) { // first try to hit the cache ProcessDefinitionEntity processDefinitionEntity = processEngineConfiguration .getDeploymentCache() .getProcessDefinitionCache() .get(processDefinitionId); if(processDefinitionEntity == null) { // now look for it in the database (will add it to the cache). processDefinitionEntity = processEngineConfiguration .getCommandExecutorTxRequired() .execute(new Command<ProcessDefinitionEntity>() { public ProcessDefinitionEntity execute(CommandContext commandContext) { return commandContext.getProcessDefinitionManager() .findLatestProcessDefinitionById(processDefinitionId); } }); } if(processDefinitionEntity == null) { throw new FoxPlatformException("Could not find process definition with id '"+processDefinitionId+"' for process engine '"+processEngineName+"'."); } String processDefinitionKey = processDefinitionEntity.getKey(); if(processDefinitionKey == null) { throw new FoxPlatformException("Could not find process definition with id '"+processDefinitionId+"' for process engine '"+processEngineName+"'."); } return getProcessArchiveByProcessDefinitionKey(processDefinitionKey); }
/** * Resolving the process definition will fetch the BPMN 2.0, parse it and store the {@link BpmnModel} in memory. */ public ProcessDefinitionCacheEntry resolveProcessDefinition(ProcessDefinition processDefinition) { String processDefinitionId = processDefinition.getId(); String deploymentId = processDefinition.getDeploymentId(); ProcessDefinitionCacheEntry cachedProcessDefinition = processDefinitionCache.get(processDefinitionId); if (cachedProcessDefinition == null) { CommandContext commandContext = Context.getCommandContext(); DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId); deployment.setNew(false); deploy(deployment, null); cachedProcessDefinition = processDefinitionCache.get(processDefinitionId); if (cachedProcessDefinition == null) { throw new ActivitiException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache"); } } return cachedProcessDefinition; }
public Void execute(CommandContext commandContext) { if (processDefinitionId == null) { throw new ActivitiIllegalArgumentException("Process definition id is null"); } ProcessDefinitionEntity processDefinition = commandContext.getProcessDefinitionEntityManager().findById(processDefinitionId); if (processDefinition == null) { throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class); } // Update category processDefinition.setCategory(category); // Remove process definition from cache, it will be refetched later DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = commandContext.getProcessEngineConfiguration().getProcessDefinitionCache(); if (processDefinitionCache != null) { processDefinitionCache.remove(processDefinitionId); } if (commandContext.getEventDispatcher().isEnabled()) { commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, processDefinition)); } return null; }
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) { log.debug("Processing deployment {}", deployment.getName()); KnowledgeBuilder knowledgeBuilder = null; DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager(); Map<String, ResourceEntity> resources = deployment.getResources(); for (String resourceName : resources.keySet()) { log.info("Processing resource {}", resourceName); if (resourceName.endsWith(".drl")) { // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType) if (knowledgeBuilder == null) { knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); } ResourceEntity resourceEntity = resources.get(resourceName); byte[] resourceBytes = resourceEntity.getBytes(); Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes); knowledgeBuilder.add(droolsResource, ResourceType.DRL); } } if (knowledgeBuilder != null) { KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase(); deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase); } } }
public static ProcessDefinition getProcessDefinition(String processDefinitionId, boolean checkCacheOnly) { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); if (checkCacheOnly) { ProcessDefinitionCacheEntry cacheEntry = processEngineConfiguration.getProcessDefinitionCache().get(processDefinitionId); if (cacheEntry != null) { return cacheEntry.getProcessDefinition(); } return null; } else { // This will check the cache in the findDeployedProcessDefinitionById method return processEngineConfiguration.getDeploymentManager().findDeployedProcessDefinitionById(processDefinitionId); } }
public void removeDeployment(String deploymentId, boolean cascade) { DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId); if (deployment == null) { throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", DeploymentEntity.class); } // Remove any process definition from the cache List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl().deploymentId(deploymentId).list(); ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher(); for (ProcessDefinition processDefinition : processDefinitions) { // Since all process definitions are deleted by a single query, we should dispatch the events in this loop if (eventDispatcher.isEnabled()) { eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, processDefinition)); } } // Delete data deploymentEntityManager.deleteDeployment(deploymentId, cascade); // Since we use a delete by query, delete-events are not automatically dispatched if (eventDispatcher.isEnabled()) { eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, deployment)); } for (ProcessDefinition processDefinition : processDefinitions) { processDefinitionCache.remove(processDefinition.getId()); } }
public void deploy(DeploymentEntity deployment) { KnowledgeBuilder knowledgeBuilder = null; DeploymentManager deploymentManager = Context .getProcessEngineConfiguration() .getDeploymentManager(); Map<String, ResourceEntity> resources = deployment.getResources(); for (String resourceName : resources.keySet()) { log.info("Processing resource {}", resourceName); if (resourceName.endsWith(".drl")) { // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType) if (knowledgeBuilder==null) { knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); } ResourceEntity resourceEntity = resources.get(resourceName); byte[] resourceBytes = resourceEntity.getBytes(); Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes); knowledgeBuilder.add(droolsResource, ResourceType.DRL); } } if (knowledgeBuilder!=null) { KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase(); deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase); } } }
public ProcessDefinition findDeployedProcessDefinitionById(String processDefinitionId) { if (processDefinitionId == null) { throw new ActivitiIllegalArgumentException("Invalid process definition id : null"); } // first try the cache ProcessDefinitionCacheEntry cacheEntry = processDefinitionCache.get(processDefinitionId); ProcessDefinition processDefinition = cacheEntry != null ? cacheEntry.getProcessDefinition() : null; if (processDefinition == null) { processDefinition = processDefinitionEntityManager.findById(processDefinitionId); if (processDefinition == null) { throw new ActivitiObjectNotFoundException("no deployed process definition found with id '" + processDefinitionId + "'", ProcessDefinition.class); } processDefinition = resolveProcessDefinition(processDefinition).getProcessDefinition(); } return processDefinition; }