Hi Avi,

On Sun, May 10, 2015 at 9:43 AM, Avi <[email protected]> wrote:

> Hi,
> I want to implement I was looking at this example taken from typesafe
> activator (spray-actor-per-request)
> <http://www.typesafe.com/activator/template/spray-actor-per-request>
>
>
> class RestRouting extends HttpService with Actor with PerRequestCreator {
>
> implicit def actorRefFactory: ActorContext = context
>
> def receive = runRoute(route)
>
> val petService = context.actorOf(Props[PetClient])
> val ownerService = context.actorOf(Props[OwnerClient])
>
> val route = {
>  get {
>    path("pets") {
>           parameters('names) { names =>
>     petsWithOwner {
>            GetPetsWithOwners(names.split(',').toList)
>      }
>    }
>   }
>  }
> }
>
> def petsWithOwner(message : RestMessage): Route =
> ctx => perRequest(ctx, Props(new GetPetsWithOwnersActor(petService,
> ownerService)), message)
> }
>
>
>
> and I wonder if this is the best parctice to implement the actors creation
> :
> ctx => perRequest(ctx, Props(new GetPetsWithOwnersActor(petService,
> ownerService)), message)
> because I saw at the akka documentation this warning
> <http://doc.akka.io/docs/akka/snapshot/scala/actors.html> regarding
> creating actor within an actor :
> val props2 = Props(new ActorWithArgs("arg")) // careful, see below
>

The warning is here to remind users to be careful when constructing Props.
It is important that Props are serializable. When constructing Props
instances inside an actor one can easily close over the surrounding actor
instance. To avoid this, there is a recommended practice to create Props
factory methods inside the companion object that corresponds to your actor.


>
>
> also if we define an actor within an actor
> val ownerService = context.actorOf(Props[OwnerClient])
> how can it be tested ?
>

To make this testable you would need to either OwnerClient ActorRef or
Props into the RestRouting class. You can find more information with
examples on testing parent-child relationships
<http://doc.akka.io/docs/akka/2.3.11/scala/testing.html#Testing_parent-child_relationships>
in the Akka documentation.


>
>
> Just to make things clear - I am not criticizing, I am just trying to
> learn the best practice of implementation specially as I see the typesafe
> activator as educational source
>
>
> Best wishes
> Avi
>
>  --
> >>>>>>>>>> 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.
>



-- 
Martynas Mickevičius
Typesafe <http://typesafe.com/> – Reactive
<http://www.reactivemanifesto.org/> Apps on the JVM

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