I am trying to implement a long running background process that is spawned when a user visits a page. I would like to display the progress of the task just like in this example: http://web.archive.org/web/20130122091205/http://www.lunatech-research.com/archives/2011/10/31/progressbar-jqueryui-websockets-playframework
Does anyone know of a tutorial for PlayFramework 2.0 (using inbuilt AKKA) ? This one is for 1.2
After reading all the Akka Documentation for Java http://doc.akka.io/docs/akka/2.0.1/intro/getting-started-first-java.html i’ve come up with this which seems to work well.
The system works by first creating a unique Actor to process a “report” (when the generate page is loaded). This actor spawns a child actor which reports its progress back to the parent. The parent actor is then polled via JavaScript for the status of the child thread.
Once the child has finished it is terminated and once the Parent detects the child is finished it terminates itself.
Below is all the code, feel free to tear me apart if i’ve gone about this the wrong way! (Is it OK to store state in Actors?!?)
The controller code:
The Master Actor:
The Child Actor:
The view page with the long polling JavaScript: