Example17.11

「Example17.11」の編集履歴(バックアップ)一覧に戻る

Example17.11 - (2010/09/17 (金) 13:04:51) のソース

**17.11 Actors

**17.11 アクター

Chapter 3 sketched as a program example the implementation of an electronic auction service. This service was based on high-level actor processes that work by inspecting messages in their mailbox using pattern matching. A refined and optimized implementation of actors is found in the scala.actors package. We now give a sketch of a simplified version of the actors library.

第3章で電子オークションサービスのプログラム実装例をざっと見ました。そのサービスは、パターンマッチングを使ってメールボックス中のメッセージを調べて動く、高度なアクタープロセスに基づいています。アクターの洗練、最適化された実装は scala.actors パッケージに収められています。ここで、アクターライブラリの簡略化バージョンを見てみましょう。

The code below is different from the implementation in the scala.actors package, so it should be seen as an example how a simple version of actors could be implemented. It is not a description how actors are actually defined and implemented in the standard Scala library. For the latter, please refer to the Scala API documentation.

下記のコードは scala.actors パッケージの実装とは異なるので、アクターの簡略バージョンをどのように実装できるか、の例として見てください。アクターが実際にどのように定義されているか、あるいは標準 Scala ライブラリにおける実装を記述するものではありません。後者については Scala APIドキュメントを参照してください。

A simplified actor is just a thread whose communication primitives are those of a mailbox. Such an actor can be defined as a mixin composition extension of Java's standard Thread class with the MailBox class. We also override the run method of the Thread class, so that it executes the behavior of the actor that is defined by its act method. The ! method simply calls the send method of the MailBox class:

簡略化されたアクターは、通信プリミティブがメールボックスのそれであるようなスレッドです。そのようなアクターは、MailBox クラスを備えた Java の標準 Threadクラスのミックスイン合成拡張として定義できます。 私たちは Thread クラスの run メソッドもオーバライドして、その act メソッドで定義されたアクター動作を実行させます。! メソッドは MailBox の send メソッドを呼び出すだけです。

  abstract class Actor extends Thread with MailBox {
    def act(): Unit
    override def run(): Unit = act()
    def !(msg: Any) = send(msg)
  }

----
#comment
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。