Zeebe service state machine learning 2-

1. What is the state machine?

First exposure to the term, feeling that he is aware of this stuff is getting better, but later found, emm ..., yes, but understand this word only.

Posted about the official description:

Finite state machine (English: Finite- State Machine, FSM), also known as finite state automata, referred to as a state machine, is a mathematical model of the behavior of a finite number of states as well as the transfer and movement between these and other states. 

Finite state machine is a tool used for modeling the behavior of the object, its main function is to describe the object in its life cycle experienced by the state sequence, as well as how to respond to events from the outside world. In computer science, finite state machine is Modeling application behavior, system hardware design, software engineering, compilers, network protocols, and computing and language widely used.

 

2. The state machine dim?

Said so much, show me the code! The specific state machine can be doing? Otherwise, I learn doing it, Dragon of the surgery, the school can only boast blow it.

For example, a simple description of the scene, and now there is a process: a library -> Edit Inventory -> delivery.

 


Each document has three states, CREATED, ACTIVITED, COMPLETED; we usually deal with such calls, according to the new storehouse, this time the documents state is CREATED,

Before the document does not confirm the completion of the document is ACTIVITED state,

If confirmed this new success, and then update the document to COMPLETED;

If you want to continue with this process, you will need to make a judgment on the state of the documents out of the library, if it is ACTIVITED, you can not modify the stock to `` *;

If the status is COMPLETED, then to modify inventory documents;

Similarly, there are three states on modifying inventory documents ... .. and so on, each document must go update their status, and then determine whether the documents state to meet the conditions, in order to confirm whether the method of execution downstream.

For the above example was very simple, if the process is particularly long, then repeat this update, judgment is not too tired? So tired, we are not programmers did not do ah?

At this time, we can use our protagonist: the state machine debut.

The state machine maintenance status: CREATED, ACTIVITED, COMPLETED.

Change of state is triggered by an event, the formula is replaced by:

State(S) + Event(E) -> Actions (A), State(S')

An old state, after a trigger event, the occurrence of a behavior, then the state into a new state.

The benefits of the state machine is separated by the states and events, by the above formula, the logic is decoupled into a group of a formula to finish, the event will only be triggered, the behavior associated with the event to perform,

Then the business will not have to worry about if else, and just to trigger the associated event on the line.

 

3.Zeebe framework ye use?

Each service node Zeebe framework are three states: CREATED, ACTIVITED, COMPLETED.

Example: When a node entity via createEvent triggered, causing create behavior, the state becomes the entity CREATED;

When the trigger a activeEvent, generates an active behavior (calling the new JobWorker), the entity becomes ACTIVITED; JobWorker when the new call is completed, triggering compleEvent,

At this time, the entity status is updated Zeebe COMPLETED.

These processes, for Zeebe service the caller is not visible, developers will find that their new node process has been completed, the following entered the service node.

 

参考:(1)https://blog.csdn.net/qq_30739519/article/details/89444631
           (2)https://blog.csdn.net/xinghuanmeiying/article/details/81586954

Guess you like

Origin www.cnblogs.com/walt/p/11328843.html