The linked pull request includes a Java version, see:
https://github.com/akka/akka/pull/15540/files#diff-4161415cbe164e514bbc16114e346152R199

The docs are published automatically as snapshot:
http://doc.akka.io/docs/akka/snapshot/java/typed-actors.html#Typed_router_pattern

Happy hakking!



On Wed, Jul 16, 2014 at 11:07 AM, <simafeng...@gmail.com> wrote:

> Thank you very much, Mala
> But I have no idea about scala. Do you have code in java?Thanks
>
>
>
> On Monday, July 14, 2014 7:25:02 PM UTC+8, Konrad Malawski wrote:
>>
>> Hello there,
>> Since TypedActors are implemented as plain message sends (the message
>> representing the proxy method calls is called MethodCall), you can
>> simply do an untyped router, and then add a typed proxy before it:
>>
>> "TypedActor Router" must {
>>
>>   "work" in {
>>     val t1 = newFooBar
>>     val t2 = newFooBar
>>     val t3 = newFooBar
>>     val t4 = newFooBar
>>     val routees = List(t1, t2, t3, t4) map { t ⇒ 
>> TypedActor(system).getActorRefFor(t).path.toStringWithoutAddress }
>>
>>     val router = system.actorOf(RoundRobinGroup(routees).props(), "router")
>>
>>     val typedRouter = TypedActor(system).typedActorOf[Foo, 
>> Foo](TypedProps[Foo](), router)
>>
>>     info("got = " + typedRouter.optionPigdog())
>>     info("got = " + typedRouter.optionPigdog())
>>     info("got = " + typedRouter.optionPigdog())
>>     info("got = " + typedRouter.optionPigdog())
>>     info("got = " + typedRouter.optionPigdog())
>>
>>     mustStop(t1)
>>     mustStop(t2)
>>     mustStop(t3)
>>     mustStop(t4)
>>   }
>> }
>>
>>
>> And with a small modification of the pigdog to include a number (instance
>> value), we can see that the routing actually works:
>>
>> [info] TypedActorRouterSpec:
>> [info] TypedActor Router
>> [info] - must work (134 milliseconds)
>> [info]   + got = Some(Pigdog-33)
>> [info]   + got = Some(Pigdog-46)
>> [info]   + got = Some(Pigdog-25)
>> [info]   + got = Some(Pigdog-19)
>> [info]   + got = Some(Pigdog-33)
>>
>>
>> // whoa, intellij's new colorized copy paste is a bit weird. Not sure if
>> awesome or just weird ;-)
>> --
>> Konrad 'ktoso' Malawski
>> hAkker @ typesafe
>> http://akka.io
>>
>  --
> >>>>>>>>>> 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 akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Cheers,
Konrad 'ktoso' Malawski
hAkker @ Typesafe

<http://typesafe.com>

-- 
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
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