Hello Darius,
Two ideas for you :-)

1)

I personally would aggregate the results inside of an Actor. It seems a
reasonable thing to do, since you’re more reacting to getting the results,
then proactively receive’ing like you’d have to do with Inbox.
In the aggregating Actor you can setup a simple counter that will count
down until you’ve received all results, and then trigger the printing of
them. You don’t have to do any blocking recive() then (good thing :-)).

You could send messages from your main() method to the experiment actors
similarily like you do with inbox - have an implicit val aggregator =
system.actorOf(...) so it would get the replies of the experiment actors.

2)
If you’d like to stick to the Inbox style, you can do that by extending the
deadline you’re willing to await for a message during receive() calls. The
default timeout is configured in akka actor’s reference.conf, and is equal:

# Default timeout to assume for operations like Inbox.receive et al
default-timeout = 5s

So you could just give it some very big deadline, like this:

import concurrent.duration._
val got = i.receive(5 minutes)

That will block until it gets a message, but well, if your experiment never
completes you’ll still get a timeout like you did.
With the Actor approach you could bake in a bit more fine grained control
(reset a timeout whenever an experiment completes etc).

I hope this helps to pick a direction :-)
-- 
Cheers,
Konrad Malawski
blog.project13.pl | java.pl | geecon.org  | gdgkrakow.pl | krakowscala.pl


2014-03-16 2:17 GMT+01:00 <[email protected]>:

> Hi,
> I am new in Akka.
> Here's situation.
> I am writing program which computes some math problem.
> 1 Experiment is computed by 1 EvaluationActor
> No. of experiments might be thousands,or hundreds of thousends, even more.
> Each EvaluationActor has child actor - ResultActor which collects stats
> from experiment.
> Now, I have EvaluationScheduler type(which's non-actor) and want to
> collect stats from all experiments to show it.
> According to documentation I should use Inbox class to be able to get
> multi replies from ResultActors.
> Here's some test code for Inbox usage :
>
> def InboxTest = {
>     implicit val as = ActorSystem()
>
>     val a = actor(new Act {
>       become {
>         case "hello" ⇒ sender ! "hi"
>         case "hello1" ⇒ sender ! "hi1"
>         case "hello2" ⇒ sender ! "hi2"
>       }
>     })
>
>     implicit val i = inbox()
>     a ! "hello"
>     a ! "hello2"
>     a ! "hello1"
>
>     i.receive().asInstanceOf[String].foreach(print _)
>     print("\n")
>     i.receive().asInstanceOf[String].foreach(print _)
>     print("\n")
>     i.receive().asInstanceOf[String].foreach(print _)
>     print("\n")
>
> The code is rough, but my thought was to show that I have to call
> receive() each time I want get next message.
> Since I can't get mailboxsize will be tricky to know when check for next
> message.
>
> So now, using this I need to build some mechanism to be sure that I have
> all stats from each ResultActor = each experiment.
> Simple solution for this is counting received messages and maybe sending
> some experimentID or something.
> But this's not solution, because if mailbox will be empty at I got :
> java.util.concurrent.TimeoutException: deadline passed
>
> Any better ideas/propositions?
> Maybe there's better way more like "out of the box" in akka for such task?
>
> regards
> Darius.
>
>  --
> >>>>>>>>>> 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.
>

-- 
>>>>>>>>>>      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