State Machine-Based Service Processing Method and Processing Device
By receiving service request information in the state machine and establishing and destroying the state machine based on the service ID and target events, the problem of excessive caching burden on the state machine in the prior art is solved, and efficient state machine management and service processing are achieved.
Patent Information
- Application Number
- CN202210467503.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-29
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-04-29
AI Technical Summary
In the prior art, the cache burden of state machines is heavy, resulting in too many state machine instances being managed in the system, resulting in excessive cache burden of the system, which may lead to disorder in all business states.
By receiving service request information, a state machine is established based on the service ID and target event, and the service request information is input into the state machine to output substate information, and the state machine is destroyed when the substate information is in the terminated state. This method does not depend on the current and historical states of the state machine, reducing the storage and input load of the state machine.
It effectively reduces the cache burden of state machines, avoids the risk of state disorder, improves the efficiency of state machines, and reduces the resource consumption of creating and maintaining state machines.
Smart Images

Figure CN114780594B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of state machine rule processing. Specifically, it relates to a service processing method, a processing device, a processor, and a processing system based on a state machine. Background Art
[0002] The state machine itself is widely used in the design of hardware control circuits. For example, in the more classic control of elevators and washing machines, the state machine is applied. The state machine also has a wide range of applications in software, such as the Spring state machine. However, the state machine requires a state manager, and the states from the initial state to the end state are all managed in the state manager. This kind of state machine stores the current state of a certain process service, and the state machine generates the next state according to the current state. This approach has the following disadvantages: There are too many state machine instances managed in the system. For example, in the Spring state machine, the states are stored in the cache, which places a heavy burden on the cache. And there are always states that have not been completed for a long time and have not been released. If the cache fails, it may cause all service states to be disordered.
[0003] The above information disclosed in the background art section is only used to enhance the understanding of the background art of the technology described in this article. Therefore, the background art may contain certain information that is not prior art known to those skilled in the art in this country. Summary of the Invention
[0004] The main purpose of this application is to provide a service processing method, a processing device, a processor, and a processing system based on a state machine to solve the problem of heavy cache burden of the state machine in the prior art.
[0005] According to one aspect of an embodiment of the present invention, a service processing method based on a state machine is provided, including: a receiving step of receiving service request information, where the service request information includes a service ID (Identity Document) and a target event, and the service request information does not include predetermined information. Here, the service request information is generated based on a service operation, the service ID is an ID generated according to the operation information of the service operation, the target event is an event triggered by the service request information, and the predetermined information is the current state of the state machine and the historical state of the state machine; a building step of building a state machine according to the service request information; an input step of inputting the service request information into the state machine so that the state machine outputs next state information; and destroying the state machine when the next state information is a termination state.
[0006] Optionally, the state machine includes a mapping relationship, which represents the mapping relationship among events, business scenarios, and states. The input step includes: inputting the service request information into the state machine so that the state machine determines the target business scenario. The target business scenario is determined by the state machine according to the service ID, and the target business scenario is the scenario for executing the service operation; receiving the secondary state information output by the state machine. The secondary state information is determined by the state machine according to the target business scenario, the target event, and the mapping relationship, and the secondary state information is the state corresponding to the service request information.
[0007] Optionally, the establishing step includes: using the reteOO (efficient matching mode) algorithm to obtain a predetermined rule that matches the target event from the rule library; generating a finite state automaton according to the predetermined rule, and the finite state automaton does not store the historical state.
[0008] Optionally, generating a finite state automaton according to the predetermined rule includes: creating a state machine object; determining the starting state, event set, and state set according to the predetermined rule. The event set includes multiple events, and the state set includes multiple states; setting the state machine object according to the starting state, the event set, and the state set to obtain the finite state automaton.
[0009] Optionally, the input step includes: inputting the service request information into the finite state automaton so that the finite state automaton executes the state transition step corresponding to the target event to output the secondary state information.
[0010] Optionally, the rule library includes multiple rules. Each rule includes an LHS (Left Hand Side, the query where the variable appears on the left side of the copy operation) part and an RHS (Right Hand Side, the query where the variable appears on the right side of the copy operation) part. Using the reteOO algorithm to obtain a predetermined rule that matches the target event from the rule library includes: storing the target event in the working memory; matching the target event in the working memory with the LHS parts of multiple rules; when the target event is consistent with the LHS part, determining that the match is successful, and determining that the RHS part corresponding to the successfully matched LHS part is the predetermined rule.
[0011] Optionally, when the secondary state information is not the termination state, the method further includes: repeating the steps, and sequentially executing the receiving step, the establishing step, and the input step at least once until the secondary state information output by the state machine is the termination state.
[0012] According to another aspect of the embodiments of the present invention, there is also provided a service processing apparatus based on a state machine, including: a receiving unit, configured to receive a service request message in a receiving step, where the service request message includes a service ID and a target event, and the service request message does not include predetermined information, wherein the service request message is generated based on a service operation, the service ID is an ID generated according to operation information of the service operation, the target event is an event triggered by the service request message, and the predetermined information is the current state of the state machine and the historical state of the state machine; a building unit, configured to build a state machine according to the service request message in a building step; an input unit, configured to input the service request message into the state machine in an input step, so that the state machine outputs next state information; and a destruction unit, configured to destroy the state machine when the next state information is a termination state.
[0013] According to another aspect of the embodiments of the present invention, there is also provided a processor, which is used to run a program, wherein when the program runs, it executes any one of the above methods.
[0014] According to another aspect of the embodiments of the present invention, there is also provided a service processing system, including: a state machine; one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include those for executing any one of the above methods.
[0015] In an embodiment of the present invention, for the state machine-based service processing method, first, service request information is received. The service request information includes a service ID and a target event, and the service request information does not include predetermined information, where the predetermined information is the current state and historical state of the state machine. Secondly, a state machine is established according to the service request information. Then, the service request information is input into the state machine, so that the state machine outputs next state information. Finally, when the next state information is a termination state, the state machine is destroyed. Compared with the prior art, in the traditional state machine, from the initial state to the end state, they are all managed in the state manager. Too many state machine instances are managed in the system, causing an excessive burden on the system cache, which may lead to the problem of disorder of all service states. In the method of the present application, the state machine is not established according to the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine; and the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the service ID and the target event to output the next state information, and there is no risk of state disorder, thus solving the problem of heavy cache burden of the state machine in the prior art. Moreover, compared with the prior art, the traditional state machine has a higher complexity. In the method of the present application, a state machine can be created according to the service request information including the service ID and the target event. The cost of creating the state machine is low. After the state change is completed, it is destroyed, and there is no need to occupy resources for a long time to maintain the state machine, thus ensuring a high usage efficiency of the state machine. Compared with the traditional state machine, the present application reduces the cache burden of the state machine. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings forming a part of this application are used to provide a further understanding of this application. The schematic embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation of this application. In the drawings:
[0017] Figure 1 The flowchart of the state machine-based service processing method according to an embodiment of this application is shown;
[0018] Figure 2 The input-output flowchart of the traditional state machine is shown;
[0019] Figure 3 The flowchart of generating a finite state automaton according to a specific embodiment of this application is shown;
[0020] Figure 4 The schematic diagram of the state machine-based service processing device according to an embodiment of this application is shown;
[0021] Figure 5 The processing flowchart of the service processing system according to an embodiment of this application is shown.
[0022] Among them, the above-mentioned drawings include the following reference numerals:
[0023] 10. Receiving unit; 20. Establishing unit; 30. Input unit; 40. Destroying unit. Detailed implementation manners
[0024] It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments may be combined with each other. The following will describe the present application in detail with reference to the drawings and in combination with the embodiments.
[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present application.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so as to describe the embodiments of the present application here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0027] It should be understood that when an element (such as a layer, film, region, or substrate) is described as being "on" another element, the element can be directly on the other element, or there can also be an intermediate element. Moreover, in the specification and the claims, when it is described that an element is "connected" to another element, the element can be "directly connected" to the other element, or "connected" to the other element through a third element.
[0028] For the convenience of description, some nouns or terms related to the embodiments of the present application are described below:
[0029] State Machine: A state machine that integrates states, actions, and events together;
[0030] FSM: Finite State machine, a finite state automaton in which the set of states is finite;
[0031] Event: An event where an entity sends a status to drive changes in various states;
[0032] Meta state machine: An atomic core state machine that only manages state transitions;
[0033] Match: Matching, rule matching;
[0034] Produce FSM: Generate the corresponding FSM;
[0035] Act: Execution, execute the state transition steps of the state machine.
[0036] As described in the background art, the cache burden of the state machine in the prior art is relatively heavy. To solve the above problems, in a typical embodiment of the present application, a business processing method, a processing device, a processor, and a processing system based on a state machine are provided.
[0037] According to an embodiment of the present application, a business processing method based on a state machine is provided.
[0038] Figure 1 It is a flowchart of a business processing method based on a state machine according to an embodiment of the present application. As Figure 1 shown, the method includes the following steps:
[0039] Step S101, a receiving step, receive business request information. The above business request information includes a business ID and a target event, and the above business request information does not include predetermined information. Among them, the above business request information is generated based on a business operation, the above business ID is an ID generated according to the operation information of the above business operation, the above target event is an event triggered by the above business request information, and the above predetermined information is the current state of the above state machine and the historical state of the above state machine;
[0040] Step S102, a building step, establish a state machine according to the above business request information;
[0041] Step S103, an input step, input the above business request information into the above state machine so that the above state machine outputs next state information;
[0042] Step S104, in the case where the above next state information is a termination state, destroy the above state machine.
[0043] The above state machine-based service processing method. First, it receives service request information, where the service request information includes a service ID and a target event, and the above service request information does not include predetermined information. The predetermined information is the current state and historical state of the state machine. Second, it creates a state machine according to the above service request information. Then, it inputs the above service request information into the state machine to make the state machine output next state information. Finally, when the next state information is the termination state, it destroys the state machine. Compared with the prior art, in the traditional state machine, from the initial state to the end state, they are all managed in the state manager. There are too many state machine instances managed in the system, causing an excessive burden on the system cache, which may lead to the problem of disorder of all service states. In the above method of the present application, the state machine is not created according to the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine; and the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the service ID and the target event to output the next state information, and there is no risk of state disorder, thus solving the problem of the heavy cache burden of the state machine in the prior art. And, compared with the prior art, the traditional state machine has a high complexity. In the above method of the present application, a state machine can be created according to the service request information including the service ID and the target event, and the cost of creating the state machine is low. After the state change is completed, it is destroyed, and there is no need to occupy resources for a long time to maintain the state machine, thus ensuring a high usage efficiency of the state machine. Compared with the traditional state machine, the present application reduces the cache burden of the state machine.
[0044] In a specific embodiment, the above state machine includes a mapping relationship, and the mapping relationship is a mapping relationship representing the mapping between events, service scenarios, and states. The above input step includes: inputting the above service request information into the above state machine so that the above state machine determines a target service scenario. The target service scenario is determined by the above state machine according to the above service ID, and the target service scenario is the scenario for executing the above service operation; receiving the above next state information output by the above state machine. The above next state information is determined by the above state machine according to the above target service scenario, the above target event, and the above mapping relationship, and the above next state information is the state corresponding to the above service request information. In the above method of the present application, by inputting the service ID into the state machine, the state machine determines the target service scenario for executing the service operation according to the service ID, and then determines and outputs the next state information corresponding to the service request information according to the target service scenario, the target event, and the mapping relationship stored in the above state machine. In this way, it further avoids the problem that the input of the existing state machine depends on the current state, resulting in a heavy cache burden of the state machine, further alleviates the cache burden of the state machine, and further reduces the risk of state machine disorder.
[0045] Specifically, when a service occurs, a state machine is created, and only the state machine configuration for general service scenarios is provided. The cost of creating the state machine is extremely low, and the state machine of the present application does not store the current state and historical state of the state machine. The state machine determines the next state information according to the target service scenario, the above-mentioned target event, and the above-mentioned mapping relationship, and then receives the next state information output by the state machine and returns the next state, thereby reducing the cache burden of the state machine and reducing the risk of state disorder.
[0046] In the actual application process, the traditional rule base either relies on business personnel to write rule DSL (Digital Subscriber Line), or sets some targeted configuration pages in the system. Moreover, if the configuration is completed, it is difficult to reuse it in other scenarios, and basically it is configured once for each scenario. To address this problem, according to another specific embodiment of the present application, the above-mentioned establishment step includes: obtaining a predetermined rule matching the above-mentioned target event from the rule base using the reteOO algorithm; generating a finite state automaton according to the above-mentioned predetermined rule, and the above-mentioned finite state automaton does not store the above-mentioned historical state. The present application directly skips the traditional configuration rules, generates a predetermined rule using the reteOO algorithm according to the specific target service scenario, and then generates a finite state automaton that does not include the historical state. In this way, compared with the prior art, it not only reduces the cache burden of the state machine but also avoids the traditional rule conflict resolution part.
[0047] It should be noted that the above-mentioned reteOO algorithm is the rete (network) algorithm in Drool (rule engine).
[0048] Specifically, the above-mentioned finite state automaton is a lightweight finite state automaton.
[0049] To further alleviate the cache burden of the state machine, according to another specific embodiment of the present application, generating a finite state automaton according to the above-mentioned predetermined rule includes: creating a state machine object; determining the starting state, event set, and state set according to the above-mentioned predetermined rule, the above-mentioned event set includes multiple events, and the above-mentioned state set includes multiple states; setting the above-mentioned state machine object according to the above-mentioned starting state, the above-mentioned event set, and the above-mentioned state set to obtain the above-mentioned finite state automaton. The finite state automaton generated according to the predetermined rule does not store the historical state, which further alleviates the heavy cache burden of the state machine and further avoids the problem of state disorder.
[0050] According to a specific embodiment of the present application, the above input step includes: inputting the above service request information into the above finite state automaton, so that the above finite state automaton executes the state transition step corresponding to the above target event to output the above next state information. By inputting the service request information into the finite state automaton, each input of the state will return a unique next state, without relying on the historical storage state, further alleviating the cache burden of the state machine.
[0051] In another specific embodiment of the present application, the above rule library includes multiple rules. The above rules include an LHS (Left Hand Side, query where variables appear on the left side of the copy operation) part and an RHS (Right Hand Side, query where variables appear on the right side of the copy operation) part. The reteOO algorithm is used to obtain a predetermined rule matching the above target event from the rule library, including: storing the above target event in the working memory; matching the above target event in the working memory with the above LHS parts of multiple above rules; when the above target event is consistent with the above LHS part, determining that the match is successful, and determining that the above RHS part corresponding to the successfully matched above LHS part is the above predetermined rule. The multiple rules in the rule library of the present application obtain the RHS part corresponding to the LHS part as the predetermined rule by matching the target event with the LHS part, instead of using the traditional rule of comparing the rules and data in the rule library and then processing. This improves the efficiency of obtaining rules, and at the same time avoids rule conflicts, thereby further avoiding the subsequent process of resolving rule conflicts. Moreover, traditional rules all require business experts to participate in the dynamic maintenance of rules, manage variable business rules, and the version control and online modification of rules all require professional support. However, the present application only needs to maintain necessary parameters, simplifies rule setting, and ensures that the development, maintenance, and extension of the state machine are relatively easy.
[0052] Specifically, the generation of the above state machine uses the reteOO algorithm of the business rule engine. The efficiency of rule condition matching determines the performance of the engine. This algorithm generates a "dynamic" rule execution chain to form a rule inference mechanism. The above business process uses the finite state automaton technology, applies the state machine thinking, and quickly models the business process rules using the finite state automaton. An event - tranction engine and a finite state automaton engine are constituted.
[0053] According to another specific embodiment of the present application, when the above-mentioned next state information is not in the termination state, the above method further includes: repeating the steps, sequentially executing the above-mentioned receiving step, the above-mentioned establishing step, and the above-mentioned input step at least once until the above-mentioned next state information output by the above state machine is in the above-mentioned termination state. Through the above-mentioned repeating steps, it is ensured that the state machine can be destroyed after being used up, without occupying resources for a long time to maintain the state machine.
[0054] The entire above process of the present application is completely data-driven, using the strict single-way data flow principle, making the data make the state predictable, easy to develop, maintain and expand. There is no need to manually write and configure the state machine specifically, improving the usage efficiency of the state machine.
[0055] According to a specific embodiment, the processing flow of a traditional finite state automaton is as Figure 2 shown. In a traditional finite state automaton, the output of the next state depends on the current state. For example, in a Moore type finite state automaton: next state = f(current state, input), output = f(current state); in a Mealy type finite state automaton: next state = f(current state, input), output = f(current state, input). However, the business processing based on the state machine of the present application does not store historical states, and each input of the state will return a unique next state. The core of the input is an event. In this state machine model: next state = f(event, input), output = f(event, input). Among them, the specific steps are as follows:
[0056] Step S201; create a state machine object, for example, create a "JD.com purchase transfer state machine";
[0057] Step S202; set the default start state of the object, as well as all state sets and all event sets. For example, set the default start state of the purchase transfer state machine object to be "awaiting order placement"; assume that among all state sets, there are "awaiting login", "awaiting order placement", "awaiting cash payment", "awaiting coupon use", "awaiting credit card use", "awaiting stock preparation", "awaiting transportation", "awaiting delivery", "awaiting receipt confirmation". Assume that among all event sets, there are "place an order", "make a payment", "pick up the package", "ship the goods", "deliver the package";
[0058] Step S203; input the current business ID and the triggered event enumeration, and perform state switching; input "place an order" and switch to "awaiting cash payment" according to shopping with cash payment. If it is a coupon shopping business scenario, input "place an order" and switch the state to "awaiting coupon use". In particular, it should be noted that performing state switching does not require the current state, that is, the current state "awaiting order placement", and the state machine does not store the transfer state of the current business, that is, whether the current business transfers to "awaiting delivery" or "awaiting transportation", the state machine does not care. As long as the event that occurs in the current business and the current business primary key are told to the state machine, the state machine will return what the next state is;
[0059] Step S204; Return information such as the next state of the current business process; Some basic rules will be set: If the current state is the termination state, there is no need to switch states; If the triggered event is not within the events that can be triggered in the current state, state switching is not allowed;
[0060] Step S205; Destroy the state machine object. In a distributed system, the creation cost of this state machine is extremely low, and it is a state machine that does not store historical states and can be destroyed after use.
[0061] According to a specific embodiment, as Figure 3 shown, using the reteOO algorithm, transform the RHS part into a state machine. The specific main process is as follows:
[0062] Step 301; Match: Find the set of working memory that conforms to the LHS part; For example, find all state sets of different state machines such as the "Taobao shopping process state machine", "Tmall shopping process state machine", "JD.com shopping process state machine", and "Douyin shopping process state machine" that conform to the business of "shopping process", and there are slight differences in the state sets;
[0063] Step 302; Produce FSM: Produce a lightweight finite state automaton that does not store historical states and whose conditions are met according to the current business. For example, match a "Tmall shopping process state machine" according to logging in to Taobao and entering the Tmall mall scenario, and use the "Douyin shopping process state machine" when the customer logs in to Douyin and places an order using a Douyin link. Assume that the customer uses a third-party platform to log in and does not know which shopping platform is used, then it depends on which platform the source of goods comes from and is automatically matched in the background;
[0064] Step 303; Act: Execute the part of the RHS state machine. Once the state machine to be used is selected, then if "placing an order" occurs, execute the "Tmall shopping process state machine" process;
[0065] Step 304; Return to the first step.
[0066] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0067] The embodiments of the present application further provide a service processing apparatus based on a state machine. It should be noted that the service processing apparatus based on a state machine in the embodiments of the present application can be used to execute the service processing method based on a state machine provided in the embodiments of the present application. The following introduces the service processing apparatus based on a state machine provided in the embodiments of the present application.
[0068] Figure 4 is a schematic diagram of a service processing apparatus based on a state machine according to an embodiment of the present application. As Figure 4 shown, the apparatus includes a receiving unit 10, a creating unit 20, an input unit 30, and a destroying unit 40. Among them, the receiving unit 10 is used for the receiving step to receive service request information, the service request information includes a service ID and a target event, and the service request information does not include predetermined information. Among them, the service request information is generated based on a service operation, the service ID is an ID generated according to operation information of the service operation, the target event is an event triggered corresponding to the service request information, and the predetermined information is the state in which the state machine is currently located and the historical state of the state machine; the creating unit 20 is used for the creating step to create a state machine according to the service request information; the input unit 30 is used for the input step to input the service request information into the state machine so that the state machine outputs next state information; the destroying unit 40 is used to destroy the state machine when the next state information is a termination state.
[0069] The above-mentioned state machine-based service processing device receives service request information through the above-mentioned receiving unit. The service request information includes a service ID and a target event, and the service request information does not include predetermined information. The predetermined information is the current state and historical state of the state machine. Through the above-mentioned establishing unit, a state machine is established according to the service request information. The service request information is input into the state machine through the above-mentioned input unit, so that the state machine outputs next state information. Through the above-mentioned destroying unit, when the next state information is the termination state, the state machine is destroyed. Compared with the prior art, in the traditional state machine, from the initial state to the end state, they are all managed in the state manager. Too many state machine instances are managed in the system, causing an excessive burden on the system cache, which may lead to the problem of disorder of all service states. In the above-mentioned device of the present application, the state machine is not established according to the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine. And the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the service ID and the target event to output the next state information, and there is no risk of state disorder, thus solving the problem of heavy cache burden of the state machine in the prior art. Moreover, compared with the prior art, the traditional state machine has a high complexity. In the above-mentioned device of the present application, a state machine can be created according to the service request information including the service ID and the target event, and the cost of creating the state machine is low. After the state change is completed, it is destroyed, and there is no need to occupy resources for a long time to maintain the state machine, thus ensuring a high utilization efficiency of the state machine. Compared with the traditional state machine, the present application reduces the cache burden of the state machine.
[0070] In a specific embodiment, the above state machine includes a mapping relationship, which represents the mapping relationship among events, business scenarios, and states. The above input unit includes a first input module and a receiving module. Among them, the first input module is used to input the above business request information into the above state machine, so that the state machine determines the target business scenario. The target business scenario is determined by the state machine according to the above business ID, and the target business scenario is the scenario for executing the above business operation. The receiving module is used to receive the above next state information output by the state machine. The next state information is determined by the state machine according to the above target business scenario, the above target event, and the above mapping relationship. The next state information is the state corresponding to the above business request information. In the above device of the present application, by inputting the business ID into the state machine, the state machine determines the target business scenario for executing the business operation according to the business ID, and then determines the next state information corresponding to the business request information and outputs it according to the target business scenario, the target time, and the mapping relationship stored in the state machine. This further avoids the problem that the existing state machine input depends on the current state, resulting in a heavy cache burden on the state machine, further alleviates the cache burden of the state machine, and further reduces the risk of state machine disorder.
[0071] Specifically, when a business occurs, a state machine is created, and only the state machine configuration for general business scenarios is provided. The cost of creating the state machine is extremely low, and the state machine of the present application does not store the current state and historical state of the state machine. The state machine determines the next state information according to the target business scenario, the above target event, and the above mapping relationship, and then receives the next state information output by the state machine and returns the next state, thereby reducing the cache burden of the state machine and reducing the risk of state disorder.
[0072] In the actual application process, the traditional rule library either relies on business personnel to write rule DSLs or sets some targeted configuration pages in the system. Moreover, if the configuration is completed, it is difficult to reuse it in other scenarios, and basically one scenario is configured once. To address this problem, according to another specific embodiment of the present application, the above establishment unit includes an acquisition module and a generation module. Among them, the acquisition module is used to obtain the predetermined rules matching the above target event from the rule library by using the reteOO algorithm. The generation module is used to generate a finite state automaton according to the above predetermined rules, and the finite state automaton does not store the above historical state. The present application directly skips the traditional configuration rules, generates predetermined rules by using the reteOO algorithm according to the specific target business scenario, and then generates a finite state automaton that does not include the historical state. In this way, compared with the prior art, it not only reduces the cache burden of the state machine but also avoids the traditional rule conflict resolution part.
[0073] It should be noted that the above reteOO algorithm is the rete algorithm in Drool.
[0074] Specifically, the above finite state automaton is a lightweight finite state automaton.
[0075] In order to further alleviate the cache burden of the state machine, according to another specific embodiment of the present application, the above generation module includes a creation sub-module, a first determination sub-module, and a setting sub-module. Among them, the above creation sub-module is used to create a state machine object; the above first determination sub-module is used to determine the start state, event set, and state set according to the above predetermined rules. The event set includes multiple events, and the state set includes multiple states; the above setting sub-module is used to set the above state machine object according to the above start state, the above event set, and the above state set to obtain the above finite state automaton. The finite state automaton generated according to the predetermined rules does not store historical states, which further alleviates the heavy cache burden of the state machine and further avoids the problem of state disorder.
[0076] According to a specific embodiment of the present application, the above input unit includes a second input module. Among them, the above second input module is used to input the above service request information into the above finite state automaton, so that the above finite state automaton executes the state transition step corresponding to the above target event to output the above next state information. By inputting the service request information into the finite state automaton, each state input will return a unique next state, without relying on the historical storage state, which further alleviates the cache burden of the state machine.
[0077] In still another specific embodiment of the present application, the above rule library includes multiple rules. The rules include an LHS part and an RHS part. The above acquisition module includes a storage sub-module, a matching sub-module, and a second determination sub-module. Among them, the above storage sub-module is used to store the above target event in the working memory; the above matching sub-module is used to match the above target event in the working memory with the above LHS parts of multiple above rules; the above second determination sub-module is used to determine that the matching is successful when the above target event is consistent with the above LHS part, and determine that the above RHS part corresponding to the above LHS part with successful matching is the above predetermined rule. The multiple rules in the rule library of the present application obtain the RHS part corresponding to the LHS part as the predetermined rule by matching the target event with the LHS part, instead of using the traditional rule of comparing the rules and data in the rule library and then processing. This improves the efficiency of obtaining rules and avoids rule conflicts, thereby further avoiding the subsequent process of resolving rule conflicts. Moreover, traditional rules all require business experts to participate in the dynamic maintenance of rules, manage variable business rules, and the version control and online modification of rules all require professional support. However, the present application only needs to maintain necessary parameters, simplifies rule setting, and ensures that the development, maintenance, and expansion of the state machine are relatively easy.
[0078] Specifically, the generation of the above state machine uses the reteOO algorithm of the business rule engine. The efficiency of rule condition matching determines the performance of the engine. This algorithm generates a "dynamic" rule execution chain, forming a rule inference mechanism. The above business process uses the finite state automaton technology. Using the state machine thinking, the business process rules are quickly modeled using the finite state automaton. An event-action engine and a finite-state-machines engine are formed.
[0079] According to another specific embodiment of the present application, the above device further includes a repetition unit. The repetition unit is used to repeat the steps and sequentially execute the above receiving step, the above establishing step, and the above input step at least once until the next state information output by the state machine is the above termination state when the next state information is not the termination state. Through the above repetition steps, it is ensured that the state machine can be destroyed after use and does not need to occupy resources for a long time to maintain the state machine.
[0080] The above entire process of the present application is completely data-driven and uses the strict single-item data flow principle, making the state predictable by data, easy to develop, maintain, and expand. There is no need to manually write and configure the state machine specifically, improving the usage efficiency of the state machine.
[0081] According to a specific embodiment, as Figure 2 shown, it is the processing flow of the traditional finite state automaton. For the traditional finite state automaton, the output of the next state depends on the current state. For example, for the Moore finite state automaton: next state = f(current state, input), output = f(current state); for the Mealy finite state automaton: next state = f(current state, input), output = f(current state, input). However, the state machine-based business processing of the present application does not store historical states, and each input of the state will return a unique next state. The core of the input is the event. For this state machine model: next state = f(event, input), output = f(event, input). Among them, the specific steps are as follows:
[0082] Step S201; create a state machine object, for example, create a "JD.com purchase logistics transfer state machine";
[0083] Step S202: Set the default start state of the object, and all state sets and all event sets. For example, set the default start state of the shopping flow state machine object to "pending order"; assume that all state sets include "pending login", "pending order", "pending cash payment", "pending coupon use", "pending credit card use", "pending stock preparation", "pending transportation", "pending delivery", and "pending confirmation of receipt". Assume that all event sets include "placing order", "payment", "collection", "shipping", and "delivery";
[0084] Step S203: Input the current business ID and the triggered event enumeration, and execute the state switching; input "place an order" to switch to "waiting for cash payment" according to the shopping with cash payment; if it is a coupon shopping business scenario, input "place an order" to switch the state to "waiting for coupon use". It should be noted that the execution state switching does not require the current state, that is, the current state is "waiting for order placement", and the state machine will not store the flow state of the current business, that is, whether the current business flows to "waiting for delivery" or "waiting for transportation". The state machine does not care. As long as the event occurring in the current business and the current business primary key are told to the state machine, the state machine will return what the next state is;
[0085] Step S204: Return the next state of the current business process and other information; some basic rules will be set: if the current state is a termination state, there is no need to switch the state; if the triggered event is not within the events that can be triggered by the current state, switching the state is not allowed, etc.;
[0086] Step S205: destroy the state machine object. In a distributed system, the creation cost of this state machine is extremely low, and it is a state machine that does not store historical states and can be destroyed after use.
[0087] According to a specific embodiment, Figure 3 As shown, the reteOO algorithm is used to transform the RHS part into a state machine. The specific main process is as follows:
[0088] Step 301; Match: find the working memory set that matches the LHS part; for example, find all state machines that match the "shopping process" business, such as "Taobao shopping flow state machine", "Tmall shopping flow state machine", "JD shopping flow state machine", and "Douyin shopping flow state machine". The state sets of different state machines are slightly different, etc.
[0089] Step 302; Produce FSM: Produce a lightweight finite state automaton that does not store historical states and whose condition is satisfied according to the current business. For example, match a "Tmall shopping process state machine" according to the scenario that the user logs in to Taobao and enters the Tmall Mall, and match a "Douyin shopping process state machine" when the customer logs in to Douyin and places an order using a Douyin link. Assume that the customer logs in using a third-party platform and does not know which shopping platform is used. Then it depends on which platform the source of goods comes from and is automatically matched in the background;
[0090] Step 303; Act: Execute part of the RHS state machine. Once the used state machine is selected, if "placing an order" occurs, then execute the "Tmall shopping process state machine" process;
[0091] Step 304; Return to the first step.
[0092] The above state machine-based business processing device includes a processor and a memory. The above receiving unit, the above establishing unit, the above input unit, and the above destroying unit, etc. are all stored in the memory as program units, and the processor executes the above program units stored in the memory to implement corresponding functions.
[0093] The processor contains a kernel, and the kernel retrieves the corresponding program units from the memory. One or more kernels can be set, and by adjusting the kernel parameters, the problem of heavy cache burden of the state machine in the prior art can be solved.
[0094] The memory may include non-permanent memory in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.
[0095] An embodiment of the present invention provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, the above state machine-based business processing method is implemented.
[0096] An embodiment of the present invention provides a processor, and the above processor is used to run a program, wherein when the above program runs, the above state machine-based business processing method is executed.
[0097] An embodiment of the present invention provides a device, the device includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, at least the following steps are implemented:
[0098] Step S101, receiving step: Receive service request information, where the service request information includes a service ID and a target event, and the service request information does not include predetermined information. Among them, the service request information is generated based on a service operation, the service ID is an ID generated according to the operation information of the service operation, the target event is the event triggered by the service request information, and the predetermined information is the current state of the state machine and the historical state of the state machine;
[0099] Step S102, establishing step: Establish a state machine according to the service request information;
[0100] Step S103, inputting step: Input the service request information into the state machine so that the state machine outputs next state information;
[0101] Step S104: Destroy the state machine when the next state information is a termination state.
[0102] The device in this article can be a server, a PC, a PAD, a mobile phone, etc.
[0103] This application also provides a computer program product, which, when executed on a data processing device, is adapted to execute a program initialized with at least the following method steps:
[0104] Step S101, receiving step: Receive service request information, where the service request information includes a service ID and a target event, and the service request information does not include predetermined information. Among them, the service request information is generated based on a service operation, the service ID is an ID generated according to the operation information of the service operation, the target event is the event triggered by the service request information, and the predetermined information is the current state of the state machine and the historical state of the state machine;
[0105] Step S102, establishing step: Establish a state machine according to the service request information;
[0106] Step S103, inputting step: Input the service request information into the state machine so that the state machine outputs next state information;
[0107] Step S104: Destroy the state machine when the next state information is a termination state.
[0108] According to another typical embodiment of the present application, a service processing system is further provided. The service processing system includes a state machine, one or more processors, a memory, and one or more programs. Among them, the above one or more programs are stored in the above memory and are configured to be executed by the above one or more processors. The above one or more programs include those for executing any of the above methods.
[0109] The above service processing system includes a state machine, processors, a memory, and programs. The above programs are used to execute any of the above methods. Compared with the prior art, in the traditional state machine, from the initial state to the end state, they are all managed in the state manager. Too many state machine instances are managed in the system, causing an excessive burden on the system cache, which may lead to the problem of disorder of all service states. The above method of the present application does not establish a state machine based on the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine; and the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the service ID and the target event to output the next state information, without the risk of state disorder, thus solving the problem of heavy cache burden of the state machine in the prior art and ensuring better stability of the entire service processing system. Moreover, compared with the prior art, the traditional state machine has a higher complexity. In the present application, a state machine can be created based on the service request information including the service ID and the target event. The cost of creating the state machine is low. After the state change is completed, it is destroyed, and there is no need to occupy resources for a long time to maintain the state machine, thus ensuring a higher usage efficiency of the state machine. Compared with the traditional state machine, the present application reduces the cache burden of the state machine.
[0110] Figure 5 The processing flow chart of the service processing system according to a specific embodiment of the present application is shown as Figure 5 shown. The management personnel initialize service parameters, configuration and other information, and quickly build a rule library according to this information; the user operates a certain service mode (such as Figure 5 Service Mode A therein) to generate and send service request information including a service ID and a target event. Then, according to the service request information, the reteOO algorithm is used to obtain a predetermined rule matching the above target event from the rule library. Furthermore, according to the above predetermined rule, a lightweight finite state automaton that does not store historical states is generated, that is, Figure 5 Service Mode A state machine therein; finally, the above service request information is input into the finite state automaton to output the next state information, that is, Figure 5 the next state therein.
[0111] In the above embodiments of the present invention, the descriptions of the respective embodiments have their own emphases. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0112] In several embodiments provided by the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the above division of units can be a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces. The indirect couplings or communication connections of units or modules can be in electrical or other forms.
[0113] The units described above as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0114] In addition, in each embodiment of the present invention, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0115] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the above methods in each embodiment of the present invention. The foregoing storage medium includes: USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical disks, and other various media that can store program codes.
[0116] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:
[0117] 1) The above-mentioned business processing method based on the state machine in this application first receives business request information, where the business request information includes a business ID and a target event, and the above-mentioned business request information does not include predetermined information. The predetermined information is the current state and historical state of the state machine. Secondly, a state machine is established according to the above-mentioned business request information. Then, the above-mentioned business request information is input into the state machine to make the state machine output next state information. Finally, when the next state information is the termination state, the state machine is destroyed. Compared with the prior art, in the traditional state machine, from the initial state to the end state, they are all managed in the state manager. There are too many state machine instances managed in the system, resulting in an overly heavy system cache burden, which may lead to the problem of disorder in all business states. In the above method of this application, the state machine is not established according to the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine; and the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the business ID and the target event to output the next state information, and there is no risk of state disorder, thus solving the problem of the heavy cache burden of the state machine in the prior art. Moreover, compared with the prior art, the traditional state machine has a higher complexity. In the above method of this application, a state machine can be created according to the business request information including the business ID and the target event. The cost of creating the state machine is low. After the state change is completed, it is destroyed, and there is no need to occupy resources for a long time to maintain the state machine, thus ensuring a high usage efficiency of the state machine. Compared with the traditional state machine, this application reduces the cache burden of the state machine.
[0118] 2) The above-mentioned business processing device based on the state machine in this application receives business request information through the above-mentioned receiving unit. Among them, the business request information includes a business ID and a target event, and the above-mentioned business request information does not include predetermined information, where the predetermined information is the current state and historical state of the state machine; through the above-mentioned establishment unit, a state machine is established according to the above-mentioned business request information; through the above-mentioned input unit, the above-mentioned business request information is input into the state machine, so that the state machine outputs next state information; through the above-mentioned destruction unit, when the next state information is the termination state, the state machine is destroyed. Compared with the prior art, in the traditional state machine, from the initial state to the end state, they are all managed in the state manager. There are too many state machine instances managed in the system, causing an excessive burden on the system cache, which may lead to the problem of disorder of all business states. In the above-mentioned device of this application, the state machine is not established according to the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine; and the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the business ID and the target event to output the next state information, and there is no risk of state disorder, thus solving the problem of heavy cache burden of the state machine in the prior art. Moreover, compared with the prior art, the traditional state machine has a high complexity. In the above-mentioned device of this application, a state machine can be created according to the business request information including the business ID and the target event, and the cost of creating the state machine is low. After the state change is completed, it is destroyed, and there is no need to occupy resources for a long time to maintain the state machine, thus ensuring a high usage efficiency of the state machine. Compared with the traditional state machine, this application reduces the cache burden of the state machine.
[0119] 3) The above business processing system of the present application includes a state machine, a processor, a memory, and a program. The above program is used to execute any of the above methods. Compared with the prior art, in the traditional state machine, the entire process from the initial state to the end state is managed in the state manager. There are too many state machine instances managed in the system, resulting in an excessive cache burden on the system, which may cause problems such as disorder in all business states. In the above method of the present application, the state machine is not established based on the current state and historical state of the state machine. That is to say, the state machine does not store the current state and historical state of the state machine; and the input of the state machine does not include the current state and historical state, that is, the state machine does not depend on the previous state, but depends on the business ID and the target event to output the next state information, without the risk of state disorder, thus solving the problem of heavy cache burden of the state machine in the prior art and ensuring better stability of the entire business processing system. Moreover, compared with the prior art, the traditional state machine has a high complexity. In the present application, a state machine can be created based on the business request information including the business ID and the target event, and the cost of creating the state machine is low. After the state change is completed, the state machine is destroyed without occupying resources for a long time to maintain the state machine, thus ensuring a high utilization efficiency of the state machine. Compared with the traditional state machine, the present application reduces the cache burden of the state machine.
[0120] The foregoing are only the preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, various modifications and changes can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the protection scope of the present application.
Claims
1. A service processing method based on a state machine, characterized in that Including: A receiving step of receiving service request information, where the service request information includes a service ID and a target event, and the service request information does not include predetermined information. Herein, the service request information is generated based on a service operation, the service ID is an ID generated according to operation information of the service operation, the target event is an event triggered corresponding to the service request information, and the predetermined information is the current state of the state machine and the historical states of the state machine; A establishing step of establishing a state machine according to the service request information; An inputting step of inputting the service request information into the state machine so that the state machine outputs next state information; Destroying the state machine when the next state information is a termination state.
2. The method according to claim 1, wherein The state machine includes a mapping relationship, which is a mapping relationship representing an event, a service scenario, and a state. The inputting step includes: Inputting the service request information into the state machine so that the state machine determines a target service scenario, where the target service scenario is determined by the state machine according to the service ID, and the target service scenario is a scenario for executing the service operation; Receiving the next state information output by the state machine, where the next state information is determined by the state machine according to the target service scenario, the target event, and the mapping relationship, and the next state information is the state corresponding to the service request information.
3. The method according to claim 1, characterized in that, The establishing step includes: Obtaining a predetermined rule matching the target event from a rule base by using the reteOO algorithm; Generating a finite state automaton according to the predetermined rule, and the finite state automaton does not store the historical state.
4. The method according to claim 3, wherein Generating a finite state automaton according to the predetermined rule includes: Creating a state machine object; Determining a start state, an event set, and a state set according to the predetermined rule, where the event set includes multiple events and the state set includes multiple states; Setting the state machine object according to the start state, the event set, and the state set to obtain the finite state automaton.
5. The method according to claim 3, wherein The inputting step includes: Inputting the service request information into the finite state automaton so that the finite state automaton executes the state transition step corresponding to the target event to output the next state information.
6. The method according to claim 3, wherein The rule base includes multiple rules, and each rule includes an LHS part and an RHS part. Obtaining a predetermined rule matching the target event from the rule base by using the reteOO algorithm includes: Storing the target event in a working memory; Matching the target event in the working memory with the LHS parts of multiple rules; When the target event is consistent with the LHS part, determining that the matching is successful, and determining that the RHS part corresponding to the successfully matched LHS part is the predetermined rule.
7. The method according to any one of claims 1 to 6, characterized in that, When the next state information is not a termination state, the method further includes: A repeating step of sequentially executing the receiving step, the establishing step, and the inputting step at least once until the next state information output by the state machine is the termination state.
8. A service processing device based on a state machine, characterized in that, Including: A receiving unit, for the receiving step, to receive service request information, where the service request information includes a service ID and a target event, and the service request information does not include predetermined information. Among them, the service request information is generated based on a service operation, the service ID is an ID generated according to the operation information of the service operation, the target event is the event triggered corresponding to the service request information, and the predetermined information is the current state of the state machine and the historical state of the state machine; A establishing unit, for the establishing step, to establish a state machine according to the service request information; An input unit, for the input step, to input the service request information into the state machine so that the state machine outputs next state information; A destroying unit, for destroying the state machine when the next state information is a termination state.
9. A processor, characterized in that, The processor is used to run a program, where when the program runs, it executes the method according to any one of claims 1 to 7.
10. A service processing system, characterized in that, Comprising: A state machine, One or more processors, a memory, and one or more programs, where the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include methods for executing any one of claims 1 to 7.
Citation Information
Patent Citations
Service processing scheduling method and device, computer equipment and storage medium
CN110648046A
Real-time regular expression search engine
US9967272B1