Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Is <a href="http://www.scala-lang.org/docu/files/api/scala/actors/Actor.html" rel="nofollow noreferrer">Actor</a>.link and <a href="http://www.scala-lang.org/docu/files/api/scala/actors/Actor.html" rel="nofollow noreferrer">Actor</a>.trapExit what you are looking for?</p> <p><strong>EDIT</strong> Try this. I moved everything into the act methods. Also sending proxies between remote actors seemed to cause problems. There's some discussion about this possible bug here: <a href="http://www.scala-lang.org/node/6779" rel="nofollow noreferrer">http://www.scala-lang.org/node/6779</a> ; see the comment from Stefan Kuhn.</p> <pre><code>package test import scala.actors.{OutputChannel, AbstractActor, Exit, Debug, Actor} , Actor._ import scala.actors.remote.RemoteActor , RemoteActor._ object ActorTestA{ def main(args :Array[String]) { println("Start A") val a = new A().start println("Fin A") } } object ActorTestB{ def main(args :Array[String]) { println("Start B") val b = new B().start b ! 'start println("Fin B") } } case class AA(hostname: String, port: Int, symbol: Symbol) { def proxy = select(actors.remote.Node(hostname, port), symbol) } case class M1(sendRef :AA, m2 :M2) case class M2(v1:String, v2 :String, sendRef :AA) case class M3(m2 :M2) object A { val portToUse = 20000 } class A extends Actor { def act = { alive(A.portToUse) register('A, this) RemoteActor.classLoader = getClass().getClassLoader() val proxy = select(actors.remote.Node("localhost", A.portToUse), 'A) loop { react { case M1(sendRef, m2) =&gt; println("A receives M1") sendRef.proxy ! M3(m2) self ! 'exit case 'exit =&gt; println("A exits") exit case any =&gt; println("Unknown Msg: "+any) } } } } class B extends Actor { def act = { RemoteActor.classLoader = getClass().getClassLoader() val portToUse = 20001 alive(portToUse) register('B, this) var proxy = AA("localhost", portToUse, 'B) var resultTo :Option[OutputChannel[Any]] = None loop { react { case 'start =&gt; println("B starts") val a = select(actors.remote.Node("localhost", A.portToUse), 'A) a ! M1(proxy, M2("some","val", proxy)) resultTo = Some(sender) case M3(M2(v1,v2,sendRef))=&gt; println("B receives M3") resultTo match { case Some(ch) =&gt; ch ! sendRef.proxy; case None =&gt; println("ch missing!?") } self ! 'exit case 'exit =&gt; println("B exits") exit case any =&gt; println("Unknown Msg: "+any) } } } } </code></pre>
 

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