This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Linked RemoteActor does not receive Exit notification

5 replies
E. Labun
Joined: 2010-06-20,
User offline. Last seen 42 years 45 weeks ago.

Hi,

The Master-Actor in the following code does not receive
Exit-notification from the linked Slave-Actor, and therefore the program
does not terminate. Is it a bug or defined behavior?
I'm using Scala-2.8.0.RC6.

-------------------------------------------------
import scala.actors._
import Actor._
import remote._
import RemoteActor._

object Master extends Actor {
trapExit = true
def act() {
Debug.level = 3
alive(9900)
register('master, self)
loop {
react {
case e: Exit =>
println("* master: slave disconnected. Exiting too...")
exit
case x =>
println("* master: message received: " + x)
val slave = sender.receiver
link(slave)
slave ! "Connected"
}
}
}
}

object Slave extends Actor {
Debug.level = 3
def act() {
val master = select(Node("localhost", 9900), 'master)
// val master = Master // see *Note
// link(master) // see *Note
master ! "Hello"

loop {
react {
case x =>
println("* slave: message received: " + x)
println("* slave: exiting now...")
exit
}
}
}
}

object trapExitTest extends Application {
Master.start
Slave.start
}
-------------------------------------------------

Output:

-------------------------------------------------
Info: created service at Node(192.168.101.129,9900)
Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
Info: created service at Node(192.168.101.129,8481)
Info: Thread[Thread-7,5,main]: waiting for new connection on port 8481...
Info: Thread[Thread-8,5,main]: transmitting data...
Info: Started new Thread[Thread-9,5,main]
Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
Info: scala.actors.remote.NetKernel@1968e23: processing
NamedSend(Locator(Node(192.168.101.129,8481),'remotesender0),Locator(Node(localhost,9900),'master),[B@14da8f4,'nosession)
* master: message received: Hello
Info: Thread[Thread-9,5,main]: transmitting data...
Info: scala.actors.remote.NetKernel@bd928a: processing
NamedSend(Locator(Node(192.168.101.129,9900),'master),Locator(Node(192.168.101.129,8481),'remotesender0),[B@1dfc547,'nosession)
* slave: message received: Connected
* slave: exiting now...
Info: alive actor Slave$@47393f terminated
Info: terminating scala.actors.remote.NetKernel@bd928a
Info: Thread[Thread-7,5,main]: shutting down...
Info: Thread[Thread-8,5,main]: caught java.net.SocketException: socket
closed
Info: Thread[Thread-8,5,main]: service terminated at
Node(192.168.101.129,8481)
Info: Thread[Thread-9,5,main]: caught java.io.EOFException
Info: Thread[Thread-9,5,main]: service terminated at
Node(192.168.101.129,9900)
-------------------------------------------------

*Note: If I call link() from the Slave-object or if the Master-actor is
referenced explicitly (not via select()) then the Exit-notification
arrives an the program terminates properly.

Thanks,
Eugen

Stefan Kuhn
Joined: 2009-10-01,
User offline. Last seen 42 years 45 weeks ago.
Re: Linked RemoteActor does not receive Exit notification

I have the same problem with RC7.

Furthermore I noticed, that if you send the DelegatingActor master over
the network, it gets a new identity at the same node each time it's
received (note the hash value):

INF [20100713-11:17:49.762] graphtor.utils: Actor Registered:
'scala.actors.ActorProxy-2147483647@Node(127.0.0.1,61200) Hash: 55821173
INF [20100713-11:17:57.401] graphtor.utils: Actor Unregistered:
'scala.actors.ActorProxy-2147483647@Node(127.0.0.1,61200) Hash: 1578101576

I'm not sure if it's related to your problem.

-stefan

On 20.06.10 14:12, E. Labun wrote:
> Hi,
>
> The Master-Actor in the following code does not receive
> Exit-notification from the linked Slave-Actor, and therefore the program
> does not terminate. Is it a bug or defined behavior?
> I'm using Scala-2.8.0.RC6.
>
> -------------------------------------------------
> import scala.actors._
> import Actor._
> import remote._
> import RemoteActor._
>
> object Master extends Actor {
> trapExit = true
> def act() {
> Debug.level = 3
> alive(9900)
> register('master, self)
> loop {
> react {
> case e: Exit =>
> println("* master: slave disconnected. Exiting too...")
> exit
> case x =>
> println("* master: message received: " + x)
> val slave = sender.receiver
> link(slave)
> slave ! "Connected"
> }
> }
> }
> }
>
> object Slave extends Actor {
> Debug.level = 3
> def act() {
> val master = select(Node("localhost", 9900), 'master)
> // val master = Master // see *Note
> // link(master) // see *Note
> master ! "Hello"
>
> loop {
> react {
> case x =>
> println("* slave: message received: " + x)
> println("* slave: exiting now...")
> exit
> }
> }
> }
> }
>
> object trapExitTest extends Application {
> Master.start
> Slave.start
> }
> -------------------------------------------------
>
>
>
> Output:
>
> -------------------------------------------------
> Info: created service at Node(192.168.101.129,9900)
> Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
> Info: created service at Node(192.168.101.129,8481)
> Info: Thread[Thread-7,5,main]: waiting for new connection on port 8481...
> Info: Thread[Thread-8,5,main]: transmitting data...
> Info: Started new Thread[Thread-9,5,main]
> Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
> Info: scala.actors.remote.NetKernel@1968e23: processing
> NamedSend(Locator(Node(192.168.101.129,8481),'remotesender0),Locator(Node(localhost,9900),'master),[B@14da8f4,'nosession)
> * master: message received: Hello
> Info: Thread[Thread-9,5,main]: transmitting data...
> Info: scala.actors.remote.NetKernel@bd928a: processing
> NamedSend(Locator(Node(192.168.101.129,9900),'master),Locator(Node(192.168.101.129,8481),'remotesender0),[B@1dfc547,'nosession)
> * slave: message received: Connected
> * slave: exiting now...
> Info: alive actor Slave$@47393f terminated
> Info: terminating scala.actors.remote.NetKernel@bd928a
> Info: Thread[Thread-7,5,main]: shutting down...
> Info: Thread[Thread-8,5,main]: caught java.net.SocketException: socket
> closed
> Info: Thread[Thread-8,5,main]: service terminated at
> Node(192.168.101.129,8481)
> Info: Thread[Thread-9,5,main]: caught java.io.EOFException
> Info: Thread[Thread-9,5,main]: service terminated at
> Node(192.168.101.129,9900)
> -------------------------------------------------
>
>
>
> *Note: If I call link() from the Slave-object or if the Master-actor is
> referenced explicitly (not via select()) then the Exit-notification
> arrives an the program terminates properly.
>
> Thanks,
> Eugen
>

tolsen77
Joined: 2008-10-08,
User offline. Last seen 1 year 38 weeks ago.
Re: Linked RemoteActor does not receive Exit notification
The actor that calls it link(targetActor) method will notify the targetActor when it exits. If you want the slave actors to notify the master, then the slave actors need to link to the master actor.

On Sun, Jun 20, 2010 at 2:12 PM, E. Labun <labun@gmx.net> wrote:
Hi,

The Master-Actor in the following code does not receive
Exit-notification from the linked Slave-Actor, and therefore the program
does not terminate. Is it a bug or defined behavior?
I'm using Scala-2.8.0.RC6.

-------------------------------------------------
import scala.actors._
import Actor._
import remote._
import RemoteActor._

object Master extends Actor {
 trapExit = true
 def act() {
   Debug.level = 3
   alive(9900)
   register('master, self)
   loop {
     react {
       case e: Exit =>
         println("* master: slave disconnected. Exiting too...")
         exit
       case x =>
         println("* master: message received: " + x)
         val slave = sender.receiver
         link(slave)
         slave ! "Connected"
     }
   }
 }
}

object Slave extends Actor {
 Debug.level = 3
 def act() {
   val master = select(Node("localhost", 9900), 'master)
   // val master = Master // see *Note
   // link(master)        // see *Note
   master ! "Hello"

   loop {
     react {
       case x =>
         println("* slave: message received: " + x)
         println("* slave: exiting now...")
         exit
     }
   }
 }
}

object trapExitTest extends Application {
 Master.start
 Slave.start
}
-------------------------------------------------



Output:

-------------------------------------------------
Info: created service at Node(192.168.101.129,9900)
Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
Info: created service at Node(192.168.101.129,8481)
Info: Thread[Thread-7,5,main]: waiting for new connection on port 8481...
Info: Thread[Thread-8,5,main]: transmitting data...
Info: Started new Thread[Thread-9,5,main]
Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
Info: scala.actors.remote.NetKernel@1968e23: processing
NamedSend(Locator(Node(192.168.101.129,8481),'remotesender0),Locator(Node(localhost,9900),'master),[B@14da8f4,'nosession)
* master: message received: Hello
Info: Thread[Thread-9,5,main]: transmitting data...
Info: scala.actors.remote.NetKernel@bd928a: processing
NamedSend(Locator(Node(192.168.101.129,9900),'master),Locator(Node(192.168.101.129,8481),'remotesender0),[B@1dfc547,'nosession)
* slave: message received: Connected
* slave: exiting now...
Info: alive actor Slave$@47393f terminated
Info: terminating scala.actors.remote.NetKernel@bd928a
Info: Thread[Thread-7,5,main]: shutting down...
Info: Thread[Thread-8,5,main]: caught java.net.SocketException: socket
closed
Info: Thread[Thread-8,5,main]: service terminated at
Node(192.168.101.129,8481)
Info: Thread[Thread-9,5,main]: caught java.io.EOFException
Info: Thread[Thread-9,5,main]: service terminated at
Node(192.168.101.129,9900)
-------------------------------------------------



*Note: If I call link() from the Slave-object or if the Master-actor is
referenced explicitly (not via select()) then the Exit-notification
arrives an the program terminates properly.

Thanks,
Eugen

tolsen77
Joined: 2008-10-08,
User offline. Last seen 1 year 38 weeks ago.
Re: Linked RemoteActor does not receive Exit notification
+ trapExit = true in targetActor, which is missing in the slave btw (if you're linking slave -> master as in the example).

On Tue, Jul 13, 2010 at 1:45 PM, Trond Olsen <tolsen77@gmail.com> wrote:
The actor that calls it link(targetActor) method will notify the targetActor when it exits. If you want the slave actors to notify the master, then the slave actors need to link to the master actor.

On Sun, Jun 20, 2010 at 2:12 PM, E. Labun <labun@gmx.net> wrote:
Hi,

The Master-Actor in the following code does not receive
Exit-notification from the linked Slave-Actor, and therefore the program
does not terminate. Is it a bug or defined behavior?
I'm using Scala-2.8.0.RC6.

-------------------------------------------------
import scala.actors._
import Actor._
import remote._
import RemoteActor._

object Master extends Actor {
 trapExit = true
 def act() {
   Debug.level = 3
   alive(9900)
   register('master, self)
   loop {
     react {
       case e: Exit =>
         println("* master: slave disconnected. Exiting too...")
         exit
       case x =>
         println("* master: message received: " + x)
         val slave = sender.receiver
         link(slave)
         slave ! "Connected"
     }
   }
 }
}

object Slave extends Actor {
 Debug.level = 3
 def act() {
   val master = select(Node("localhost", 9900), 'master)
   // val master = Master // see *Note
   // link(master)        // see *Note
   master ! "Hello"

   loop {
     react {
       case x =>
         println("* slave: message received: " + x)
         println("* slave: exiting now...")
         exit
     }
   }
 }
}

object trapExitTest extends Application {
 Master.start
 Slave.start
}
-------------------------------------------------



Output:

-------------------------------------------------
Info: created service at Node(192.168.101.129,9900)
Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
Info: created service at Node(192.168.101.129,8481)
Info: Thread[Thread-7,5,main]: waiting for new connection on port 8481...
Info: Thread[Thread-8,5,main]: transmitting data...
Info: Started new Thread[Thread-9,5,main]
Info: Thread[Thread-6,5,main]: waiting for new connection on port 9900...
Info: scala.actors.remote.NetKernel@1968e23: processing
NamedSend(Locator(Node(192.168.101.129,8481),'remotesender0),Locator(Node(localhost,9900),'master),[B@14da8f4,'nosession)
* master: message received: Hello
Info: Thread[Thread-9,5,main]: transmitting data...
Info: scala.actors.remote.NetKernel@bd928a: processing
NamedSend(Locator(Node(192.168.101.129,9900),'master),Locator(Node(192.168.101.129,8481),'remotesender0),[B@1dfc547,'nosession)
* slave: message received: Connected
* slave: exiting now...
Info: alive actor Slave$@47393f terminated
Info: terminating scala.actors.remote.NetKernel@bd928a
Info: Thread[Thread-7,5,main]: shutting down...
Info: Thread[Thread-8,5,main]: caught java.net.SocketException: socket
closed
Info: Thread[Thread-8,5,main]: service terminated at
Node(192.168.101.129,8481)
Info: Thread[Thread-9,5,main]: caught java.io.EOFException
Info: Thread[Thread-9,5,main]: service terminated at
Node(192.168.101.129,9900)
-------------------------------------------------



*Note: If I call link() from the Slave-object or if the Master-actor is
referenced explicitly (not via select()) then the Exit-notification
arrives an the program terminates properly.

Thanks,
Eugen


Stefan Kuhn
Joined: 2009-10-01,
User offline. Last seen 42 years 45 weeks ago.
Re: Linked RemoteActor does not receive Exit notification

Did you try this for _Remote_Actors?

> The actor that calls it link(targetActor) method will notify the
> targetActor when it exits. If you want the slave actors to notify the
> master, then the slave actors need to link to the master actor.
I think if "a link b", "b link a" is automatically done.

Stephen Tu
Joined: 2010-02-24,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Linked RemoteActor does not receive Exit notification
i'm curious what you're code looks like for this example; it would help me to know some of the use cases that people are using for actor shipping.

On Tue, Jul 13, 2010 at 3:03 AM, Stefan Kuhn <qn.666@gmx.net> wrote:
I have the same problem with RC7.

Furthermore I noticed, that if you send the DelegatingActor master over the network, it gets a new identity at the same node each time it's received (note the hash value):

INF [20100713-11:17:49.762] graphtor.utils: Actor Registered: 'scala.actors.ActorProxy-2147483647@Node(127.0.0.1,61200)  Hash: 55821173
INF [20100713-11:17:57.401] graphtor.utils: Actor Unregistered: 'scala.actors.ActorProxy-2147483647@Node(127.0.0.1,61200)        Hash: 1578101576

I'm not sure if it's related to your problem.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland