Best way to integrate with heavy backend?

161 views
Skip to first unread message

obsfucation

unread,
Mar 27, 2011, 8:05:37 PM3/27/11
to play-framework
Hi,

As part of a project I'm doing, I need to be able to integrate a web
front-end onto a Java document-processing system I have been given.

Having explored many other Java web frameworks, Play! jumps out as
being very approachable, however I'm having a few problems
understanding how I should build a Play! website on top of what I
currently have.

The Java back-end I currently have runs relatively slowly, and so I do
not want to make users wait on the site whilst the processing is
taking place.

My question can be broken down into the following:

1) How should I interact with the standalone Java application on the
backend, from the Play! frontend?

2) How could I 'start' the task in the back end, tell the user this
has occured and how could I then show them when it has finished?

I'm sorry if this is poorly articulated, and will of course be able to
provide any more details as needed.

Thanks for any help you can give!

felipera

unread,
Mar 28, 2011, 2:34:00 AM3/28/11
to play-framework
http://www.playframework.org/documentation/1.1.1/jobs

Read up about suspendable requests, oh it's gorgeous.

Have Fun!
Felipe
http://geeks.aretotally.in

Morten Kjetland

unread,
Mar 28, 2011, 8:21:45 AM3/28/11
to play-fr...@googlegroups.com
One approach is this:

The play app return html without data.
Then you use jquery to fetch data from play via ajax.
when the  play receives the ajax call, you can use play async features to go get the data from backend. When the backend data is ready you return it to the browser.
While the browser waits for data, you can display a spinning progressbar or something.

This way you can create a webapp that looks responsive even though it isn't.. :)

-morten

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


obsfucation

unread,
Mar 28, 2011, 5:08:03 PM3/28/11
to play-fr...@googlegroups.com, felipera
Read up about suspendable requests, oh it's gorgeous.

I really can't describe how much I agree, that is very nice. One follow-up question I'm not quite sure on- what would the user's browser behaviour be in this case?

Would it seem like one long request, or could I render something to them in the mean time (which I'm not sure is possible, given that a 'render' call ends the execution of the method/action I thought?).

Given that the task I'm executing on the back-end may take 30 secs or more, I really need to be able to display something in the mean time- at least to confirm that the action has begun.

Thanks for your help thus far!

obsfucation

unread,
Mar 28, 2011, 5:12:10 PM3/28/11
to play-fr...@googlegroups.com, Morten Kjetland
Hi Morten,

Cheers for your suggestion here.

Would you be able to elaborate more on your third step (or suggest any resources that may help with achieving it)?

I'm unfortunately very new to Play!, so don't quite understand how I would create an action just for the AJAX to call and how I could then use the async features (jobs, right?) to wait for the results and then return them.

Also, I'm hopeless at Javascript, but there's only one way for me to change that ;)!

Thanks very much in advance

Ivan San José García

unread,
Mar 29, 2011, 2:53:32 AM3/29/11
to play-fr...@googlegroups.com
I think Morten want to describe something like this:

User request page that do long task (Controller.pageLongTask()):
public static void pageLongTask() {
render();
}

pageLongTask.html:
<img id="spinning" src="spinning.jpg" />
Loading...
$(document).ready() {
$.get(
"/longTask",
function(data) { $('#spinning').hide(); alert(data); },
);
}


And, longTask controller should be a suspended request that you can
see in documentation
of Play!:
public static void longTask() {
if (request.isNew) {
Future<String> task = new doVeryLongTask().now();
request.args.put("task", task);
waitFor(task);
}

render(((Future<String>) request.args.get("task")).get());
}

Note that this code is only for that you can have an idea of what
Morent want to describe, I didn't test this code!!

2011/3/28 obsfucation <chrisjam...@gmail.com>:

grandfatha

unread,
Mar 29, 2011, 5:13:10 AM3/29/11
to play-framework
You can run a JS Timer (look at JS "setTimeout()"-functions) that asks
for the "current status" via an AJAX-request every 500 ms and display
the result to the user in some way.

All of this however depends on what feedback your "heavy backend"
provides, though. A progress-bar only makes sense if you can
interpolate this feedback into a decimal value between 0 and 1,
because otherwise you will be forced to use an indefinite loading-
spinner/progress-bar, which does not really provide information about
whether the long-running-task is a) still running or b) how much time
is left.



grandfatha

unread,
Mar 29, 2011, 5:14:07 AM3/29/11
to play-framework
Try looking at the chat sample app for demonstration of this kind of
applications.
Reply all
Reply to author
Forward
0 new messages