Akka Accompaniment Chord Pools

I consider the use of new typed channels as a way to support the actor model in my project without the pain of a large number of explicit casts, where you really need to wait for an answer.

I was lucky with the creation of typed channels and their integration, but so far I do not see any simple solutions for creating pools of these participants for parallel execution, which is easy to do with ordinary untyped participants. Do I need to create my own router system?

For example, for untyped actors, I can do something similar, and I magically get four actors.

akkaSystem.actorOf(Props[UntypedActor]
                   .withRouter(RoundRobinRouter(nrOfInstances=4)), "routed")

For typed pipes, I need to do something like this:

ChannelExt(akkaSystem).actorOf(new TCActor, "singleton")

Obviously, I could write a second typed channel that creates a pool of actors and rotates between them, but this is similar to what someone would have done before!

+4
source share
1 answer

As noted in the comments, Akka refused to support typed channels, and Patrick Norvaull suggested using untyped actors. One way to sort things out on the response side is with a query template, Future.mapTo method, and pattern matching.

For example, suppose you have some class hierarchy embedded in Basewith subclasses of type OakLeaf, ShinyLeafand Needle. From the actor’s side you can do such things:

import akka.pattern.ask

(myActor ? MessageToActor).mapTo[Base] match {
  case oak: OakLeaf => ...
  case shiny: ShinyLeaf => ...
  case needle: Needle => ...
}

I have no suggestions on how to resolve the issue of which channels have been provided.

, Akka Java . Scala , Java - ?

0

Source: https://habr.com/ru/post/1524391/


All Articles