Hi,

I have a method to create an account balance actor per currency for that 
account, I had that on a hash map but I think that if Akka has an internal 
hash map *-concurrent or not-* to keep actor references then why should I 
keep yet another hash map?, I was using a computeIfAbsent(...) on my own 
hash map so I'm wondering if:

   1. Will resolveOne() method wait up to 5 seconds if the actor doesn't 
   exist?, I wish not to wait for so long if it really doesn't because such 
   actors are children of the supervisor calling the method within 
   onReceive(...)
   2. The following try to resolve one, if it succeed it just forward the 
   message else tries to create it and forward the message, if it fails 
   creating it after it couldn't resolve it *-unlikely but possible-*, it 
   will forward the message via actor selection because another thread *-the 
   next call to resolveOne()-* created it.

  
  private void applyToAccount(Currency currency, BalanceOperation operation) 
{
    final ActorContext context = context();
    context.actorSelection(currency.code).resolveOne(FIVE_SECONDS).
onComplete(
      new OnComplete<ActorRef>() {
        @Override
        public void onComplete(Throwable failure, ActorRef balanceRef) 
throws Throwable {
          if (!(failure instanceof ActorNotFound)) {
            // Actor exists, forward the message.
            balanceRef.forward(operation, context);
          } else {
            try {
              // Try to create it and forward the message.
              context.actorOf(balancePersistorProps(currency), currency.code
).forward(operation, context);
            } catch (Exception e) {
              // It failed creating it so looks the unlikely happened, 
forward the message via actor selection.
              context.actorSelection(currency.code).forward(operation, 
context);
            }
          }
        }
      }, context.dispatcher());
  }

Suggestions are very welcome,

Many thanks,

Guido.

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