Reputation: 1486
Got a question on actors within the play framework. Disclaimer - I am still new to actors/AKKA and have been spending quite a while now reading through documentation. I apologise if the answers to any of the below is already documented somewhere that I have missed.
What I would like to verify is that I am implementing a correct/idiomatic solution to the below scenario:
Case: Using play framework, I need to execute code that may block (sql query) in such a way that it does not hinder the rest of my web server.
Below is my current solution and some questions:
static ActorRef actorTest = Akka.system().actorOf(
Props.create(ActorTest.class));
public static Promise<Result> runQuery() {
Promise<Result>r = Promise.wrap(
Patterns.ask(actorTest, query, 600000)).map(
new Function<Object, Result>() {
public Result apply(Object response) {
return ok(response.toString());
}
});
return r;
}
Any clarification on the above will be greatly appreciated.
Upvotes: 0
Views: 563
Reputation: 1813
I'm using mostly Scala with Akka and Play so I may be misguiding you but let's give it a try.
First of all you can ditch actors for the task you want. I would just run the computation in the Future.
User actors when you need to have some state. Running query by async mean will do just fine with Future.
Futures and Actora are run on ExecutionContext that the default reincarnation is available in Scala by importing and using by reference. This may be different in Java but probably not much. That default ExecutionContext is configured in application.conf just like you've said.
Upvotes: 1