scala - Akka: how to get the results? -


Consider the following skala code that calculates factories using the Acakka. I do not know how to get the output.

  Import Scale. Annotation. Tailrec Import akka.actor. (Actor, Actor, Actorsystem, Props) Import Scales. Convert Pattern. Ask import akka.util.Timeout import scala.concurrent.duration._ Case class GetResult () provides class factor housing calculator acct {DRF receive = {case number: int = & gt; Sender ! (Num, factor): Personal DF factor (num: int) = factorTail (num, 1) @ailailc Private private carcass (number: int, ac: big element): begun = {(num, acc) match {case (0, A) = & gt; One case (n, a) = & gt; FactorTech (N-1, N * A)}}} Class Factorial Collector (FACTORIAL: LIST [int]) Extends actor with actor logging {var list: LIST [BIGINT] = blue size = factorials.size For (num & lt; - factorials) {Context.actorOf (Props (new factorial communication))! Num} def receive = {case (num: int, fac: bigInt) => {Log.info ("$ FAC Originally for $ num") list = FAP :: list size - = 1 if (size == 0) {log info (list.toString) context.system.shutdown ()}} Case GetResult = & gt; Sender ! List}} class factorial (factors: list [int]) {well system = actor system ("factorial") wall collector = system. Factors (props (new factorial calculator (factorial), "collector") Built-in value timeout = timeout (10 seconds) Val future = collector? GetResult val results = await.result (future, timeout.duration) system.awaitTermination ()} var x = new functional (list (50, 18, 32, 28, 22, 42, 55, 48))  < / Pre> 

The results are stored in list , but x.result Empty list .

First you should not use the form context.actorOf () Props (new factorial cleeters but: context.actorOf (props [factorial communication])

Second, you can send a message to the factorial collector for an ascendant, for example:

Diff Received = {.... Case by Maricelt => Sender ! List ....}

Or instead of giving a list with the integer to calculate in constructor, you can send it to the method asked by the collector. Then you got the future with the calculation result in the future.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -