Activiti Series: Is it possible to write information about certain processes to a history table while others do not?

Source: Internet
Author: User
Tags key string

First, the cause intends to use Activiti timed start event to start the process on a timed basis, and then start another process instance for each user in the process to calculate the real-time bill for each user, the number of users of the system is generally 1000~2000 (this is assumed to be 2000), Real-time bills are usually calculated hourly, then the day's data is 2000x24=48000, one months is 150w, a year is 1800w, so the number of records for Activiti history table is a bit more, it is doubtful whether he can run more smoothly under such data volume.I think Activiti design is not designed to do this kind of large-scale automatic triggering, no human participation in the process.
So it's not possible to make this automated process without writing a history table by some settings, but other processes that need to be manually involved are still able to record the history normally.


Second, source reading
then read the Activiti 5.18 source code, analysis is as follows:
    Write history is expressed in Defaulthistorymanager, implemented by Historylevel to control, the relevant code is as follows:
  
 
  1. public void recordProcessInstanceStart(ExecutionEntity processInstance) {
  2. if(isHistoryLevelAtLeast(HistoryLevel.ACTIVITY)) {
  3. HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity(processInstance);
  4. // Insert historic process-instance
  5. getDbSqlSession().insert(historicProcessInstance);
  6. ....
  7. }

The implementation of Ishistorylevelatleast is as follows:
  
 
  1. public boolean isHistoryLevelAtLeast(HistoryLevel level) {
  2. if(log.isDebugEnabled()) {
  3. log.debug("Current history level: {}, level required: {}", historyLevel, level);
  4. }
  5. // Comparing enums actually compares the location of values declared in the enum
  6. return historyLevel.isAtLeast(level);
  7. }


The Historylevel enumeration type is implemented as follows
  
 
  1. /**
  2. * Enum that contains all possible history-levels.
  3. *
  4. * @author Frederik Heremans
  5. */
  6. public enum HistoryLevel {
  7. NONE("none"),
  8. ACTIVITY("activity"),
  9. AUDIT("audit"),
  10. FULL("full");
  11. private String key;
  12. private HistoryLevel(String key) {
  13. this.key = key;
  14. }
  15. /**
  16. * @param key string representation of level
  17. * @return {@link HistoryLevel} for the given key
  18. * @throws ActivitiException when passed in key doesn‘t correspond to existing level
  19. */
  20. public static HistoryLevel getHistoryLevelForKey(String key) {
  21. for(HistoryLevel level : values()) {
  22. if(level.key.equals(key)) {
  23. return level;
  24. }
  25. }
  26. throw new ActivitiIllegalArgumentException("Illegal value for history-level: " + key);
  27. }
  28. /**
  29. * String representation of this history-level.
  30. */
  31. public String getKey() {
  32. return key;
  33. }
  34. /**
  35. * Checks if the given level is the same as, or higher in order than the
  36. * level this method is executed on.
  37. */
  38. public boolean isAtLeast(HistoryLevel level) {
  39. // Comparing enums actually compares the location of values declared in the enum
  40. return this.compareTo(level) >= 0;
  41. }
  42. }

As you can see, it is up to the level members of the Defaulthistorymanager to record the process execution information in the history table, which is only recorded at activity and above. Defaulthistorymanager is global and is not related to a specific process or process instance, so in the default implementation, Activiti does not support setting up a single process or whether a process instance writes a history table.Third, the solution if we really want to implement for each process or process instance can control whether he writes a log, There are two changes: 1. To add a Historylevel attribute, or process variable, to a executionentity, it is more convenient to use a process variable, and there is no need to change the original class; 2. To implement a custom historymanager, and then inject it into the Commandcont Ext. In this custom historymanager, you need to be able to judge the level of Executionentity's historylevel in order to decide whether or not to record his historical information;

From for notes (Wiz)

Activiti Series: Is it possible to write information about certain processes to a history table while others do not?

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.