On Sat, Mar 22, 2014 at 2:48 PM, Patrik Nordwall
<[email protected]>wrote:

> 22 mar 2014 kl. 03:03 skrev Justin du coeur <[email protected]>:
>
> Now I want these Conversations to time out, with the Manager shutting down
> the child after some period of inactivity.  Is there an established trait
> for managing this?
>
> Not that I know about, but I described something similar somewhere:
> - all messages are sent via the Manager actor, which creates child
> Aggregate instances on demand
> - when receiving a message the Manager extract the Aggregate identifier
> from the message
> - the Manager creates a new child Aggregate actor if it doesn't exist, and
> then forwards the message to the Aggregate
> - the Aggregate can passivate itself by sending a Passivate message to the
> parent Manager, which then sends PoisonPill to the Aggregate
> - in-between receiving Passivate and Terminated the Manager will buffer
> all incoming messages for the passivating Aggregate
> - when receiving Terminated it will flush the buffer for the Aggregate,
> which can result in activation again
>
> The PoisonPill can be replaced with some other custom stop message if the
> Aggregate needs to do further interactions with other actors before
> stopping.
>

Yep, that's roughly the design I'm thinking of, with the addition that the
Manager keeps track of when it most recently received a message for each
Aggregate, and has a scheduler strobe that pings the Manager once a second
or so, to check whether any Aggregates have timed out.  (It looks easier to
have the timer inside the Manager rather than the Aggregate, to avoid funky
race conditions.)  The timeout should be configurable based on the
Aggregate's type, and I suspect I want to wrap the Aggregate's ActorRef in
something that handles the management, and works with a trait that gets
mixed into the Manager.

> I realize that the problem isn't rocket science.  But it occurred to me
> that it can't be a rare pattern - I think I'm going to want variants of
> this in several places in my app, and I think the code is more or less
> identical, so there should be a common trait to boil out of this.  Has
> anyone written that yet?
>
> Similar is implemented in cluster sharding, but not general purpose.
>

Okay -- that was the impression I'd gotten.  I suspect that my most
immediate use case *should* be built with Akka Persistence and Cluster
Sharding, but it's likely to be 3-6 months before I have my infrastructure
sufficiently up to snuff to use those.  (Before I get there, I need to
upgrade to a Play release that incorporates Akka 2.3, and I need to choose
a DB back end that will work nicely with Akka Persistence.  At the moment
I'm entirely MySQL-based, and I'm going to have to have a discussion with
IT about which NoSQL DB we're going to use.)


> Let us know if you come up with something that is usable for others, might
> be a great contribution.
>

Okay, will do.  It'll likely be working in a week or two; I'll plan to
write it in a reasonably reusable way.

(Where should a writeup for this be placed when it's working?  I note that
Aggregator is under the official documentation's "Contributions" section --
now that the Community area exists, is there a clear idea of what belongs
where?  This reminds me that, now that I've used Requester
<https://github.com/jducoeur/Querki/blob/master/querki/app/querki/util/Requester.scala>enough
to have a fair sense of its strengths and weaknesses, I should also
probably toss that in somewhere -- it's a very simple little pattern, but
quite useful...)

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      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/d/optout.

Reply via email to