scalaとかplayframeworkとか。技術ブログにしたいなと。環境は Windows7x64, mac です。たまに声優さん情報が混ざります。最近ちょっとClojure触りました。

Scala Akka 適当訳


Actor base trait that should be extended by or mixed to create an Actor with the semantics of the 'Actor Model': http://en.wikipedia.org/wiki/Actor_model

ActorのベースtraitはActor Modelの意味論としてActorを作るためにextendかmixされるべきである。

An actor has a well-defined (non-cyclic) life-cycle.


RUNNING (created and started actor) - can receive messages
SHUTDOWN (when 'stop' or 'exit' is invoked) - can't do anything

The Actor's own ActorRef is available as self, the current message’s sender as sender and the ActorContext as context.
The only abstract method is receive which shall return the initial behavior of the actor as a partial function (behavior can be changed using context.become and context.unbecome).


class ExampleActor extends Actor {

  override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
    case _: ArithmeticException      ⇒ Resume
    case _: NullPointerException     ⇒ Restart
    case _: IllegalArgumentException ⇒ Stop
    case _: Exception                ⇒ Escalate

  def receive = {
                                     // directly calculated reply
    case Request(r)               => sender ! calculate(r)

                                     // just to demonstrate how to stop yourself
    case Shutdown                 => context.stop(self)

                                     // error kernel with child replying directly to “customer”
    case Dangerous(r)             => context.actorOf(Props[ReplyToOriginWorker]).tell(PerformWork(r), sender)

                                     // error kernel with reply going through us
    case OtherJob(r)              => context.actorOf(Props[ReplyToMeWorker]) ! JobRequest(r, sender)
    case JobReply(result, orig_s) => orig_s ! result

The last line demonstrates the essence of the error kernel design: spawn one-off actors which terminate after doing their job, pass on sender to allow direct reply if that is what makes sense, or round-trip the sender as shown with the fictitious JobRequest/JobReply message pair.

もしくは、架空の JobRequest/JobReply メッセージペアで示された送信者を返します。

If you don’t like writing context you can always import context._ to get direct access to actorOf, stop etc. This is not default in order to keep the name-space clean.

もしcontextを書くことを好まないならば、import context._ と記述すれば、actorOfやstopなどを直接的に使用することが出来ます。

体系的に学ぶ 安全なWebアプリケーションの作り方 脆弱性が生まれる原理と対策の実践

体系的に学ぶ 安全なWebアプリケーションの作り方 脆弱性が生まれる原理と対策の実践