java - Play Framework await() makes the application act wierd -


i having strange trouble method await(future future) of controller.

whenever add await line anywhere in code, genericmodels have nothing placed await, start loading incorrectly , can not access of attributes.

the wierdest thing if change in different java file anywhere in project, play try recompile guess , in moment starts working perfectly, until clean tmp again.

when use await in controller bytecode enhancement break single method 2 threads. pretty cool, 1 of 'black magic' tricks of play1. but, 1 place play acts weird , requires restart (or found, code changing) - other place can act strange when change model class.

http://www.playframework.com/documentation/1.2.5/asynchronous#suspendinghttprequests

to make easier deal asynchronous code have introduced continuations. continuations allow code suspended , resumed transparently. write code in imperative way, as:

public static void computesomething() { promise delayedresult = verylongcomputation(…); string result = await(delayedresult); render(result); }

in fact here, code executed in 2 steps, in 2 different hreads. see it, it’s transparent application code.

using await(…) , continuations, write loop:

 public static void loopwithoutblocking() {      for(int i=0; i<=10; i++) {            logger.info(i);           await("1s");      }      rendertext("loop finished"); }  

and using 1 thread (which default in development mode) process requests, play able run concurrently these loops several requests @ same time.


to respond comment:

 public static void generatepdf(long reportid) {     promise<inputstream> pdf = new reportaspdfjob(report).now();     inputstream pdfstream = await(pdf);     renderbinary(pdfstream); 

and reportaspdfjob play job class dojobwithresult overridden - returns object. see http://www.playframework.com/documentation/1.2.5/jobs more on jobs.

calling job.now() returns future/promise, can use this: await(job.now())


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -