I have a RMI controller which receives requests through the network. This controller delegates responsibility on an akka actor which later on the time gets in touch with a pool of workers for resolving an algebraic operation.
Is enough the below piece of code to ensure that my akka master actor (masterActor) will receive and respond properly all the request from each thread that RMI creates for each request to my controller? I mean, are Patterns.ask and Await.result thread safe? Have they a way to access with mutual exclusion to masterActor reference? Or I need to create a critical section in my controller?
Class MyController extends ... {
/* ... */
ActorRef masterActor;
/* ... */
public <O extends AlgebraOp<R>, R extends Equation & Resolved> R resolve(
Equation AlgebraOp, Context context){
EquationAndContext message = new EquationAndContext(AlgebraOp, context);
Future<R> future = (Future<R>) Patterns.ask(masterActor, message, timeout);
R operationResolved = null;
boolean timeoutExpired = false;
while(!timeoutExpired) {
try {
operationResolved = (R) Await.result(future, timeout.duration());
timeoutExpired = true;
} catch (Exception timeExpired) {
/* Re-build the future for next try */
future = (Future<R>) Patterns.ask(masterActor, message, timeout);
}
}
return operationResolved;
}
}
Cheers