Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A while ago I wrote <a href="http://vasilrem.com/blog/software-development/fault-tolerance-primitives-in-scala-links-and-traps/" rel="nofollow">a post</a> on linking actors in Scala. Actor linking is an idiomatic [and the easiest] way to monitor actors in Erlang, Scala Actors and other actor libraries. By defalt, when you link 2 actors, and one of them dies, another immediately dies too (unless the actor traps/handles exit signal):</p> <pre><code>scala&gt; case object Stop defined module Stop scala&gt; scala&gt; val actor1 = actor { | loop { | react { | case Stop =&gt; | println("Actor 1: stop") | exit() | case msg =&gt; println(msg) | } | } | } actor1: scala.actors.Actor = scala.actors.Actor$$anon$1@1feea62 scala&gt; scala&gt; val actor2 = actor { | link(actor1) | self.trapExit = true | loop { | react { | case msg =&gt; println(msg) | } | } | } actor2: scala.actors.Actor = scala.actors.Actor$$anon$1@1e1c66a scala&gt; actor1.start res12: scala.actors.Actor = scala.actors.Actor$$anon$1@1feea62 scala&gt; actor2.start res13: scala.actors.Actor = scala.actors.Actor$$anon$1@1e1c66a scala&gt; actor1 ! Stop Actor 1: stop scala&gt; Exit(scala.actors.Actor$$anon$1@1feea62,'normal) // Actor 2 received message, when Actor1 died </code></pre> <p>A more sophisticated and flexible way is using supervisors (supervisor behavior in Erlang, <strong><a href="http://doc.akkasource.org/fault-tolerance-scala#Supervision" rel="nofollow">actor supervisors</a></strong> in Akka Actors library, etc). A supervisor (being itself an actor) monitors a number of other actors, and restarts them with regards to a specified strategy (restart all actors, if one dies; restart just one actor, when it dies).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload