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

Actor as instance variable of another actor

2 replies
Gilles SCOUVART
Joined: 2009-03-06,
User offline. Last seen 42 years 45 weeks ago.

Dear Scala users,

 

I have a question about actors. I would like to have an actor, that itself has an anonymous actor as an instance variable, which only listens to feedback from other actors.

The problem I’m having is that the child actor seems to share the mailbox of its parent, and I get an “assertion failed: receive from channel belonging to other actor”. Is there no means to do what I’m trying to do? (Of course I could handle the message in the parent actor, but the plan was not to overload the parent mailbox with low-level messages.) But perhaps I miss something basic about actor design.

As a side question, I’m wondering whether reply/!? must go together, or we can use reply even if not waiting for the response on the other side?

 

Many thanks for your help,

 

Gilles.

Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Actor as instance variable of another actor
Hey Gilles,

I think code would help everyone here.

On Tue, Sep 14, 2010 at 10:11 AM, Gilles SCOUVART <Gilles.SCOUVART@n-side.be> wrote:

Dear Scala users,

 

I have a question about actors. I would like to have an actor, that itself has an anonymous actor as an instance variable, which only listens to feedback from other actors.

The problem I’m having is that the child actor seems to share the mailbox of its parent, and I get an “assertion failed: receive from channel belonging to other actor”. Is there no means to do what I’m trying to do? (Of course I could handle the message in the parent actor, but the plan was not to overload the parent mailbox with low-level messages.) But perhaps I miss something basic about actor design.

As a side question, I’m wondering whether reply/!? must go together, or we can use reply even if not waiting for the response on the other side?

 

Many thanks for your help,

 

Gilles.




--
Viktor Klang,
Code Connoisseur
Work:   www.akkasource.com
Code:   github.com/viktorklang
Follow: twitter.com/viktorklang
Read:   klangism.tumblr.com

Stephen Tu
Joined: 2010-02-24,
User offline. Last seen 42 years 45 weeks ago.
Re: Actor as instance variable of another actor
Gilles,
How about something like:

scala> class MyMainActor extends Actor {
     |
     |   object MyHandlerActor extends Actor {
     |     start()
     |     def act() {
     |       loop {
     |         react {
     |           case e => println("Got: " + e)
     |         }
     |       }
     |     }
     |   }
     |
     |   def act() {
     |     loop {
     |       react {
     |         case e => MyHandlerActor forward e
     |       }
     |     }
     |   }
     | }
defined class MyMainActor

scala> val m = (new MyMainActor).start()
m: scala.actors.Actor = MyMainActor@1f75442

scala> m ! "Hello"
Got: Hello


On Tue, Sep 14, 2010 at 1:11 AM, Gilles SCOUVART <Gilles.SCOUVART@n-side.be> wrote:

Dear Scala users,

 

I have a question about actors. I would like to have an actor, that itself has an anonymous actor as an instance variable, which only listens to feedback from other actors.

The problem I’m having is that the child actor seems to share the mailbox of its parent, and I get an “assertion failed: receive from channel belonging to other actor”. Is there no means to do what I’m trying to do? (Of course I could handle the message in the parent actor, but the plan was not to overload the parent mailbox with low-level messages.) But perhaps I miss something basic about actor design.

As a side question, I’m wondering whether reply/!? must go together, or we can use reply even if not waiting for the response on the other side?

 

Many thanks for your help,

 

Gilles.


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