Yes, almost: it should be context.actorOf, not system.actorOf.

Regards, Roland 

Sent from my iPhone

> On 3 Oct 2016, at 15:15, gervais.b <[email protected]> wrote:
> 
> Yes, sorry, state is good but per actor, so that I should create one actor 
> instance each time I would like to combine the two CSV. 
> 
> So, given that actor should/can have states and that tell is the preferred 
> approach. I should have something like that :
> 
> class Combiner(subject:Subject, report:ActivityReport) extends Actor {
>   system.actorOf(Props[HttpFetch], "fetch-first") ! Get("http://../first.csv";)
>   system.actorOf(Props[HttpFetch], "fetch-second") ! 
> Get("http://../second.csv";)
> 
>   def receive = {
>     case Got("http://../first.csv";, response) => 
>       tagsByName = parse(response.body)
>       maybeCombine()
>     case Got("http://../second.csv";, response) => 
>       activities = parse(response.body)
>       maybeCombine()
>   }
> 
>   def maybeCombine() = if ( tagsByName.isDefined && activities.isDefined ) {
>     val tag = tagsByName.filter(line => line(1)==subject.name)(0)
>     activities.filter(line => line(0)==tag).foreach(report.add)
>   }
> 
> 
> }
> 
> 
> Is that okay ?
> 
> 
>  
> 
>> On Monday, 3 October 2016 14:37:39 UTC+2, rkuhn wrote:
>> 
>>> 3 okt. 2016 kl. 14:30 skrev gervais.b <[email protected]>:
>>> 
>>> Hello,
>>> 
>>> I'm fairly new with Akka (and maybe the whole question below is polluted by 
>>> my synchronous background). In my app, I have to parse 2 CSV available as 
>>> HTTP, I plan to access them from one actor that accept two messages (one 
>>> per csv). But I should add another HTTP resources next week. So I'm 
>>> planning to create one 'HttpFetch'. My question is about the reply for this 
>>> actor. Should use tell or ask ? 
>>> 
>>> With ask everything seems simple, I ask for a resource and receive a Future 
>>> that I can map. But I have the feeling that ask must be used in border 
>>> cases.
>>> With tell then the 'HttpFectch' actor will receive 'Get(target:URI)' and 
>>> send the response later with a 'Got(target: URI, response:..)'. That's nice 
>>> and looks simple also. But I have to combine the result of the two CSV 
>>> (find "tag" in first and filter lines of second based on this "tag"). So I 
>>> have to maintains state in my actor and I know this is a bad idea.
>> 
>> Maintaining state is the only point of an actor, that’s definitely not a bad 
>> idea :-) Where did you get the notion that actors should be stateless?
>> 
>>> So, what is the best pattern to send and combine the response of two 
>>> messages ?
>> 
>> I’d prefer the tell variant and create a new Actor for each such 
>> combination. This way you can focus on the business logic without getting 
>> distracted by incidental concerns like managing multiple such processes in 
>> parallel—which would then be governed by the actor library for you.
>> 
>> Regards,
>> 
>> Roland
>> 
>>> 
>>> -- 
>>> >>>>>>>>>> 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 https://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 https://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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to