Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement a process choreography Framework with java

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how to achieve a process choreography framework java related knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you have something to gain after reading this article, let's take a look at it.

Process registration

It was mentioned earlier that to support the formal registration process model of yml, properties, xml, json and interface, in order to reflect the principle of single responsibility, we need to deal with a kind of format parsing logic independently. In order to reflect the extension development and the modification shutdown principle, we first define a set of interfaces, and then provide the corresponding implementation logic through the factory pattern. Here the factory is the consumer, and the specific implementation is called through the interface, which in this case is the provider and a set of policy patterns.

Process loading

Process loading we need to know several other requirements function points: 1, provide external unified access interface; 2, provide execution records and execution time-consuming; 3, different process nodes need to define different parsers; 4, create parsing types through factories; 5, process nodes are executed sequentially.

Different parsing methods are performed by different node types, it is obvious that factory mode is needed to create parsing classes, and external extension development is turned off for modification, and new nodes do not need to use other code logic. Just add a node parser to the factory function. At the same time, we define a Map collection to create the parsing object when the factory function is loaded, instead of creating a parser every time it is parsed, reducing unnecessary memory.

The code is as follows:

Public class NodeComponentFactory {

Private final static Map cacheParser = new HashMap ()

Static {

CacheParser.put (NodeParserEnum.method.name (), new MethodNodeComponent ())

CacheParser.put (NodeParserEnum.bean.name (), new BeanNodeComponent ())

CacheParser.put (NodeParserEnum.condition.name (), new ConditionNodeComponent ())

CacheParser.put (NodeParserEnum.service.name (), new ServiceNodeComponent ())

CacheParser.put (NodeParserEnum.subflow.name (), new SubFlowNodeComponent ())

}

Public static NodeParser getNodeInstance (String nodeName) {

Return cacheParser.get (nodeName)

}

}

When we find that every node parsing type needs to implement the parser interface, and each node has similar steps, then we need to consider using an abstract factory here, which is also in line with a design principle of dependency inversion. The upper module is accessed by relying on the interface, and the next module inherits the abstract class. At the same time, the policy pattern is also used for interface calls. In the logical process of implementation, we will find that many steps are repeated, such as initializing input parameters, executing records, all of which we put the repetitive content into abstract classes, through the way of template pattern, let the process node only focus on the parsing level.

Public abstract class AbstractNodeComponent implements NodeParser {

Public Map nodeMap

/ * *

* initialization parameters

* @ param inputUrl

* @ param baseInput

* @ return

, /

Public BaseInput initInput (String inputUrl, BaseInput baseInput) {

BaseInput baseInputTarget = ClassUtil.newInstance (inputUrl, BaseInput.class)

BeanUtils.copyProperties (baseInput,baseInputTarget)

Return baseInputTarget

}

/ * *

* parsing node information

* @ param node Node Information

* @ param baseInput request parameters

* @ param baseTemp temporary context

* @ return

, /

Public BaseOutput parserNode (Node node, BaseInput baseInput, BaseTemp baseTemp) {

BaseTemp.setFlowRecord (baseTemp.getFlowRecord () .append (FlowConstants.NODEKEY+FlowConstants.NODE+FlowConstants.COLON+node.getId ()

BaseOutput baseOutput = parser (node, baseInput, baseTemp)

Return baseOutput

}

@ Override

Public void setNodeMap (Map nodeMap) {

This.nodeMap = nodeMap

}

@ Override

Public abstract BaseOutput parser (Node node, BaseInput baseInput, BaseTemp baseTemp)

} process loading order

In the process execution, we need to divide the components very finely, and it is best to divide the classes that independently implement a function into a component, reflecting the principle of a single responsibility, and as long as the executive functions are divided in detail, it can be flexibly combined in each process of the process execution. You can see several components in the following flowchart, the first is the entrance to the unified execution of the process, which will be used in two places, the first is the interface for external calls, and the second is the entry for the execution of the subprocess; the second component is the node's unified load management component, that is, the factory class mentioned above; the third is each component's own parser, which is used to implement the operations of different types of nodes. In the process of design, we must know the boundary between the process, management and nodes, and reduce the coupling. Only in this way can different components be composed flexibly.

These are all the contents of the article "how to implement a process choreography framework in java". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report