You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hugo Palma <hu...@gmail.com> on 2009/02/02 15:41:39 UTC

How to implement a long lasting operation waiting page

I have an operation that needs to be executed that could take a couple
of minutes and so i'd like to provide a page where at first it
displays a waiting message while the operation is getting executed and
then if shows the result of that operation, using ajax so that i don't
have to go to another page.

Any ideas about the best way to do this ? If i bind the process
execution to any phase of the page lifecycle it will always be
executed before it renders anything and i loose control on how to
update the page once the operation is complete.

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to implement a long lasting operation waiting page

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi,

Thread source takes the exception handler as parameter and I think you can
have a "PercentageCompleteHandler" also that it could take. That handler
should contain methods to set it ready, and to ask whether the task is
complete.

Set this PercentageCompleteHandler to the session of the executing user, and
pass it to the thread that executes the task. (Modify the service to take
PercentageCompleteHandler in also.) In the example below the finally part is
good place to mark the task as ready. If you want more detailed information
you can extend runnable and make it take the PercentageCompleteHandler that
it must update periodically.

public void runInThread(final Runnable task, final TaskExceptionHandler
taskExceptionHandler){
  26         new Thread(new Runnable(){
  27 
  28             public void run() {
  29                 try {
  30                    task.run();
  31                 } catch (Throwable e) {
  32                     taskExceptionHandler.exceptionThrown(task, e);
  33                 } finally {
  34                     _perthreadManager.cleanup();
  35                 }
  36             }
  37             
  38         }).start();
  39     }

You should be ok polling now with your page instance whether the task is
ready by asking it from the PercentageCompleteHandler  in the session, but
remember _not_ not lose reference to the PercentageCompleteHandler as that
is your view to the executing thread.

 - Ville


HugoPalma wrote:
> 
> Thanks.
> But how can the client side know when the task is complete ?
> 
> I tried to set a persistent field just after the task is complete but
> Tapestry throws an exception saying that it can't persist the field,
> probably because it's getting executed inside a thread.
> I have the client side polling the server side for any kind of signal that
> the task is over, but i can't quite figure out out to give that
> information
> to the client.
> 
> On Tue, Feb 3, 2009 at 12:30 PM, Ville Virtanen
> <vi...@cerion.fi>wrote:
> 
>>
>> Hi,
>>
>> take a look at this:
>> http://wiki.apache.org/tapestry/Tapestry5HowToRunTaskInThread
>>
>> Your page only delegates the execution of the task to another thread and
>> then the ajax part polls the page wether the task is ready, once it is
>> you
>> show the results.
>>
>> Don't know the ajax part, but that example should be extended a bit so
>> that
>> the thread source takes also the thread progress inspector which can tell
>> you how many percent the task is complete...
>>
>>  - Ville
>>
>>
>> HugoPalma wrote:
>> >
>> > I have an operation that needs to be executed that could take a couple
>> > of minutes and so i'd like to provide a page where at first it
>> > displays a waiting message while the operation is getting executed and
>> > then if shows the result of that operation, using ajax so that i don't
>> > have to go to another page.
>> >
>> > Any ideas about the best way to do this ? If i bind the process
>> > execution to any phase of the page lifecycle it will always be
>> > executed before it renders anything and i loose control on how to
>> > update the page once the operation is complete.
>> >
>> > Thanks.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > For additional commands, e-mail: users-help@tapestry.apache.org
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-implement-a-long-lasting-operation-waiting-page-tp21790821p21808947.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-implement-a-long-lasting-operation-waiting-page-tp21790821p21928063.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to implement a long lasting operation waiting page

Posted by Hugo Palma <hu...@gmail.com>.
Thanks.
But how can the client side know when the task is complete ?

I tried to set a persistent field just after the task is complete but
Tapestry throws an exception saying that it can't persist the field,
probably because it's getting executed inside a thread.
I have the client side polling the server side for any kind of signal that
the task is over, but i can't quite figure out out to give that information
to the client.

On Tue, Feb 3, 2009 at 12:30 PM, Ville Virtanen <vi...@cerion.fi>wrote:

>
> Hi,
>
> take a look at this:
> http://wiki.apache.org/tapestry/Tapestry5HowToRunTaskInThread
>
> Your page only delegates the execution of the task to another thread and
> then the ajax part polls the page wether the task is ready, once it is you
> show the results.
>
> Don't know the ajax part, but that example should be extended a bit so that
> the thread source takes also the thread progress inspector which can tell
> you how many percent the task is complete...
>
>  - Ville
>
>
> HugoPalma wrote:
> >
> > I have an operation that needs to be executed that could take a couple
> > of minutes and so i'd like to provide a page where at first it
> > displays a waiting message while the operation is getting executed and
> > then if shows the result of that operation, using ajax so that i don't
> > have to go to another page.
> >
> > Any ideas about the best way to do this ? If i bind the process
> > execution to any phase of the page lifecycle it will always be
> > executed before it renders anything and i loose control on how to
> > update the page once the operation is complete.
> >
> > Thanks.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-implement-a-long-lasting-operation-waiting-page-tp21790821p21808947.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: How to implement a long lasting operation waiting page

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi, 

take a look at this:
http://wiki.apache.org/tapestry/Tapestry5HowToRunTaskInThread

Your page only delegates the execution of the task to another thread and
then the ajax part polls the page wether the task is ready, once it is you
show the results.

Don't know the ajax part, but that example should be extended a bit so that
the thread source takes also the thread progress inspector which can tell
you how many percent the task is complete...

 - Ville


HugoPalma wrote:
> 
> I have an operation that needs to be executed that could take a couple
> of minutes and so i'd like to provide a page where at first it
> displays a waiting message while the operation is getting executed and
> then if shows the result of that operation, using ajax so that i don't
> have to go to another page.
> 
> Any ideas about the best way to do this ? If i bind the process
> execution to any phase of the page lifecycle it will always be
> executed before it renders anything and i loose control on how to
> update the page once the operation is complete.
> 
> Thanks.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-implement-a-long-lasting-operation-waiting-page-tp21790821p21808947.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to implement a long lasting operation waiting page

Posted by nillehammer <ta...@winfonet.eu>.
Hi Hugo,

perhaps you do not need ajax at all. The meta tag <meta
http-equiv="refresh" content="5; URL=myWaitingPage"> might come in
handy. This tag causes the browser to wait a certain amount of seconds
before it requests the url. You could implement "myWaitingPage" to check
whether the operation finished. If yes it would redirect to the result
page, if not it would redirect to itself.

Hope this helps. Regards, nillehammer
--
http://www.winfonet.eu

Hugo Palma schrieb:
> I have an operation that needs to be executed that could take a couple
> of minutes and so i'd like to provide a page where at first it
> displays a waiting message while the operation is getting executed and
> then if shows the result of that operation, using ajax so that i don't
> have to go to another page.
> 
> Any ideas about the best way to do this ? If i bind the process
> execution to any phase of the page lifecycle it will always be
> executed before it renders anything and i loose control on how to
> update the page once the operation is complete.
> 
> Thanks.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 

-- 
http://www.winfonet.eu

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org