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());
}
private void applyToAccount(Currency currency, BalanceOperation operation) {
context().child(currency.code).
getOrElse(new AbstractFunction0<Option<ActorRef>>() {
@Override
public Option<ActorRef> apply() {
return Option.some(context().actorOf(balancePersistorProps(currency), currency.code));
}
}).
get().forward(operation, context);
}
private void applyToAccount(Currency currency, BalanceOperation operation) {
context().child(currency.code).
getOrElse(() -> Option.some(context().actorOf(balancePersistorProps(currency), currency.code))).
get().forward(operation, context);
}
--
>>>>>>>>>> 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+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.