In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Under the Dazhong Taiwan strategy, China Central Taiwan will sink the public capacity of the company's business, and adopt a more reasonable and reusable architecture and technology to achieve these basic capabilities. In the e-commerce industry, it will face a large number of state maintenance, such as purchase of goods, shelves of goods, occurrence of transactions, changes in the status of orders, customer service intervention and so on. There is a strong logical relationship between each state, for example, the refund operation will be a completely different process before and after shipment, as shown in figure 1.
Figure 1 refund flow chart
Thus it can be seen that the management of complex states is a scenario of business dependence and changeable requirements. In the start-up period of the company, hard-coding can be used to judge the status of each operation and customize a set of logical links for each operation. With the increase of business, customized links are obviously not elegant, and a large number of process codes can not be maintained. at this time, the general solution of China and Taiwan is particularly important. Finite State Machine (Finite State Machine, abbreviation: FSM) began to land in China.
1 finite state machine
Finite state machine (hereinafter referred to as FSM) is also called finite state automaton, referred to as state machine. Wikipedia is defined as a mathematical model that represents a limited number of states and behaviors such as transitions and actions between them.
This model is very consistent with the problems encountered in the business center. Figure 1 is a state transition diagram, which can be used to represent a state machine, as well as a state transition table. As shown in figure 2:
Figure 2 State transition table
It can be seen that FSM is a model that manages a limited number of state transitions by abstracting it into actions and states. An action is a description of the activity to be carried out at a given time. We summarize the action types as follows:
Enter action: to perform when entering a state
Exit action: occurs when exiting state
Input actions: depending on the current state and input conditions
Transfer action: when a specific transfer is made
Under the framework of FSM, the state transfer process of the pipeline is abstracted and structured, and the complex state transition diagram is divided into the smallest units of adjacent states. This is equivalent to building Lego blocks, which can be combined into complex state transition diagrams on this mechanism.
2 Spring StateMachine
The main purpose of the Spring Statemachine framework is to help developers simplify the development process of the state machine and make the state machine structure more hierarchical. Let's take a look at how to implement Spring SM. First, the smallest Lego model is shown in figure 3:
Figure 3 SM minimum unit
If there is a state STATE1, STATE2 and event EVENT1, EVENT2. Event-driven state flow. Let's analyze the main code of Spring SM.
2.1 relying on pom
Org.springframework.statemachine
Spring-statemachine-core
2.1.3.RELEASE
2.2 create a state machine
Register the three elements of the state machine through annotations: source, target, and event
2.3 Annotation listener
Perceive the occurrence of events through the listener and deal with the relevant logic accordingly
2.4 running the state machine
(3) transaction center
In the transaction scenario, we define our own state machine framework and abstract the state roles in accordance with the transaction scenario:
Initial state, target state: state relationship
Roles: different roles have different operation permissions, such as seller, buyer, system, customer service
Actions: corresponding event
Handler: the action implementation corresponding to the event action
So an event can be defined as: in role A, under the initial state S1, the OP1 operation will be processed using handler, and the execution successfully sets the state to the target state S2.
3.1Personalized FSM abstraction
In view of the personalized needs of the transaction, the conditions of the state table are extended, and both handler and Java reflection are used to further structure the logic code. After this step, we can store the data template in the database. Figure 4:
Figure 4 FSM status table in the middle of the transaction
Through the modification, the core code FSM execution engine has less than 100 lines. By registering the business handler, the business capability can be expanded flexibly. At the same time, the maintenance of data state is through the state table, rather than relying on manual coding, which saves a lot of time for code quality assurance and engineering regression testing. It also lays the groundwork for the configuration of China Central Station.
3.2 Central Taiwan enabling service
China Taiwan has precipitated the basic capacity, how to achieve it? How does CCTV enable the business? is the business satisfactory?
Look at the following example, based on transactions, C2C and proprietary are two very different businesses, and they have two completely different sets of business processes. C2C platform needs to guarantee both sides of the sale and purchase, while self-management is more likely to guarantee the rights and interests of buyers. The simplified version flow is shown in figure 5:
Figure 5 simplified version of the transaction process
Through the FSM capability of China Central Station, as long as we can draw the state diagram, then the corresponding state flow table configuration has also been generated. Handler only needs to pay attention to the business logic of the current operation, greatly decoupling the state and business.
It is no exaggeration to say that when a new business comes, China Central Station can single-person complete the state machine configuration development and launch within 2 days. This is the efficiency of CCTV.
4 Summary
FSM solves the problem of complex business state flow, and takes the trading business as an example. But FSM has far more application scenarios than transactions. Such as customer service work order, commodity status and so on. But not all processes need to use FSM, need to make a good business process compromise, just as the Taiwan strategy is more suitable for companies in the 10-100 stage.
At the same time, FSM is only a framework, and we need to build a set of peripheral business logic based on it. In the process of state transfer, business logic is our muscle. The frame is like a skeleton that binds us to make the technology grow healthier, which may be the charm of Zhongtai.
More free technical materials and videos
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.