How to integrate activiti source code and activiti source code

Source: Internet
Author: User

How to integrate activiti source code and activiti source code

  • What is the execution insider of TaskService. completeTask?

    Activiti adopts the command mode. completeTask is encapsulated into a CompleteTaskCmd. Some peripheral processing, such as log logs, is required for executing a Cmd. Activiti defines an interceptor chain. Each interceptor on the chain has a next and will continue to execute next. Taking CompleteTaskCmd as an example, the interceptor chain is:

    Logger interceptor --> spring transaction interceptor --> CommandContext interceptor --> CommandInvoker interceptor

    The CommandContext interceptor mainly sets Context:
          // Push on stack      Context.setCommandContext(context);      Context.setProcessEngineConfiguration(processEngineConfiguration);            return next.execute(config, command);

    Here push, and there is a place where pop and CommandInvoker will do this:
      public <T> T execute(CommandConfig config, Command<T> command) {    return command.execute(Context.getCommandContext());  }

  • How can I go down when a node is over?

    The answer is TaskEntity. the completeTask () method calls execution. signal () --> activityBehavior. signal () --> activityBehavior. leave () method. This method will eventually activate the eventNotificationsCompleted () method of atomicoperationtransitionpolicylistenerstart. This method will create the destination of the current Transition. The Code is as follows:
      protected void eventNotificationsCompleted(InterpretableExecution execution) {    TransitionImpl transition = execution.getTransition();    ActivityImpl destination = null;    if(transition == null) { // this is null after async cont. -> transition is not stored in execution      destination = (ActivityImpl) execution.getActivity();    } else {      destination = transition.getDestination();    }        ActivityImpl activity = (ActivityImpl) execution.getActivity();    if (activity!=destination) {      ActivityImpl nextScope = AtomicOperationTransitionNotifyListenerTake.findNextScope(activity, destination);      execution.setActivity(nextScope);      execution.performOperation(TRANSITION_CREATE_SCOPE);    } else {      execution.setTransition(null);      execution.setActivity(destination);      execution.performOperation(ACTIVITY_EXECUTE);    }  }}
  • How does one know that the loop has ended when a multi-instance task is executed?

    Multiple instance tasks start multiple tasks and execution and call execution. signal () --> activityBehavior. signal () --> activityBehavior. leave (), ParallelMultiInstanceBehavior. leave () contains the following code:

        List<ActivityExecution> joinedExecutions = executionEntity.findInactiveConcurrentExecutions(execution.getActivity());    if (joinedExecutions.size() == nrOfInstances || completionConditionSatisfied(execution)) {            // Removing all active child executions (ie because completionCondition is true)      List<ExecutionEntity> executionsToRemove = new ArrayList<ExecutionEntity>();      for (ActivityExecution childExecution : executionEntity.getParent().getExecutions()) {        if (childExecution.isActive()) {          executionsToRemove.add((ExecutionEntity) childExecution);        }      }      for (ExecutionEntity executionToRemove : executionsToRemove) {        if (LOGGER.isDebugEnabled()) {          LOGGER.debug("Execution {} still active, but multi-instance is completed. Removing this execution.", executionToRemove);        }        executionToRemove.inactivate();        executionToRemove.deleteCascade("multi-instance completed");      }      executionEntity.takeAll(executionEntity.getActivity().getOutgoingTransitions(), joinedExecutions);
    The completionConditionSatisfied () method is used to determine whether or not the end is complete. The takeAll () method ends the current sub-execution and sets the master execution to active.

  • Can I add/modify an activity during runtime?

    Of course! But remember, the execution with the current activity will be used in the subsequent execution and end of the activity! If the program is closed, execution tries to re-load the activity based on the ID from ProcessDefinition, as shown below:

      protected void ensureProcessDefinitionInitialized() {    if ((processDefinition == null) && (processDefinitionId != null)) {      ProcessDefinitionEntity deployedProcessDefinition = Context        .getProcessEngineConfiguration()        .getDeploymentManager()        .findDeployedProcessDefinitionById(processDefinitionId);      setProcessDefinition(deployedProcessDefinition);    }  }    protected void ensureActivityInitialized() {    if ((activity == null) && (activityId != null)) {      activity = getProcessDefinition().findActivity(activityId);    }  }
    Let's take a look at the set method of execution to see why it retains a bunch of IDS:
      public void setActivity(ActivityImpl activity) {    this.activity = activity;    if (activity != null) {      this.activityId = activity.getId();      this.activityName = (String) activity.getProperty("name");    } else {      this.activityId = null;      this.activityName = null;    }  }
    Therefore, the way to ensure that the program fully understands the transformed activity is: Customize ProcessDefinition and rewrite its findActivity () method!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.