Graph Oriented Programming(面向图形编程)
Workflow is mostly related to the management of tasks for people. The core focus of a workflow process specifies tasks performed by humans are related to achieve a certain process goal.
工作流主要是与人们任务的管理相关。一个工作流过程限定被人任务执行的核心焦点是与完成一个确定的流程目标。
Suspending an execution in java is not possible. Actually, it is possible to suspend and resume a thread in java (with e.g. Object.wait() and Object.notify()). But this does not match the needs for the process wait states because of persistence. Workflow, BPM and orchestration solutions need to persist(持久层) their execution during wait states. In fact, state changes in a process should correspond to transactions on a server. Inbetween those transactions the suspended(暂停的) execution should be persistable in e.g. a database or on the file system.
Actually, it is not so surprising that java does not have a built-in(内置的) mechansim for suspending and persisting executions. That is because java is built on top of the Von Neumann architecture. This essentially(本质上) comes down to an environment for executing a sequence(序列) of instructions(指令). This article presents a technique for extending the Von Neumann architecture for supporting the suspension and persistence of executions.
Products in the three fields(领域) have all solved this problem in their own way, from their own perspective(观点). As a consequence(推理), each solution combined a technique for suspending an execution with a whole lot of other functionalities. This is the fundamental reason why these topics are perceived(察觉、感知到) as confusing(混淆的) and unclear(不清楚的) by the development community.
图形表现和开发流程
The technical ability to suspend an execution creates a very interesting opportunity(机会、时机) : a direct link between the business process and the technical implementation(商业流程和技术实现). The business process is a central part of the requirements specified by the business analyst. Without a mechansim for suspending executions, the implementation of the business process requires a complex translation into a software design. In that case(如果是那样的话), the developer will have to store the executional state(执行状态) in some form in the database during wait states. This complexity(复杂性) is added and combined(被结合) with the functional requirements of the business process(商业流程的功能需求).
The conclusion(结论) is that it would be great if we could find a solution for suspending an execution that is related to the graphical representation of a business process. Many (probably all) of the graphical representations of business processes are based upon a directed graph. Some of the process languages are limited to a tree which is a subset of a directed graph. Those languages are called block structured languages(块结构语言).
An important consideration is that the proposed(建议) solution should embrace(包含) iterative(迭代的) development. With UML class diagrams, this is an established(确定的) practice. The analyst(分析家) can draw an analysis model in an UML class diagram. Then the developer takes this model as a starting point and transforms it into a design model. Adding more technical details will result(以...为) in an implementation. Too many proposed solutions ended up in being visual programming environments.
What is Graph Oriented Programming?(什么是面向图形编程?)
Graph oriented programming is a technique for solving problem of suspending and persisting an execution. Because of its limited scope, this technique, is easy to understand and serves as the building block for other functionalities targeted by workflow, BPM and orchestration solutions.
面向图表编程是为解决暂停或持久化执行的问题的一种技术。因为它限定的范围,这种技术,是容易理解并且服务于为其他功能性目标、BPM和orchestration解决方案建造模块。
The central idea of Graph Oriented Programming is that a we complement plain imperative(命令) programming with a runtime model for executing graphs. So a graph is specified as part of the software and at runtime, executions of the graph are coupled to the execution of the imperative programmed software.
面向图表编程的主要概念是,我们使用运行模式为执行图表完成清晰的命令程序。所以一个图表是被限定为软件的一部分,并且图表的执行是连接到命令程序软件的执行。
A process graph is made up of Nodes and Transitions. Transitions have a direction and connect two nodes in the graph.
一个流程图表是由节点和转变(transitions)组成的.转变有一个方向并且连接图表中的两个节点。
The graph can be seen as a state machine. Although, the executional model that we will explain here is concrete and has better support for concurrent paths of execution.
这个图表可以看做是一个状态机器。虽然我们这里解释的执行模式是具体的且更好的为并发路径执行提供更好的支持。
The following UML class diagram sketches(大略) how the process elements can be modelled in an UML class diagram. This also shows that a process graph can be represented(表现) as data. The process graph data can be expressed in different formats : XML, java objects, records in a database,...
The next part is the most difficult part to understand for programmers and technical people. That is because we are specifying an executional model that differs from the well known Von Neumann architecture.
We define a Token as a path of execution. It's a path of execution within one system.
我们定义了一个令牌作为执行路径。它是一个系统中的一个执行路径。
Note that an execution of a process can involve multiple concurrent paths of execution. We now define an execution of a process as a tree of tokens. A token has a pointer to a node in the process graph.
注意:一个流程的执行可以包括多个并发的执行路径。我们现在定义一个流程的执行作为一个令牌树。一个令牌做为流程图表中的一个节点的一个指针。
The following UML class diagram shows the tree of tokens modelled as a UML class diagram(UML 类图). This is included to show that an execution of a process can be represented as data. This is actually the crucial(至关重要的) part of making an execution persistable.
Now, we'll explain how the execution of java can be coupled to the execution of the graph. The next image shows the methods in Node and Transition that are involved in graph execution. To calculate the next state of an execution, we propose(计划) a modified version of the chain of responsibility pattern(责任链模式) as described by the GOF 'Design Patterns' book.
The Nodes in the graph can represent wait states. During a wait state, a Token points to that Node. Each Token that is in a Node can receive a signal. A Signal can be send to a Token to resume execution after a wait state is finished. This will cause the graph execution to start.
在图表中的节点可以表现为等待状态。在一个等待状态,一个令牌指向那个节点。在节点中每一个令牌可以接受一个信号。一个信号可以在等待状态完成后,可以发送一个令牌来重新执行。这将导致图表执行开始。
A Signal is the trigger that resumes graph execution. 信号是再继续图表执行的触发器。
The effect(结果) of this signal is that the Token will leave the node. In case(万一) the node has more then one leaving transition, the leaving transition has to be specified as part of the signal. Transitions just take a Token to the destination(目的) Node. When a token arrives in a Node, the Node is executed. Each node in the graph is of a specific type that determines(确定) its runtime behaviour. Each node type corresponds to a subclass of Node and the behaviour is implemented in the execute-method.
The node's execute-method has 2 responsibilities.[节点的执行方法有两个责任] First, it can perform some business logic, related to the type of the node. [首先,它可以运行一些商业逻辑,关系到节点的类型]E.g. sending a message, updating a database, creating a task for a user,...[例如发送消息,更新数据库,为用户创建一个任务,......] And the second responsibility of the node's execute-method is the propagation of the graph execution.[节点执行方法的第二个责任是传递图表的执行] If the node does not propagate the execution, it behaves as a wait state.[如果这个节点没有传递执行,它将作为一个等待状态。] It can propagate the token that arrived in the node down(沿着) one of the leaving transitions. Or it can create new Tokens and propagate those down the leaving transitions.
Graph execution ends when all tokens have entered a wait state.[当所有的令牌都进入等待状态,图表执行结束] At that time, the signal has been completely processed and the complete process execution (that is made up of a tree of tokens) enters a new overall(全面的) wait state. At this time, the tree of tokens can be persisted. Each token is now waiting to receive another signal.
One crucial(至关紧要的) refinement(精要) of this model is necessary : Actions(行为 动作). Actions are pieces of java code that are executed upon events in the process.[actions是在进程中事件之上执行的java代码片段] Examples of events are 'leaving a node', 'entering a node' and 'taking a transition'.[示例事件包括“离开一个节点”,"进入一个节点"、“接受一个转变”] These are all instantanious events that cannot span(跨越) wait states.
The refinement of the graph execution model with actions is necessary because this allows the technical developer to add implementation details to the business process, without having to change the graph that was originally(最初) created by the business analyst.
Now we can summarize how this model solves the traditional problems of workflow, BPM and orchestration solutions.
Simple API + chain of responsibility: replaces monolithic systems. 简单API+责任链
Inheriting from Node: gives ultimate(最终) process language power. 从节点中继承
Adding ‘invisible’ Actions: gives modelling freedom to the business analysts. 加入不视行为
Process development cycle: replaces visual programming. 过程开发周期