How to detect dead actor?

89 views
Skip to first unread message

Shouichi KAMIYA

unread,
Mar 7, 2011, 3:59:49 PM3/7/11
to Akka User List
Hi

I'm new to akka and wrote a simple ping pong app (client and server)
to understand remote actor.
The app looks like it works fine but when I shutdown server with ctrl-
c, client keeps reconnecting to the dead server.
How can I detect the server being down and prevent client from
reconnecting?
The code looks like below:

import akka.actor.Actor

class Server extends Actor {
def receive = {
case "ping" => self.reply("pong")
}
}

class Client extends Actor {
val server = Actor.remote.actorFor("server", "0.0.0.0", 2552)

def receive = {
case "ping" => server ! "ping"
case "pong" => println("got pong")
}
}

object Test {
def server = {
val server = Actor.actorOf[Server].start
Actor.remote.start("0.0.0.0", 2552)
Actor.remote.register("server", server)
}

def client = {
Actor.actorOf[Client].start
}
}

Thanks.

√iktor Klang

unread,
Mar 7, 2011, 4:10:17 PM3/7/11
to akka...@googlegroups.com
Hi,

You can both configure reconnection time window:

    client {
      reconnect-delay = 5
      read-timeout = 10
      message-frame-size = 1048576
      reap-futures-delay = 5
      reconnection-time-window = 600 # Maximum time window that a client should try to reconnect for
    }
You can also register a listener to Actor.remote, and shut down the client connection upon receiving "akka.remoteinterfaceRemoteClientDisconnected(client, address)" and do client.shutdownClientConnection(address)

Does that help?

Cheers,


--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




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

Shouichi KAMIYA

unread,
Mar 8, 2011, 10:06:58 AM3/8/11
to Akka User List
Thank you very much for your quick reply Victor!

RemoteClientDisconnected did the trick and the ping pong app worked
perfect.

Next I tried to create a chat app (server and client).
Clients connect to server and the server holds their actor refs in a
list.
The problem is when the client is killed by ctrl-c, how to detect that
and remove actor ref from the list?
I know we have events such as RemoteClientDisconnected, but we can't
get actor ref from that (as far as I know).
How can I solve this problem?

Thanks.

On Mar 8, 6:10 am, √iktor Klang <viktor.kl...@gmail.com> wrote:
> Hi,
>
> You can both configure reconnection time window:
>
>     client {
>       reconnect-delay = 5
>       read-timeout = 10
>       message-frame-size = 1048576
>       reap-futures-delay = 5
>    *   reconnection-time-window = 600 # Maximum time window that a
> client should try to reconnect for*
> Work:   Scalable Solutions <http://www.scalablesolutions.se>

√iktor Klang

unread,
Mar 8, 2011, 11:22:39 AM3/8/11
to akka...@googlegroups.com
On Tue, Mar 8, 2011 at 4:06 PM, Shouichi KAMIYA <pet...@gmail.com> wrote:
Thank you very much for your quick reply Victor!

You are most welcome,
 

RemoteClientDisconnected did the trick and the ping pong app worked
perfect.

Great to hear
 

Next I tried to create a chat app (server and client).
Clients connect to server and the server holds their actor refs in a
list.
The problem is when the client is killed by ctrl-c, how to detect that
and remove actor ref from the list?
I know we have events such as RemoteClientDisconnected, but we can't
get actor ref from that (as far as I know).
How can I solve this problem?

On the server, remove all actors whose homeAddress are the one that went down.

Have a look at ActorRef.homeAddress and compare it to the address supplied by the RemoteClientDisconnected event.

Does that help?

Cheers,
 

Florian Hars

unread,
Mar 8, 2011, 12:04:30 PM3/8/11
to akka...@googlegroups.com
On 08.03.2011 17:22, √iktor Klang wrote:
> On the server, remove all actors whose homeAddress are the one that went
> down.

Is that race free? The listener is an actor, too, does every dispatcher
guarantee that the client disconnected message will be handled before a
new client process has been started and registered a new client actor
with the same homeAddress?

- Florian.

√iktor Klang

unread,
Mar 8, 2011, 12:55:44 PM3/8/11
to akka...@googlegroups.com

Of course the listener should be the same actor that manages the actors.

On Mar 8, 2011 6:04 PM, "Florian Hars" <ha...@pre-sense.de> wrote:

On 08.03.2011 17:22, √iktor Klang wrote:

> On the server, remove all actors whose homeAddress are th...

Is that race free? The listener is an actor, too, does every dispatcher
guarantee that the client disconnected message will be handled before a
new client process has been started and registered a new client actor
with the same homeAddress?

- Florian.


--

You received this message because you are subscribed to the Google Groups "Akka User List" group.

To...

Shouichi KAMIYA

unread,
Mar 9, 2011, 6:23:32 AM3/9/11
to akka...@googlegroups.com
Thank you for your help. I really appreciate that!

> On the server, remove all actors whose homeAddress are the one that went
> down.
>
> Have a look at ActorRef.homeAddress and compare it to the address supplied
> by the RemoteClientDisconnected event.

I use RemoteServerClientDisconnected but I don't know if I can remove
dead actors correctly, because RemoteServerClientDisconnected provides
address like Some(/136.187.37.xxx:53800) and actorRef.homeAddress
provides address like Some(0.0.0.0/0.0.0.0:2552).

Thanks.

--
Tokyo Univ. Dept. of  Information Science 4th grade
Shouichi KAMIYA

√iktor Klang

unread,
Mar 9, 2011, 6:31:00 AM3/9/11
to akka...@googlegroups.com
On Wed, Mar 9, 2011 at 12:23 PM, Shouichi KAMIYA <pet...@gmail.com> wrote:
Thank you for your help. I really appreciate that!

> On the server, remove all actors whose homeAddress are the one that went
> down.
>
> Have a look at ActorRef.homeAddress and compare it to the address supplied
> by the RemoteClientDisconnected event.

I use RemoteServerClientDisconnected but I don't know if I can remove
dead actors correctly, because RemoteServerClientDisconnected provides
address like Some(/136.187.37.xxx:53800) and actorRef.homeAddress
provides address like Some(0.0.0.0/0.0.0.0:2552).


Sounds like a bug, it's probably sending the endpoint address instead of the target address.

Lemme open a ticket, I'll have a look at it ASAP.

Cheers,
 

Shouichi KAMIYA

unread,
Mar 9, 2011, 6:44:34 AM3/9/11
to akka...@googlegroups.com
> Lemme open a ticket, I'll have a look at it ASAP.

Thank you very much!

--
Tokyo Univ. Dept. of  Information Science 4th grade
Shouichi KAMIYA

√iktor Klang

unread,
Mar 9, 2011, 8:57:00 AM3/9/11
to akka...@googlegroups.com
On Wed, Mar 9, 2011 at 12:44 PM, Shouichi KAMIYA <pet...@gmail.com> wrote:
> Lemme open a ticket, I'll have a look at it ASAP.

Thank you very much!

Seems hard, the server only knows that the inbound connection drops off, but it does not know anything about which server address that inbound connection is correlated to.

Any ideas on this guys?

Cheers,
 
Reply all
Reply to author
Forward
0 new messages