Monday, 30 September 2013

Play Frame work 2.2 How Concurrent execution works

Play Frame work 2.2 How Concurrent execution works

Recently, we started to work with play 2.2. Previously we were working
with play 2.1.3. In play 2.2 it says Akka.future and async methods are
seen as deprecated. Also when we tried to run below piece of code
fetchSample() through a loop, it took more time to complete in play 2.2.
So how can we replace the below deprecated code with the latest one?
private static Promise<SampleDBResponseBean> fetchSample(
final Document sampleDoc) throws Exception {
Promise<SampleBean> promiseOfSampleJson = Akka.future(
new Callable<SampleBean>() {
public SampleBean call() throws Exception
{
return doSomeCalc(sampleDoc);
}
});
}
private Result getAsyncResult(final SampleResponseBean
sampleDbResponseBean) {
List<F.Promise<? extends SampleDBResponseBean>> promiseList =
sampleDbResponseBean
.getSampleHelperList();
Promise<List<SampleDBResponseBean>> promiseJsonObjLists = Promise
.sequence(promiseList);
return async(
promiseJsonObjLists.map(
new Function<List<SampleDBResponseBean>, Result>() {
public Result apply(List<SampleDBResponseBean> sampleList) {
SampleResponseBean sampleResponseBean = new SampleResponseBean();
sampleResponseBean.setStatus("success");
sampleResponseBean.setSampleList(sampleList);
JsonNode jsNodeResponse = Json.toJson(sampleResponseBean);
return ok(jsNodeResponse);
}
}));
}
I had searched a lot of places not seeing any solution. The problem
effects our code performance when comparing to 2.1.3.
Any ideas how can we implement the deprecated methods for the above 2
methods in play 2.2?

No comments:

Post a Comment