Thanks for clarifying. I was using the version of complete I showed in
order to have control over the status code etc, but there are no doubt
other ways to do that in Spray.

My takeaway is that I shouldn't be too hasty about standardizing on
per-request actors.

On Wed, Oct 1, 2014 at 2:13 AM, Akka Team <[email protected]> wrote:

>
> Hi Richard,
>
> No, I mean the other complete() method that you call from the Success and
> Failure paths of the onComplete block. Why not just use
> complete(result.transform(...))?
>
> -Endre
>
> On Wed, Oct 1, 2014 at 2:01 AM, Richard Rodseth <[email protected]>
> wrote:
>
>> Hi Endre
>>
>> Yes, the one I showed (onComplete()) *is* taking a future. The result of
>> my ask is a Future[Long].
>>
>>
>>
>> On Tue, Sep 30, 2014 at 3:58 AM, Akka Team <[email protected]>
>> wrote:
>>
>>> Hi Richard,
>>>
>>>
>>>
>>>> The route looks something like this:
>>>>
>>>>     post {
>>>>
>>>>       val result = (xyzService ?
>>>> XYZService.CreateXYZ(xyzAttributes)).mapTo[Long]
>>>>
>>>>       onComplete(result) {
>>>>
>>>>         case Success(value) => complete(s"The result was $value")
>>>>
>>>>         case Failure(ex) => complete(StatusCodes.InternalServerError,
>>>> s"An error occurred: ${ex.getMessage}")
>>>>
>>>>      }
>>>>
>>>>
>>> Isn't there a version of complete() that take a Future directly? (maybe
>>> called completeAsynch, but I think there should be one). I am not sure
>>> calling complete() out of the context of the actor works or not.
>>>
>>> -Endre
>>>
>>>
>>>
>>>>     }
>>>>
>>>> In this case the XYZService actor forwards a transformed message to the
>>>> DbActor
>>>>
>>>>     case msg @ XYZService. CreateXYZ(attributes) => {
>>>>
>>>>       dbActor forward DbActor.AddXYZ(attributes) // Interesting that I
>>>> can "forward" a new message
>>>>
>>>>     }
>>>>
>>>> If the response needed transforming, presumably an additional ask would
>>>> be needed within the XYZService.
>>>>
>>>> The DbActor replies with a result
>>>>
>>>>     case AddXYZ(attributes) => db withSession { implicit session =>
>>>>
>>>>       try {
>>>>
>>>>         val result = XYZDAO.add(attributes)
>>>>
>>>>         sender() ! result
>>>>
>>>>       } catch {
>>>>
>>>>         case e: Exception =>
>>>>
>>>>           sender() ! akka.actor.Status.Failure(e)
>>>>
>>>>           throw e
>>>>
>>>>       }
>>>>
>>>>     }
>>>>
>>>> Does this seem reasonable? Would it be considered better practice to
>>>> use per-request actors for every route, to avoid the use of tell, or
>>>> somehow pass the request context to the service actor for completion? I've
>>>> read the Ian Forsey article, but am a bit unclear on whether to standardize
>>>> on the per-request model. I did notice that the route I implemented using
>>>> per-request is slow on all but the first request, and I haven't had time to
>>>> look into that.
>>>>
>>>> --
>>>> >>>>>>>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Akka Team
>>> Typesafe - The software stack for applications that scale
>>> Blog: letitcrash.com
>>> Twitter: @akkateam
>>>
>>> --
>>> >>>>>>>>>> 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.
>>
>
>
>
> --
> Akka Team
> Typesafe - The software stack for applications that scale
> Blog: letitcrash.com
> Twitter: @akkateam
>
> --
> >>>>>>>>>> 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