.. Some notes on asynchronous messages 非同期メッセージに関するノート =================================== .. Quick Sequence Diagram Editor is not a tool that gives you unlimited freedom of drawing. A sequence is subject to these two constraints: Quick Sequence Diagram Editorは自由にシーケンス図を書くツールではなく、手早く正確に作図するために意図的に以下の2つの制約をつけています: .. 1. Messages can only be sent by actors or objects that have received a message and are still active. .. 2. When a message is sent, some activities that were initiated by the sending object (the caller) may have to be finished before. This is done automatically by the Quick Sequence Diagram Editor, which should be considered an advantage: Answer arrows need not be specified by the user, the editor takes care that they are inserted at the right place and time. 1. メッセージはアクター、もしくはメッセージを受け取ってアクティブになっているオブジェクトからしか送信できません。 2. メッセージが送信されるときには、送信元オブジェクト(送信者)が開始していたアクティビティは、送信前に完了している必要があります。通常はこの部分はツール側で面倒を見ます。これに関してはメリットがあり、ツール側で、正しい場所とタイミングに、返信用のメッセージを自動で挿入するために、すべてにおいて逐一指定する必要はありません。 .. These constraints seem to make it impossible to specify an asynchronous message. This is a message that returns immediately from the callee and renders it active while the caller remains active as well and could send another message without rendering the former callee inactive again. これらの制約は、非同期なメッセージに対して行うことはできないように見ます。非同期メッセージは、送信した直後に返事が返ってくるが、送信側がアクティブな間も、受信側がアクティブでい続けて、直前に呼ばれた側が再び非アクティブになる前に、他のメッセージを送信できるかのように描画されます。 .. But such messages can be modelled very well by Quick Sequence Diagram Editor as it supports multithreading. One may object to this because multithreading is an implementation detail, and maybe one does not want to deal with it. But multithreading is the only means (and it is a sufficient means too) for modelling asynchronity that is offered by the editor. And after all, it is just a modelling tool, so one does not have to delve really deeply into the details of multithreading. しかし、このようなメッセージはQuick Sequence Diagram Editorでは、マルチスレッドの描画をサポートしているため、うまくモデル化することができます。内部的にはマルチスレッドを使用して実装されていることが多く、そのような機能を使って描画するのは詳細に入ってしまうために反対する人もいるかもしれません。しかし、Quick Sequence Diagram Editorにとっては、マルチスレッドが、非同期メッセージを描画する唯一の方法で、なおかつ十分な方法です。結局のところ、単なるモデリングツールなので、マルチスレッドの詳細の深くまで探求する必要はありません。 .. As an example, suppose you want to model a sequence where a server starts a background job that does a lot of queries to a database and sends back a result later: サンプルとして、サーバが、数多くのクエリーをデータベースに投げるようなバックグランドジョブを実行して、結果を後から返すというケースのシーケンスを以下に示します:: user:Actor server:Server[a] job:BackgroundJob[a] db:Database[a] user:server[s].start # ここでは、新しいスレッドを生成することによって、暗示的に非同期メッセージを # 実現しています。'j'というニーモニックのおかげで、ジョブオブジェクトは # 新しいスレッド上で安全に識別することができます。そのため、スレッド番号を # 厳格に取り扱う必要はありません。 [c asynchronous message] server:>job[j].start [/c] job:db.do 1'000'000 queries server[s]:server.do something useful job[j]:job.analyze queries job[j]:job.compute result server[s]:server.wait for result job[j]:server.send back result job[j]:stop server[s]:user.send result to user .. image:: async.png .. # Here comes the asynchronous message that implicitly spawns # a new thread. Thanks to the mnemnonic 'j' the job object # can safely be identified on that new thread, so # you do not even have to deal with thread numbers. .. As long as objects are used by only a single thread or there are mnemonics, thread numbers can be ignored. If thread colourizing is disabled, the resulting sequence diagram should look very similar to a diagram made with a WYSIWYG tool that allows to put arrows everywhere. オブジェクトがシングルスレッドとして使用されるか、ニーモニックがあると、スレッド番号は無視することができます。もしもスレッドに色付けする機能がオフになっていると、自由な位置に矢印を置けるWYSIWYGのツールを使って使って作成したものと、非常に似たシーケンス図が結果としてできあがります。