Hi everyone, I'm just a novice in using Akka. By developing a small 
university project, I had a doubt:
I find myself in the situation where N actors send a message, to an oracle 
actor, the message contains a ticket (an object with a number indicating 
the execution position) and a number to compare with the secret one inside 
the oracle itself .
The oracle will have to compare each message, then establish the right 
execution order (Ticket T1 <T2 <T3 .... TN).

I'm trying two ways, the first is to use "stash" and "unstash" but getting 
poor results, only the first actor can submit his guess, honestly I do not 
even know if logically it may be the right choice

public void onReceive(Object message) throws Throwable {
 if (!gameFinished) {
 if (message instanceof GuessMsg && nRequest < nPlayers) {
 unstashAll();
 if (!gameFinished && ((GuessMsg) message).getTicket().getValue() == nRequest + 
1) {
 ResultMsg result = getResult(((GuessMsg) message).getGuess());
 getSender().tell(result, ActorRef.noSender());
 nRequest++;
 }

 } else {
 nRequest++;
 stash();
 }
 } else {
 throw new GameFinishedException();
 }
}


In the second way I tried to make an internal list to the actor containing the 
mesages, when I received them all, to rearrange them, and in each message I 
pass the reference to the sender object (getSelf ()) but when I send the answer 
it seems 

do not get to the destination and then get a timeout event: 
AskTimeoutException, this is the code:


public void onReceive(Object message) throws Throwable {
 if (!gameFinished) {
   if (message instanceof GuessMsg && nRequest < nPlayers) {

     orderList.put(((GuessMsg) message).getTicket().getValue(), ((GuessMsg) 
message).getGuess());

     if (orderList.keySet().size() == nPlayers && !gameFinished) {
       Object[] keys = orderList.keySet().toArray();
       Arrays.sort(keys);
       Result result = getResult(orderList.get(key));
       if (result.found())
         this.gameFinished = true;
       ActorRef sender = orderList.get(key).getSender();
       sender.tell(result, ActorRef.noSender());
     }
    }
   }
 } else {
    throw new GameFinishedException();
 }
}


This is the request I send from Player Actor:


if (message instanceof TryMsg) {
 Future<Object> future = Patterns.ask(this.oracle, new GuessMsg(ticket, new 
Guess(id, value, getSelf())), 20000);
 Result result = (ResultMsg) Await.result(future, timeout.duration());
 System.out.println("[PLAYER-" + id + "] Get Result");
 checkResult(result);
}

What do you think? Can anyone help me?

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to