Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Asynchronous Jobs - Struts Action Classes

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can anyone please elaborate on the steps taken to execute asynchronous jobs from a Struts Action Helper Class? For example:

User clicks a link/button/etc and a call to the Action Class is made. The Action Class calls a method in the Helper Class that starts a process execution. The user is then able to navigate freely throughout the application while this is in progress. Once the execution completes, the user is sent a notification that the process has finished.

I have an understanding of how to start the process execution, but as for the notification and navigation aspects of my requirement, I have yet to develop a solution for.

If anyone has any valuable input, advice, tips, directions, etc. Please Feel FREE to reply!

I need some kind of direction here...
Thanks in advance.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure this is what you're asking about, but it sounds like you're trying to use AJAX. Here's a link to a short AJAX description: AJAX primer.

Essentially, AJAX lets you make server side calls from the client using javascript and then asynchronously wait on the server to respond. Meanwhile, you can move about freely in the application.

Hope this helps
 
John Simpson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is partially what I need. I have implemented the Ajax functionality.

My problem is that once the request has been submitted, the execution of the process needs to be separate from the return response.

So:
The client clicks a link, the request is submitted, (asynchronously) and the client is then able to navigate within the page. On the server side, the request comes in, and evaluated to the corresponding process, that

a) either starts a thread
b) gets added to a queue

While the process is executing, a response is sent to the client stating that the process is in motion. The client is still able to freely navigate throughout.

Once the process is finished, a notification is sent to the client's browser stating that it has finished, (may or may not have a link to the result).

Does this make it more clear?
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does your server-side technology look like? One project that I worked on briefly had a fairly elaborate job processing architecture that was based on message driven beans and Weblogic custom features. (I only worked a little with the messaging service; I did not design or develop it) My current project has a much simpler job processing scheme where the Action kicks off a thread and the processing thread records its state in the database. Other actions can then poll the database to get the status of the job.

- Brent
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this has anything to do with struts (there is a tiny chance - if you really care about the server knowing what's happening with the client).

When you make and AJAX call you the server has no idea that it was an AJAX call. It simple returns a response when it's ready. The Asynchronous behavior is handled by the browser. The browser is free to navigate at will. I suspect you probably want to be able to receive the response after navigating away from the page that initiated the request. This is not possible... but you can fake it. The trick is to keep the piece of code that initiated the AJAX call, as you navigate around. Probably the easiest was is to stick the the whole site/app in an iframe. Out side of the frame you would have the AJAX code to send and receive asynchronously (you would call the javascript functions by using "parent.").

Does that at all seem like it would behave as expected? (I know that the url changing is sometimes a problem in that scenario, but you can use a hash/anchor if that improves usability/bookmaking)
 
John Simpson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for the replies!


I suspect you probably want to be able to receive the response after navigating away from the page that initiated the request. This is not possible... but you can fake it.



Yes, this is exactly what my requirement is.


The trick is to keep the piece of code that initiated the AJAX call, as you navigate around. Probably the easiest was is to stick the the whole site/app in an iframe.



When you say "piece of code" are you referring to the url & its parameters?
---

UPDATE: I have the functionality to run the asynchronous process, using a separate Struts Action. (which gets called from the Ajax request) The 'asynchAction' starts a thread instance of my utility. (which runs the process). My problem now is sending a notification to the client that the process has finished...

I have read through several other forums, which state that the client should periodically refresh, or re-submit the request. Then in the asynchAction have a condition to see if the process is finished. This seems to be managable, but does anyone have other ideas?

I basically need a method to notify the client that the process has finished. (after the initial response has been sent.)

Any and all input is greatly appreciated!

 
Quincy Acklen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see what you're getting at. Maybe a quick example.

Take a page that has two frames (or iframes) A and B. When you navigate around your site you do it all in frame A. But when you want to kick off some long slow request (even synchronous one - more on that in a minute) you use frame B. Frame B is unaffected by what happens in frame A. Frame B maintains its state/session/scope independent of frame A.

Whenever the response is ready it is sent to frame B. And that response can be pretty much anything - of particular use is something that can modify frame A (or even a simple javascript alert() from frame B can notify the user the slow request has finished). That's just basic use of frames and requires no "ajax" at all.

A request can be sent and left waiting for a response synchronously in _that_ frame without affecting the other frame. But, if synchronous, it will prevent other things from happening in that frame (B) until the response is returned. For this reason you may wish to use ajax requests inside frame B (or alternatively more frames).

All of this requires no special handling on the server (AJAX is purely a client side "technology"). You can do things on the server to be more ajax friendly, but they shouldn't be required.

With ajax you simply don't have to use frames or wait for the response. You can send a request and pretty much forget about it until it returns. What that means is NOT that you can navigate away from the page that made the request, rather you can continue to interact with the page that is there. If the request were synchronous, mouseover effects and javascript and scrolling wouldn't work until the response is received. With ajax the page continues to "work", but you must remain on the page that made the request if you want to receive the response.

This is why I suggested the extra frame. It seems like you want to use the rest of your app as it is (without making the whole thing ajax based), and just have this one request be asynchronous.
 
John Simpson
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies...

I have discovered my own confusion. The issue that I am having is that my initial request, (from the client - ajax) is asynchronous. BUT, the call to run the process in my struts action is not asynchronous. My action simply receives the request, starts a thread, and returns a response. The thread is the process which needs to be ran asynchronously. Not the initial request from the client. I guess because of 'asynchronous' abilities of ajax, I was expecting different results. It is clear now what I need to do. Thank you for your input though, it was very helpful...
 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Mr. John Simpson. Iam having the same kind of problem to be handled in my application. My situation is I just want to put a request from GUI in struts and I dont want my gui to wait for the response. I hope you have handled this situation successfully in your application. Can you please help me by sharing you solution approach with me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic