任何人都有使用Quick Sequence Diagram Editor的经验吗?即时显示+文本源代码+ Java实现的组合对我来说非常有吸引力,但是我无法弄清楚如何使语法按我的意愿行事,文档也不是很清楚。这是一个人为的例子:
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm.give me $10
atm:al has $3=bank.check al's account balance
al:atm.what time is it
atm:al.it's now
atm:al.stop bugging me
atm:al.you only have $3
atm:bill.and don't you open your mouth
bill:atm.who asked you?
bill:atm.give me $20
al:atm.hey, I'm not finished!
atm:bill has $765=bank.check bill's account balance
atm:yes I'm sure, bill has $765=bank.hmm are you sure?
atm:bill.here's $20, now go away
atm:great, he's a cool dude=bank.I just gave Bill $20
al:atm.what about my $10?
atm:al.read my lips: you only have $3
以下是QSDE在单线程模式下的结果:
并采用多线程模式:
我想我不清楚是什么开始/结束那些竖条。我有一个单线程的情况,但涉及状态,所有消息都是异步的。我想这意味着我应该使用外部对象来表示该状态及其生命周期。我想要的是一个时间轴来表示消息序列
和另一个表示消息序列的时间轴
与其他“睿智”代表我现在不关心的其他杂项消息。
有没有办法用QSDE做到这一点?
答案 0 :(得分:14)
当一个新线程启动时(来自用户的消息总是启动一个新线程),它在显式停止或图表结束之前不会停止。例如。 atm:stop终止atm线程
这是第一次尝试 (多线程模式下的所有内容):
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm.give me $10
atm:al has $3=bank.check al's account balance
atm:al.you only have $3
atm:stop
bill:atm.give me $20
atm:bill has $765=bank.check bill's account balance
atm:yes I'm sure, bill has $765=bank.hmm are you sure?
atm:bill.here's $20, now go away
atm:great, he's a cool dude=bank.I just gave Bill $20
(可以说消息应该是异步的,因为它们是通过网络传输的。无论如何,所有箭头看起来都是一样的)
“>” 中在消息开头,启动一个新线程(来自用户和进程的所有消息默认启动一个新线程。)
“&安培;”最后意味着调用立即返回,并且不显示新线程。您可以使用它来模拟向现有线程发送消息。 (默认情况下,所有对用户和进程的消息都会立即返回。)
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm.give me $10
atm:>bank.check al's account balance
bank:>atm.al has $3&
bank:stop
atm:al.you only have $3
atm:stop
bill:atm.give me $20
atm:>bank.check bill's account balance
bank:>atm.bill has $765&
bank:stop
atm:>bank.hmm are you sure?
bank:>atm.yes I'm sure, bill has $765&
bank:stop
atm:bill.here's $20, now go away
atm:>bank.I just gave Bill $20
bank:>atm.great, he's a cool dude&
bank:stop
从示例中不清楚ATM中的确切线程何时应该停止。 ATM似乎更像是用户或进程,而不是对象。所以这个例子不一定有意义
al:Actor
bill:Actor
atm:ATM[a]
bank:Bank[a]
al:atm[a].give me $10
atm:al has $3=bank.check al's account balance
al:atm.what time is it
atm:al.it's now
atm:stop
atm:al.stop bugging me
atm:al.you only have $3
atm:bill.and don't you open your mouth
bill:atm.who asked you?&
atm:stop
bill:atm.give me $20
al:atm.hey, I'm not finished!&
atm:bill has $765=bank.check bill's account balance
atm:yes I'm sure, bill has $765=bank.hmm are you sure?
atm:bill.here's $20, now go away
atm:great, he's a cool dude=bank.I just gave Bill $20
atm:_
atm:stop
al:atm.what about my $10?
atm:al.read my lips: you only have $3
答案 1 :(得分:0)
文档明确指出(引自多线程帮助):
“新生成的线程可以通过相应生命线的颜色与旧线程区分开来。”
“通常,演员发送给对象的消息(动态地)会生成一个新线程。”
所以这就是竖条的来源。
如果您需要单线程或双线程情况,则应使用对象,而不是actor。