java 要使用的工作流设计模式类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17829386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Type of workflow design pattern to use?
提问by seesee
I have a workflow that goes in sequence
我有一个按顺序运行的工作流程
A - > B - > C - > D - > E
A - > B - > C - > D - > E
I need a design pattern that allow me to add a state in between them with least code change.
我需要一种设计模式,允许我以最少的代码更改在它们之间添加状态。
http://en.wikipedia.org/wiki/Workflow_patterns
http://en.wikipedia.org/wiki/Workflow_patterns
Which of these design pattern works?
这些设计模式中的哪一个有效?
回答by vanto
You could look into petri-net implementions, calculus-inspired frameworks like Jacob, virtual machines for processes like the PVMor a statemachine implementation like SCXMLalthough the latter are waiting for state changes and then do something, so you need to sort of change your control flow into data flow.
您可以研究 Petri-net 实现、像Jacob这样的微积分启发的框架、像PVM这样的进程的虚拟机或像SCXML这样的状态机实现,尽管后者正在等待状态变化然后做一些事情,所以你需要改变你的控制流进入数据流。
If you want to implement it yourself, you need to make sure that you give the control back to some runtime controller instead of just calling the next node, because that would blow your stack. This runtime controller could also inject a context object into the activity runnables and that way you can share state between the activities. Please find a rough sketch as pseudo code below:
如果您想自己实现它,您需要确保将控制权交还给某个运行时控制器,而不是仅仅调用下一个节点,因为这会破坏您的堆栈。这个运行时控制器还可以将上下文对象注入到活动的可运行对象中,这样您就可以在活动之间共享状态。请在下面找到一个粗略的草图作为伪代码:
interface Activity {
Activity run(SharedContext context);
}
class A implements Activity {
public Activity run(SharedContext context) {
doA(context);
return new B();
}
}
class B implements Activity {
public Activity run(SharedContext context) {
doB(context);
return new C();
}
}
// runtime controller
SharedContext context = new SharedContext();
Activity next = new A();
while (next != null) {
next = next.run(context);
}
回答by Rakesh
You can try activiti. You can also design your own workflow using the eclipse plugin
你可以试试活动。您还可以使用eclipse 插件设计自己的工作流程