Hi,
I have actor system, I initialize it at the application beginning.
I need to call these actors from my controllers, so I pass the ActorRef to
my controllers/services and keep them in local variable.
upon some actions from user the actor system could be stopped, then started
(not restart).
keeping the references in the controller/services causing me errors after
starting the ActorSystem as the controllers hold the old references
(incarnations).
So, how to keep the actor references?
should I use ActorSelection with each request? would that affect the
performance?
public class MyController {
public static Promise<Result> myAction(String param) {
ActorSelection myActor = Akka.system().actorSelection(
"akka://application/user/myActor");
String myMessage = "hello";
Promise<JSONObject> resultJsonObjectPromise =
Promise.wrap(ask(myActor, myMessage, 1000000)).map(
new Function<Object, JSONObject>() {
public JSONObject apply(Object response) {
return ((myResponse) response).getJsonResult();
}
});
return resultJsonObjectPromise.map(new Function<JSONObject, Result>() {
public Result apply(JSONObject response) {
return ok(response.toString());
}
});
}
}
or shall I keep the actor reference in a main class and each time
controller get the actor ref from this class?
public class ActorBag {
public static ActorRef myActorRef;
}
@ application start:
ActorBag.myActorRef = Akka.system().actorOf(
Props.create(MyActor.class, params), "MyActor");
public class MyController {
public static Promise<Result> myAction(String param) {
ActorRef myActor = ActorBag.myActorRef;
String myMessage = "hello";
Promise<JSONObject> resultJsonObjectPromise =
Promise.wrap(ask(myActor, myMessage, 1000000)).map(
new Function<Object, JSONObject>() {
public JSONObject apply(Object response) {
return ((myResponse) response).getJsonResult();
}
});
//same as above
}
}
What is the best practice
ActorRef myActor = ActorBag.myActorRef;
or
ActorSelection myActor =
Akka.system().actorSelection("akka://application/user/myActor");
or anything else
?
Regards,
MFarid
--
>>>>>>>>>> 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.