CN115061718A - Method, computing device and computer storage medium for configuring and running state machine - Google Patents
Method, computing device and computer storage medium for configuring and running state machine Download PDFInfo
- Publication number
- CN115061718A CN115061718A CN202210302133.9A CN202210302133A CN115061718A CN 115061718 A CN115061718 A CN 115061718A CN 202210302133 A CN202210302133 A CN 202210302133A CN 115061718 A CN115061718 A CN 115061718A
- Authority
- CN
- China
- Prior art keywords
- node
- state
- edge
- determining
- nodes
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 42
- 230000009471 action Effects 0.000 claims abstract description 103
- 230000004044 response Effects 0.000 claims abstract description 28
- 238000004590 computer program Methods 0.000 claims description 7
- 238000010586 diagram Methods 0.000 description 10
- 230000006870 function Effects 0.000 description 9
- 238000004891 communication Methods 0.000 description 6
- 230000007704 transition Effects 0.000 description 5
- 238000013461 design Methods 0.000 description 3
- 238000011161 development Methods 0.000 description 3
- 238000012423 maintenance Methods 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 238000012937 correction Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000011084 recovery Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4498—Finite state machines
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Debugging And Monitoring (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides a method for configuring and running a state machine, a computing device and a computer readable storage medium. The method of running a state machine includes, by an execution engine: determining, at a state node of a state machine, whether a driving event is received; in response to determining that the driving event is received, determining whether the driving event is a legitimate event that triggers a state node based on the driving event and a set of node actions of a plurality of state nodes of the state machine; in response to determining that the driving event is a legal event triggering the state node, sequentially executing a node action set of the state node to obtain an execution result of the state node; determining whether an edge condition of the state node is satisfied based on an execution result of the state node; and responsive to determining that the result of the execution of the state node satisfies an edge condition for the state node, transitioning the state machine from the state node to a next state node corresponding to the edge condition.
Description
Technical Field
The present invention relates generally to the field of computer software, and more particularly, to a method of configuring a state machine, a method of running a state machine, a computing device, and a computer-readable storage medium.
Background
The concept of a state machine has been widely used in the programming of streaming applications. The State Machine is essentially a Finite State Machine (FSM), referred to simply as a State Machine. The description of the state machine includes 4 components: state (State), Event (Event), Action (Action), Transition (Transition). Wherein, a state machine at least comprises two states; an event is a trigger condition or a password for performing an operation; an action is a description of an activity to be performed at a given moment; the transition is from one state to another. An event is input to the state machine, and the state machine uniquely determines a state transition according to the current state and the triggered event.
Currently, in the development process of an application for a specific business requirement, a state machine, a state configuration file and an execution engine for the application are generally developed at the same time. Due to the fact that the state rounds of different service scenes are quite different, the code is difficult to multiplex, and when the model of the state machine is complex to a certain degree, the complexity of maintenance and expansion is brought. For example, in some multi-turn applications (e.g., turn-based games or turn-based design or approval applications), the number of state nodes and wires of the state machine of the application is very large due to the complexity of the scene. In this case, the code with insufficient reusability, extensibility and readability greatly increases the difficulty of subsequent maintenance and further development, and the state machine, state configuration file and execution engine developed for one specific application program are difficult to be applied to the development of other application programs, even if the application programs are very similar logically.
Disclosure of Invention
In view of at least one of the above problems, the present invention provides a scheme for configuring and running a state machine, which completely decouples an execution engine of the state machine and a configuration file of the state machine from a code level by designing a programmable state machine model and configuring each state node of the state machine, the execution engine only needs to be responsible for state rotation of the state machine, thereby improving reusability, extensibility, readability and high availability of state machine service codes, and enabling the same state machine model to be easily programmed for different service scenarios.
According to one aspect of the invention, a method of operating a state machine is provided. The method includes, by an execution engine: determining, at a state node of the state machine, whether a driving event is received, wherein the state machine comprises a plurality of state nodes, each state node having a node unique identifier, a node type, a node in-edge set, a node out-edge set, and a node action set; in response to determining that the driving event is received, determining whether the driving event is a legitimate event that triggers the state node based on the driving event and node action sets of the plurality of state nodes of the state machine, wherein the node action set of each state node includes an enter action set, an event action set, and a leave action set of the state node; in response to determining that the driving event is a legal event triggering the state node, sequentially executing a node action set of the state node to obtain an execution result of the state node; determining whether an out-of-edge condition of the state node is satisfied based on the execution result of the state node; and in response to determining that the result of the execution of the state node satisfies an edge condition for the state node, transitioning the state machine from the state node to a next state node corresponding to the edge condition.
In some embodiments, determining whether the driving event is a legitimate event that triggers the state node based on the driving event and the set of node actions of the plurality of state nodes of the state machine comprises: determining whether the driving event belongs to a union of node action sets of the plurality of state nodes of the state machine; in response to determining that the driving event belongs to a union of node action sets of the plurality of state nodes of the state machine, adding a fair lock to the state nodes; establishing a snapshot of the state node; determining whether the state node operates normally; and in response to determining that the state node is operating properly, determining whether the driving event belongs to a set of node actions for the state node.
In some embodiments, determining whether the driving event is a legitimate event that triggers the state node based on the driving event and the set of node actions of the plurality of state nodes of the state machine further comprises: in response to determining that the driving event belongs to the set of node actions for the state node, determining that the driving event is a legitimate event that triggers the state node; and determining that the driving event is not a legitimate event triggering the state node in response to determining that the driving event does not belong to a union of node action sets of the plurality of state nodes of the state machine or in response to determining that the driving event does not belong to a node action set of the state nodes.
In some embodiments, the method further comprises: and after the state machine is transferred from the state node to a next state node corresponding to the edge condition, releasing the fair lock of the state node.
In some embodiments, determining whether an edge condition of the state node is satisfied based on the execution result of the state node comprises: determining the node types of the state nodes, wherein the node types comprise sequence nodes, bifurcation nodes, combination nodes, bifurcation and combination end nodes and internal circulation nodes; determining one or more edge-out elements in a node edge-out set of the state nodes based on the node types of the state nodes, wherein each edge-out element comprises a next state node of the edge-out element, an edge-out condition and an edge-out sequence; and sequentially determining whether the execution result of the state node meets the edge condition of one of the one or more edge elements according to the edge sequence of the one or more edge elements.
In some embodiments, determining one or more out-of-edge elements in the node out-of-edge set of the state node comprises one of: in response to determining that the node type of the state node is a sequential node, determining a unique out-of-edge element of the sequential node; in response to determining that the node type of the state node is a bifurcation node, determining a plurality of out-edge elements of the bifurcation node, wherein the plurality of out-edge elements have a same out-edge order; in response to determining that the node type of the state node is a merge node, determining a unique out-edge element of the merge node, the unique out-edge element of the merge node having at least a next state node that is the same as another state node; in response to determining that the node type of the state node is a split merge ending node, determining a number of previous merge nodes of the split merge ending node; and in response to determining that the node type of the state node is an inner loop node, performing a loop operation at the inner loop node.
According to another aspect of the invention, a method of configuring a state machine is provided. The method comprises the following steps: determining a node type and a node unique identifier for each node of a plurality of state nodes of the state machine based on a logical relationship of a multi-closure application to be implemented; configuring a node entry edge set and a node exit edge set for each state node based on the node type of the state node, wherein the node entry edge set comprises one or more entry edge elements, each entry edge element comprises a node unique identifier of a previous state node of the state node, the node exit edge set comprises one or more exit edge elements, and each exit edge element comprises a node unique identifier of a next state node of the state node, an exit edge condition and an exit edge sequence; determining a node action set for each state node based on a logical relationship of the multi-turn application, wherein the node action set comprises an entry action set, an event action set, and an exit action set; and arranging an executable configuration file of each state node based on the node unique identifier, the node type, the node edge-in set, the node edge-out set and the node action set of the state node.
In some embodiments, orchestrating the executable configuration file of the state node comprises: configuring a unique edge entry element and a unique edge exit element of a state node for the state node of which the node type is a sequential node; for a state node of which the node type is a bifurcation node, configuring a plurality of edge-out elements of the state node, wherein the edge-out elements have the same edge-out sequence; for a state node of which the node type is a merge node, configuring an edge-out element of the state node as a next state node having at least the same as another state node; configuring the number of the last merging nodes of the state nodes for the state nodes of which the node types are the bifurcation merging end nodes; and for a state node whose node type is an inner loop node, configuring a set of entry actions of the state node to include the inner loop node.
According to another aspect of the invention, a computing device is provided. The computing device includes: at least one processor; and at least one memory coupled to the at least one processor and storing instructions for execution by the at least one processor, the instructions when executed by the at least one processor causing the computing device to perform steps according to the above-described method.
According to yet another aspect of the present invention, a computer-readable storage medium is provided, having stored thereon computer program code, which, when executed, performs the method as described above.
Drawings
The invention will be better understood and other objects, details, features and advantages thereof will become more apparent in the light of the following description of specific embodiments thereof, given with reference to the accompanying drawings.
FIG. 1 shows a schematic diagram of a system for implementing an embodiment in accordance with the invention.
Fig. 2 shows a schematic diagram of a state machine according to an embodiment of the invention.
FIG. 3 shows a flow diagram of a method for configuring a state machine according to an embodiment of the invention.
FIG. 4 shows a flowchart of the steps for orchestrating an executable configuration file for a state node, according to an embodiment of the invention.
Fig. 5 shows a flow diagram of a method of operating a state machine as described above, according to an embodiment of the invention.
FIG. 6 illustrates a flow chart of steps for determining whether a driving event is a legitimate event triggering the state node according to some embodiments of the invention.
FIG. 7 illustrates a block diagram of a computing device suitable for implementing embodiments of the present invention.
Detailed Description
Preferred embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While the preferred embodiments of the present invention have been illustrated in the accompanying drawings, it is to be understood that the invention may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
In the following description, for the purposes of illustrating various inventive embodiments, certain specific details are set forth in order to provide a thorough understanding of the various inventive embodiments. One skilled in the relevant art will recognize, however, that the embodiments may be practiced without one or more of the specific details. In other instances, well-known devices, structures and techniques associated with this application may not be shown or described in detail to avoid unnecessarily obscuring the description of the embodiments.
Throughout the specification and claims, the word "comprise" and variations thereof, such as "comprises" and "comprising," are to be understood as an open, inclusive meaning, i.e., as being interpreted to mean "including, but not limited to," unless the context requires otherwise.
Reference throughout this specification to "one embodiment" or "some embodiments" means that a particular feature, structure, or characteristic described in connection with the embodiments is included in at least one embodiment. Thus, the appearances of the phrases "in one embodiment" or "in some embodiments" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
Furthermore, the terms first, second and the like used in the description and the claims are used for distinguishing objects for clarity, and do not limit the size, other order and the like of the described objects.
Fig. 1 shows a schematic diagram of a system 1 for implementing an embodiment according to the invention. As shown in fig. 1, the system 1 includes a state machine configuration device 10 and an execution engine 20. The state machine configuration device 10 and the execution engine 20 may interact with data through various wired or wireless networks. Here, the state machine configuration device 10 and the execution engine 20 may be various mobile or fixed terminals capable of executing a computing function, which may have a structure of a computing device as described below in connection with fig. 7 or a similar structure. The state machine configuration device 10 is capable of configuring the respective state nodes of the state machine for an application to be implemented (in particular, a multi-loop application) based on the logic of the application to generate a state machine configuration file, and the execution engine 20 is capable of running the state machine of the application based on the state machine configuration file to implement the corresponding application.
The state machine configuration device 10 and the execution engine 20 may be implemented as separate or integrated hardware devices, or may be implemented as software. In the latter case, the state machine configuration device 10 and the execution engine 20 may be respectively implemented on the same or different computing devices, where each computing device may include at least one processor and at least one memory coupled with the at least one processor having stored therein instructions executable by the at least one processor that, when executed by the at least one processor, perform at least a portion of the method 300 as described below. For example, a memory of a computing device serving as state machine configuration device 10 may have stored therein a state machine configuration file as described below, which a processor of the computing device serving as execution engine 20 may run to implement a corresponding application.
In a multi-join application, the logical relationships between the various state nodes may be sequential execution, parallel execution, distributed execution, looping execution, etc., so different node types and node actions (sets) may be defined for the state nodes of the state machine based on these logical relationships.
Fig. 2 shows a schematic diagram of a state machine 200 according to an embodiment of the invention. As shown in fig. 2, state machine 200 includes a plurality of state nodes (6 state nodes 201, 202, 203, 204, 205, and 206 are schematically shown in fig. 2) connected by a plurality of edges (7 edges 211, 212, 213, 214, 215, 216, and 217 are schematically shown in fig. 2). For each state node, depending on the node type, it may have one or more incoming edges (referred to herein as incoming edges) and one or more outgoing edges (referred to herein as outgoing edges). Note that the logical relationship between its various states differs for each application to be implemented, and thus the form of its state machine may differ from the state machine 200 shown in fig. 2.
As described above, the node types of the state nodes may be defined as a sequence node, a bifurcation node, a merge node, a bifurcation merge end node, and an internal loop node according to the logical relationship among the respective state nodes being sequential execution, parallel execution, distributed execution, loop execution, and the like. A sequential (Normal) node refers to a sequentially executing node that has only one incoming edge and one outgoing edge, as shown by state nodes 201 and 204 in FIG. 2; a Fork (Fork) node refers to a node having multiple next state nodes executing in parallel, with one incoming edge and multiple outgoing edges, such as state node 202 shown in fig. 2; a merge (Join) node refers to a node that executes in parallel with at least one other node, has an incoming edge and an outgoing edge, and the outgoing edge points to a next state node that is at least the same as the next state node of the other state node, such as state nodes 203 and 205 shown in fig. 2; the forking join finish (ForkJoinFinish) node refers to a node to which a plurality of merging nodes converge, such as the state node 206 shown in fig. 2. Further, the inner loop node refers to a node that is repeatedly executed, and is not shown in fig. 2.
FIG. 3 shows a flow diagram of a method 300 for configuring a state machine in accordance with an embodiment of the invention. The method 300 may be performed, for example, by the state machine configuration device 10 as described above.
As shown in fig. 3, method 300 includes step 310, wherein state machine configuration device 10 determines a node type and a node unique identifier for each node of a plurality of state nodes of the state machine based on the logical relationship of the multi-loopback application to be implemented.
In particular, the state machine configuration device 10 may determine the logical relationship of the multi-join application to be implemented and establish a state machine 200 as shown in fig. 2. For each state node in state machine 200, its node type may be uniquely determined based on the logical relationship of the multi-closure application. Furthermore, in order to distinguish the individual state nodes, the state machine configuration device 10 also assigns a node unique identifier to each state node.
In step 320, the state machine configuration device 10 may configure a node in-edge set (ingoingEdges) and a node out-edge set (outgoingEdges) for each state node based on the node type of the state node, where the node in-edge set includes one or more in-edge elements, and each in-edge element includes a node unique identifier of a previous state node of the state node. The node out-edge set includes one or more out-edge elements, each out-edge element including a node unique identifier of a state node next to the state node, an out-edge condition, and an out-edge order. Here, the edge condition in each edge-out element is used to indicate a condition to its next state node along the edge-out, and the edge-out order indicates an order to its next state node along the edge-out. Wherein the edge-out sequence of the edge-out elements can be the same or different. In the case that the out-edge orders of the multiple out-edge elements are the same, this indicates that the current state node goes to multiple next state nodes in parallel (i.e. the node type of the current state node is a bifurcation node).
At step 330, the state machine configuration device 10 may determine a set of node actions for each state node based on the logical relationship of the multi-loopback application, where the set of node actions includes an incoming action set (enteringActions), an event action set (eventyactions), and an outgoing action set (leavingActions). Wherein the set of incoming actions includes actions to be performed upon entering the state node, the set of outgoing actions includes actions to be performed upon leaving the state node, and the set of event actions includes actions to be performed between the set of incoming actions and the set of outgoing actions.
At step 340, the state machine configuration device 10 may organize the executable configuration file for each state node based on the node unique identifier for that state node, the node type, the node in-edge set, the node out-edge set, and the node action set. The executable configuration files of all state nodes of a state machine constitute the configuration file of the state machine.
FIG. 4 shows a flowchart of step 340 of orchestrating an executable configuration file for a state node, according to an embodiment of the invention. Note that in the following description, the description of the executable configuration file for each type of state node is focused on the difference in its configuration file from the other types of state nodes, and the description of the same parts is omitted.
As shown in fig. 4, step 340 may include sub-step 341 in which, for a state node whose node type is a sequential node, the state machine configuration device 10 configures the unique in-edge element and the unique out-edge element of the state node.
For example, referring to fig. 2, for a sequential node 201, assume that its node unique identifier is "STATE _ 201", which has only one in-edge element and one out-edge element, so its node in-edge set (ingoingdges) in the configuration file can be represented as:
which indicates that the node unique identifier of the previous STATE node of the sequential node 201 is "destination _ STATE".
The node out-of-edge set (outgoingEdges) can be expressed as:
which indicates that the node unique identifier of the next STATE node of the sequence node 201 is "STATE _ 202", the out-edge condition is null (null), and the out-edge sequence is 1.
In sub-step 342, for a state node whose node type is a forked node, the state machine configuration device 10 may configure a plurality of edge out elements of the state node, wherein the edge out elements have the same order of edge out.
For example, referring to fig. 2, for a forked node 202, assume that its node unique identifier is "STATE _ 202", which has two out-edge elements, so its node out-edge set (outgoingEdges) in the configuration file can be represented as:
which indicate that the node unique identifiers of the two next-STATE nodes of the forking node 202 are "STATE _ 203" and "STATE _ 204", respectively, the out-edge condition is null, and the out-edge order is both 1 (i.e., parallel processing).
In sub-step 343, for a state node whose node type is a merge node, the state machine configuration device 10 may configure the out-edge element of that state node to have at least the same next state node as another state node.
For example, referring to fig. 2, for the merge node 203, assume that its node unique identifier is "STATE _ 203", which has one out-edge element, so its node out-edge set (outgoingEdges) of the configuration file can be represented as:
for the merge node 205, assume that its node unique identifier is "STATE _ 205", which has one out-edge element, so its node out-edge set (outingedges) of the configuration file can be expressed as:
it can be seen that the two merge nodes 203 and 205 have the same next-state node.
In sub-step 344, for a state node whose node type is a bifurcated merge termination node, the state machine configuration device 10 may configure the number of last merge nodes of the state node.
For example, referring to fig. 2, for the bifurcated merge ending node 206, assuming that its node unique identifier is "STATE _ 206", the number of the last merge nodes of its bifurcated merge ending node can be configured as 2, i.e. included in its configuration file:
"type":"FORK_JOIN_FINISH",
"finishJoinTimes":2
which indicates that the state node will receive execution results from 2 previous state nodes (i.e., two merge nodes).
In sub-step 345, for a state node whose node type is an inner loop node, the state machine configuration device 10 may configure the set of entry actions for that state node to include the inner loop node itself.
Specifically, for example, for an inner loop node, assuming that its node unique identifier is "delete _ peak _ STATE", its entry action set (entry actions) of the configuration file may be configured as:
that is, for a STATE node (DEPORTATION _ SPEAK _ STATE) whose node type is an inner loop node, the inner loop node ("name": DEPORTATION _ SPEAK _ STATE ") itself will be included in the set of incoming actions (entering actions) in its configuration file, and the execution engine 20 will perform a loop operation at that STATE node when executing the configuration file.
In the above manner, a state machine configuration file (e.g., a configuration file in json (javascript Object notification) format) of the multi-turn application is established based on the logical relationship of the application by using the programmable state machine model. For each function in the state machine (e.g., "SUBMIT", "VOTE", etc.), its function may be implemented encoded separately. Therefore, the codes of the functions in the state machine and the state machine configuration file can be relatively independent, the reusability and the expandability of the codes are enhanced, and the software development is facilitated.
Fig. 5 shows a flow diagram of a method 500 of operating a state machine as described above, according to an embodiment of the invention. Method 500 may be performed, for example, by execution engine 20 as described above.
As shown in fig. 5, method 500 includes step 510, where at one state node of the state machine, execution engine 20 may determine whether a driving event is received. The state machine may be, for example, state machine 200 as shown in fig. 2, which includes a plurality of state nodes, each having a node unique identifier, a node type, a node in-edge set, a node out-edge set, and a node action set.
If it is determined that a driving event is received ("yes" at step 510), execution engine 20 may determine whether the driving event is a legitimate event triggering a state node of the state machine based on the driving event and the set of node actions for the state node at step 520. As previously described, the node action set for each state node includes an enter action set, an event action set, and an exit action set for that state node.
FIG. 6 shows a flowchart of step 520 of determining whether a driving event is a legitimate event triggering the state node, according to some embodiments of the invention.
In sub-step 521, execution engine 20 may determine whether the driving event belongs to a union of the node action sets of the state nodes of the state machine. As previously mentioned, each state node has its own set of node actions, in which various node actions are defined, and therefore the union of the node action sets of these state nodes constitutes the legal action set of the state machine. In sub-step 521, a determination can be made as to whether the received driving event is a legitimate event for the state machine by determining whether the driving event belongs to a legitimate set of actions for the state machine.
If it is determined that the driving event is the union of the node action sets of the state nodes of the state machine (i.e., the driving event is a legitimate event of the state machine, the determination of substep 521 is yes), then, in substep 522, execution engine 20 may add a fair lock to the state node.
Public lock is a special tool of Java, and adds a public lock to a state to lock the execution order of the state execution thread in multiple threads, so as to avoid confusion with the order of other threads during the execution of the thread.
Next, in sub-step 523, execution engine 20 may establish a snapshot of the state node.
Herein, snapshotting the state node refers to establishing a fully available copy of the data set of the state node using a snapshot technique, the copy including an image of the corresponding data at a snapshot start time point (a time point at which the copy starts) to facilitate online data backup and recovery. The specific manner of establishing the snapshot is not limited herein, and may be implemented using, for example, Copy On Write (COW) or I/O Redirect (I/O Redirect) technologies.
Next, in sub-step 524, execution engine 20 may determine whether the state node is functioning properly. Here, determining whether the state node operates normally may include, for example, determining whether the state node can respond normally, or the like. If the state node is not operating properly (decision "no" of substep 524), then operation of the current state node is terminated and the system may roll back to the previous state node or take other error correction action.
If it is determined that the state node is functioning properly ("yes" determination of substep 524), execution engine 20 may determine whether the driving event belongs to the node action set for the state node, in substep 525.
In sub-step 521 it is determined whether the driving event is a legal event for the entire state machine, and further in sub-step 525 it is determined whether the driving event is a legal event for the current state node.
Further, if it is determined in sub-step 525 that the driving event belongs to the node action set of the state node (the determination of sub-step 525 is "yes"), in sub-step 526, execution engine 20 may determine that the driving event is a legitimate event that triggers the state node.
On the other hand, if it is determined in sub-step 521 that the driving event does not belong to the union of the node action sets of the plurality of state nodes of the state machine (determination of sub-step 521 is no) or it is determined in sub-step 525 that the driving event does not belong to the node action set of the state node (determination of sub-step 525 is no), in sub-step 527, execution engine 20 may determine that the driving event is not a legitimate event that triggers the state node.
Continuing with FIG. 5, if it is determined that the driving event is a legitimate event that triggers the state node ("YES" of the determination of step 520), then in step 530, execution engine 20 may execute the set of node actions for the state node in turn to obtain the execution result for the state node.
As previously described, the node action set of each state node includes an enter action set, an event action set, and a leave action set in that order, with a corresponding order of actions between the actions in each of the enter action set, the event action set, and the leave action set. Thus, at step 530, the execution engine 20 may execute the sets in order of the incoming action set, the event action set, and the outgoing action set, and in each set execute the actions in the order of the actions in the set.
At step 540, execution engine 20 may determine whether an out-of-edge condition for the state node is satisfied based on the execution results for the state node.
In some embodiments, determining whether the execution result of the state node satisfies the out-of-bound condition of the state node may include: the node type of the state node is determined (as described above, the node type may include a sequence node, a fork node, a merge node, a fork merge end node, and an inner loop node), and then one or more edge out elements in the node edge out set of the state node are determined based on the node type of the state node. As previously described, each out-of-edge element includes the next state node, out-of-edge condition, and out-of-edge order for the out-of-edge element. Next, the execution engine 20 may sequentially determine whether the execution result of the state node meets an edge condition of one of the one or more edge elements according to an edge order of the one or more edge elements.
As previously described, in the configuration file of each state node, the node edge-out set (outgoingEdges) includes one or more edge-out elements, and each edge-out element includes an edge-out condition ("condition") of the edge-out element, which indicates a condition that needs to be satisfied to leave the state node.
For example, as described above, for the sequence node 201, the out-edge element in its node out-edge set includes "condition": null ", which means that the out-edge condition of the state node is empty, i.e., no special out-edge condition is needed.
More specifically, corresponding to fig. 4 above, determining one or more out-edge elements in the node out-edge set of the state node may include any of:
if the node type of the state node is determined to be a sequential node, execution engine 20 may determine the only out-of-edge element of the sequential node;
if the node type of the state node is determined to be a forked node, execution engine 20 may determine a plurality of edge out elements of the forked node, where the edge out elements have the same edge out order;
if it is determined that the node type of the state node is a merge node, execution engine 20 may determine a unique out-edge element of the merge node, the unique out-edge element of the merge node having at least a next state node that is the same as another state node;
if it is determined that the node type of the state node is a split merge termination node, the execution engine 20 may determine the number of previous merge nodes of the split merge termination node; and
if it is determined that the node type of the state node is an inner loop node, the execution engine 20 may execute a loop operation at the inner loop node.
Continuing with FIG. 5, if it is determined that the execution result for the state node satisfies an out-of-edge condition for the state node ("YES" of step 540), execution engine 20 may transition the state machine from the state node to a next state node corresponding to the out-of-edge condition at step 550.
Further, after transitioning the state machine from the state node to a next state node corresponding to the out-of-edge condition, execution engine 20 may also release the fair lock of the state node.
On the other hand, if the determination of step 510 or 540 is negative, the execution engine 20 may end the operation of the current state node.
FIG. 7 illustrates a block diagram of a computing device 700 suitable for implementing embodiments of the present invention. The computing device 700 may be, for example, the state machine configuration device 10 or the execution engine 20 as described above.
As shown in fig. 7, computing device 700 may include one or more Central Processing Units (CPUs) 710 (only one of which is schematically shown) that may perform various suitable actions and processes in accordance with computer program instructions stored in a Read Only Memory (ROM)720 or loaded from a storage unit 780 into a Random Access Memory (RAM) 730. In the RAM 730, various programs and data required for the operation of the computing device 700 may also be stored. The CPU 710, ROM 720, and RAM 730 are connected to each other via a bus 740. An input/output (I/O) interface 750 is also connected to bus 740.
A number of components in computing device 700 are connected to I/O interface 750, including: an input unit 760 such as a keyboard, a mouse, and the like; an output unit 770 such as various types of displays, speakers, and the like; a storage unit 780 such as a magnetic disk, an optical disk, or the like; and a communication unit 790 such as a network card, modem, wireless communication transceiver, etc. The communication unit 790 allows the computing device 700 to exchange information/data with other devices over a computer network, such as the internet, and/or various telecommunications networks.
The methods 300 and/or 500 described above may be performed, for example, by the CPU 710 of the computing device 700. For example, in some embodiments, methods 300 and/or 500 may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 780. In some embodiments, some or all of the computer program may be loaded onto and/or installed onto computing device 700 via ROM 720 and/or communications unit 790. When the computer program is loaded into RAM 730 and executed by CPU 710, one or more operations of methods 300 and/or 500 described above may be performed. Further, the communication unit 790 may support wired or wireless communication functions.
Those skilled in the art will appreciate that the computing arrangement 700 illustrated in FIG. 7 is merely illustrative. In some embodiments, state machine configuration device 10 and/or execution engine 20 may contain more or fewer components than computing device 700. For example, where state machine configuration device 10 and/or execution engine 20 is a portable mobile terminal, it may contain fewer components than shown in computing device 700.
The present invention may be methods, apparatus, systems and/or computer program products. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied therein for carrying out aspects of the present invention.
In one or more exemplary designs, the functions described herein may be implemented in hardware, software, firmware, or any combination thereof. For example, if implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium.
The units of the apparatus disclosed herein may be implemented using discrete hardware components, or may be implemented integrally on a hardware component, such as a processor. For example, the various illustrative logical blocks, modules, and circuits described in connection with the present invention may be implemented or performed with a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein.
Those of skill would further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both.
The previous description of the invention is provided to enable any person skilled in the art to make or use the invention. Various modifications to the disclosure will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other variations without departing from the spirit or scope of the disclosure. Thus, the present invention is not intended to be limited to the examples and designs described herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims (10)
1. A method of running a state machine, comprising, by an execution engine:
determining, at a state node of the state machine, whether a driving event is received, wherein the state machine comprises a plurality of state nodes, each state node having a node unique identifier, a node type, a node in-edge set, a node out-edge set, and a node action set;
in response to determining that the driving event is received, determining whether the driving event is a legitimate event that triggers the state node based on the driving event and node action sets of the plurality of state nodes of the state machine, wherein the node action set of each state node includes an enter action set, an event action set, and a leave action set of the state node;
in response to determining that the driving event is a legal event triggering the state node, sequentially executing a node action set of the state node to obtain an execution result of the state node;
determining whether an out-of-edge condition of the state node is satisfied based on the execution result of the state node; and
in response to determining that the result of the execution of the state node satisfies an edge condition for the state node, transitioning the state machine from the state node to a next state node corresponding to the edge condition.
2. The method of claim 1, wherein determining whether the driving event is a legitimate event triggering the state node based on the driving event and a set of node actions of the plurality of state nodes of the state machine comprises:
determining whether the driving event belongs to a union of node action sets of the plurality of state nodes of the state machine;
in response to determining that the driving event belongs to a union of node action sets of the plurality of state nodes of the state machine, adding a fair lock to the state nodes;
establishing a snapshot of the state node;
determining whether the state node operates normally; and
in response to determining that the state node is functioning properly, determining whether the driving event belongs to a node action set of the state node.
3. The method of claim 2, wherein determining whether the driving event is a legitimate event that triggers the state node based on the driving event and a set of node actions of the plurality of state nodes of the state machine further comprises:
in response to determining that the driving event belongs to the set of node actions for the state node, determining that the driving event is a legitimate event that triggers the state node; and
determining that the driving event is not a legal event that triggers the state node in response to determining that the driving event does not belong to a union of node action sets of the plurality of state nodes of the state machine or in response to determining that the driving event does not belong to a node action set of the state nodes.
4. The method of claim 2, further comprising:
and after the state machine is transferred from the state node to a next state node corresponding to the edge condition, releasing the fair lock of the state node.
5. The method of claim 1, wherein determining whether an edge condition of the state node is satisfied based on the results of the execution of the state node comprises:
determining the node types of the state nodes, wherein the node types comprise sequence nodes, bifurcation nodes, combination nodes, bifurcation combination end nodes and internal circulation nodes;
determining one or more edge-out elements in a node edge-out set of the state nodes based on the node types of the state nodes, wherein each edge-out element comprises a next state node of the edge-out element, an edge-out condition and an edge-out sequence; and
and sequentially determining whether the execution result of the state node meets the edge condition of one of the one or more edge elements according to the edge sequence of the one or more edge elements.
6. The method of claim 5, wherein determining one or more out-edge elements in the node out-edge set of the state node comprises one of:
in response to determining that the node type of the state node is a sequential node, determining a unique out-of-edge element of the sequential node;
in response to determining that the node type of the state node is a bifurcation node, determining a plurality of out-edge elements of the bifurcation node, wherein the plurality of out-edge elements have the same out-edge order;
in response to determining that the node type of the state node is a merge node, determining a unique out-edge element of the merge node, the unique out-edge element of the merge node having at least a next state node that is the same as another state node;
in response to determining that the node type of the state node is a split merge ending node, determining a number of previous merge nodes of the split merge ending node; and
in response to determining that the node type of the state node is an inner loop node, performing a loop operation at the inner loop node.
7. A method of configuring a state machine, comprising:
determining a node type and a node unique identifier for each node of a plurality of state nodes of the state machine based on a logical relationship of a multi-closure application to be implemented;
configuring a node entry edge set and a node exit edge set for each state node based on the node type of the state node, wherein the node entry edge set comprises one or more entry edge elements, each entry edge element comprises a node unique identifier of a previous state node of the state node, the node exit edge set comprises one or more exit edge elements, and each exit edge element comprises a node unique identifier of a next state node of the state node, an exit edge condition and an exit edge sequence;
determining a node action set for each state node based on a logical relationship of the multi-turn application, wherein the node action set comprises an entry action set, an event action set, and an exit action set; and
arranging an executable configuration file of each state node based on the node unique identifier of the state node, the node type, the node edge entering set, the node edge exiting set and the node action set.
8. The method of claim 7, wherein orchestrating the executable configuration file of the state node comprises:
configuring a unique edge entry element and a unique edge exit element of a state node for the state node of which the node type is a sequential node;
for a state node of which the node type is a bifurcation node, configuring a plurality of edge-out elements of the state node, wherein the edge-out elements have the same edge-out sequence;
for a state node of which the node type is a merge node, configuring an edge-out element of the state node as a next state node having at least the same as another state node;
configuring the number of the last merging nodes of the state nodes for the state nodes of which the node types are the bifurcation merging end nodes; and
for a state node whose node type is an inner loop node, configuring the set of entry actions of the state node to include the inner loop node.
9. A computing device, comprising:
at least one processor; and
at least one memory coupled to the at least one processor and storing instructions for execution by the at least one processor, the instructions when executed by the at least one processor causing the computing device to perform the steps of the method of any of claims 1-6 and/or any of claims 7-8.
10. A computer readable storage medium having stored thereon computer program code which, when executed, performs the method of any of claims 1 to 6 and/or 7 to 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210302133.9A CN115061718B (en) | 2022-03-24 | 2022-03-24 | Method for configuring and operating a state machine, computing device and computer storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210302133.9A CN115061718B (en) | 2022-03-24 | 2022-03-24 | Method for configuring and operating a state machine, computing device and computer storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN115061718A true CN115061718A (en) | 2022-09-16 |
CN115061718B CN115061718B (en) | 2023-12-22 |
Family
ID=83197149
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210302133.9A Active CN115061718B (en) | 2022-03-24 | 2022-03-24 | Method for configuring and operating a state machine, computing device and computer storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115061718B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118760485A (en) * | 2024-09-09 | 2024-10-11 | 奥特酷智能科技(南京)有限公司 | State machine model construction method, operation method, operation device and storage medium |
Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1846419A (en) * | 2003-07-31 | 2006-10-11 | 伊尼格马泰克公司 | self-managed media flow |
CN103049264A (en) * | 2012-12-17 | 2013-04-17 | 国电南京自动化股份有限公司 | Method for controlling business system by dynamic modeling of state machine |
US20140122929A1 (en) * | 2012-10-31 | 2014-05-01 | Scott P. Nixon | Distributed on-chip debug triggering |
CN103795565A (en) * | 2013-12-27 | 2014-05-14 | 北京天融信软件有限公司 | Network event correlation analysis method and device |
WO2015058293A1 (en) * | 2013-10-23 | 2015-04-30 | Mcafee, Inc. | Method and processes for securely autofilling data fields in a software application |
CN108665239A (en) * | 2018-05-08 | 2018-10-16 | 平安普惠企业管理有限公司 | Workflow processing method, device, computer equipment and storage medium |
CN109753540A (en) * | 2018-12-03 | 2019-05-14 | 新华三云计算技术有限公司 | Shared resource access method, device and computer-readable storage medium |
CN111061579A (en) * | 2019-12-31 | 2020-04-24 | 安徽智恒信科技股份有限公司 | Method and system for transferring information of intelligent cabinet driven by multi-state machine events |
CN111164952A (en) * | 2017-11-16 | 2020-05-15 | 英特尔公司 | Distributed software-defined industrial system |
CN112068810A (en) * | 2020-08-27 | 2020-12-11 | 北京五八信息技术有限公司 | Activity event processing method and device, electronic equipment and storage medium |
CN112308541A (en) * | 2020-12-29 | 2021-02-02 | 南京智闪萤科技有限公司 | Method, computing device and computer storage medium for processing approval business process |
CN113296933A (en) * | 2020-08-14 | 2021-08-24 | 阿里巴巴集团控股有限公司 | Event processing method, device, equipment and machine-readable storage medium |
-
2022
- 2022-03-24 CN CN202210302133.9A patent/CN115061718B/en active Active
Patent Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1846419A (en) * | 2003-07-31 | 2006-10-11 | 伊尼格马泰克公司 | self-managed media flow |
US20140122929A1 (en) * | 2012-10-31 | 2014-05-01 | Scott P. Nixon | Distributed on-chip debug triggering |
CN103049264A (en) * | 2012-12-17 | 2013-04-17 | 国电南京自动化股份有限公司 | Method for controlling business system by dynamic modeling of state machine |
WO2015058293A1 (en) * | 2013-10-23 | 2015-04-30 | Mcafee, Inc. | Method and processes for securely autofilling data fields in a software application |
CN103795565A (en) * | 2013-12-27 | 2014-05-14 | 北京天融信软件有限公司 | Network event correlation analysis method and device |
CN111164952A (en) * | 2017-11-16 | 2020-05-15 | 英特尔公司 | Distributed software-defined industrial system |
CN108665239A (en) * | 2018-05-08 | 2018-10-16 | 平安普惠企业管理有限公司 | Workflow processing method, device, computer equipment and storage medium |
CN109753540A (en) * | 2018-12-03 | 2019-05-14 | 新华三云计算技术有限公司 | Shared resource access method, device and computer-readable storage medium |
CN111061579A (en) * | 2019-12-31 | 2020-04-24 | 安徽智恒信科技股份有限公司 | Method and system for transferring information of intelligent cabinet driven by multi-state machine events |
CN113296933A (en) * | 2020-08-14 | 2021-08-24 | 阿里巴巴集团控股有限公司 | Event processing method, device, equipment and machine-readable storage medium |
CN112068810A (en) * | 2020-08-27 | 2020-12-11 | 北京五八信息技术有限公司 | Activity event processing method and device, electronic equipment and storage medium |
CN112308541A (en) * | 2020-12-29 | 2021-02-02 | 南京智闪萤科技有限公司 | Method, computing device and computer storage medium for processing approval business process |
Non-Patent Citations (2)
Title |
---|
O. KASTEN 等: "Beyond event handlers: programming wireless sensors with attributed state machines", 《IPSN 2005. FOURTH INTERNATIONAL SYMPOSIUM ON INFORMATION PROCESSING IN SENSOR NETWORKS》, pages 45 - 52 * |
林水强 等: "姿势序列有限状态机动作识别方法", 《计算机辅助设计与图形学学报》, vol. 26, no. 09, pages 1403 - 1411 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118760485A (en) * | 2024-09-09 | 2024-10-11 | 奥特酷智能科技(南京)有限公司 | State machine model construction method, operation method, operation device and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN115061718B (en) | 2023-12-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110730204B (en) | Method for deleting nodes in block chain network and block chain system | |
CN110896404B (en) | Data processing method and device and computing node | |
WO2021042885A1 (en) | Method for adding node to blockchain network, and blockchain system | |
CN112286945B (en) | Configuration change method, system, device and medium based on PBFT algorithm | |
CN112104727B (en) | Method and system for deploying simplified high-availability Zookeeper cluster | |
EP4030314A1 (en) | Blockchain-based data processing method, apparatus and device, and readable storage medium | |
US10409620B2 (en) | Spanning tree protocol warm reboot system | |
CN112714158A (en) | Transaction processing method, relay network, cross-link gateway, system, medium, and device | |
EP4095685A1 (en) | State machine processing method and apparatus, state processing method and apparatus, electronic device, and storage medium | |
CN112492016A (en) | Cross-process extensible consensus method and system | |
CN115061718A (en) | Method, computing device and computer storage medium for configuring and running state machine | |
CN112416515A (en) | Method, system, equipment and medium for deploying Keepalived cluster | |
CN108062244A (en) | The canceling method and device of reptile task | |
JP7629546B2 (en) | Electric vehicle charging management and client device | |
CN112202933A (en) | Information processing method and device of block chain network and node equipment | |
CN113791792B (en) | Method, device and storage medium for acquiring application call information | |
CN113703996B (en) | Access control method, equipment and medium based on user and YANG model grouping | |
CN111737350B (en) | A method and device for selecting a consensus mechanism based on a distributed system | |
CN111813606A (en) | Fault-tolerant method, system, equipment and medium for double-node virtual machine | |
CN113032477A (en) | Long-distance data synchronization method and device based on GTID and computing equipment | |
CN108206823B (en) | A method, system and network device for processing messages | |
CN116346728A (en) | Low code platform current limiting method and device | |
CN111884932B (en) | Link determining method, device, equipment and computer readable storage medium | |
CN117478299B (en) | Block chain consensus algorithm switching method, device and computer equipment | |
CN112422635A (en) | Data checking method, device, equipment, system and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |