Hi,
I have a system that has 3 actors. The master actor sends message on a
scheduled basis (every N minute) to a child actor1 (say CA1). The CA1 then
does some processing based on the message and sends a message(s) to
children actors 2 (CA2). The master actor creates CA1, and CA1 creates CA2.
There's a possibility that CA2 may take a while to process, and exceed the
interval of the master scheduler (say it takes N+2 minutes).
So when the next message is sent to CA1 from the master the CA1 should send
back a message to the master indicating some of the CA2 actors are still
processing. CA1 should start creating CA2 only when there are no pending
CA2 actors.
The way Iam currently dealing with this is to maintain a collection of the
CA2 references in CA1.
I start creating CA2 only if the collection is empty upon receiving a
message. So every time a CA2 actor is created I add it to the collection.
And I remove from the collection when I receive a successful message from
CA2, or upon termination (I watch the CA2 from CA1).
class CA2 {
val ca2Refs = Set.Empty[ActorRef]
receive => {
case messageFromMaster => {
if (ca2Refs.isEmpty) {
val ca2Ref = context.actorOf(Props[CA2])
context.watch(ca2Ref)
ca2Refs += ca2Ref
ca2Ref ! message
}
}
case messageFromCA2 => {
ca2Refs -= ca2Ref
}
case Terminated => {
ca2Refs -= ca2Ref
}
}
}
Question I have is, is this within the "Normal practices" of akka? And will
this account for actors that are restarted? As in if a particular child
actor CA2 is restarted, will CA1 receive the Terminated message? Would
appreciate your feedback.
Regards,
Sridhar.
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.