0

I have the following situation.

I have my web site written in Tapestry. On one of the pages, I'm required to generate a fairly large Excel or PDF document (around 20 MB). Now, since the entire process takes time, I'm asking my user to wait a bit.

However, when I tried to test the upper limits, I noticed that my entire application (not just the web part) freezes, because the generation eats up all the resources and the rest of the website and application becomes unresponsive.

Here is the flow how I've been doing it so far.

  1. User clicks a button to request the file on the page
  2. Data is being fetched from database (this part is quite fast)
  3. Data is passed to a Tapestry service which prepares it (nothing fancy, also fast)
  4. Prepared data is sent to EJB service which creates and deploys a visitor which creates the excel/pdf file
  5. The InputStream of the created file is passed all the way up to Tapestry which wraps it in StreamResponse and offers the download

What would be an appropriate way to handle this problem?

Could I perhaps use Tapestry's ParallelExecutor from some Tapestry service of mine in a manner like this?

Future<InputStream> future = executor.invoke(new Invokable<InputStream>() { ... });

My main objective is that the application and website keep running, that they do not freeze.

Thank you in advance.

ioreskovic
  • 5,531
  • 5
  • 39
  • 70

1 Answers1

1

Take a look at the progresslink demo from tapestry stitch. It might give you some inspiration to poll for a long running / asynchronous task in tapestry.

lance-java
  • 25,497
  • 4
  • 59
  • 101
  • Well, my task should not really be asynchronous, I cannot just hit the button and forget about it. I need to wait for the result (the file) and do something with it. – ioreskovic Oct 09 '14 at 10:49
  • 1
    As I said, it was for inspiration. You could extend the `ProgressTask` interface and add a `getResult()` method. This method is invoked only when `getProgress()` reaches 1 (100%). For your use case, getResult() will return the PDF (byte array) and you can stop polling and redirect to the PDF. – lance-java Oct 09 '14 at 10:55
  • Note, `ProgresssTaskManagerImpl` removes the tasks as soon as they are finished. You might need to store the result somewhere (ConcurrentMap) before removing. – lance-java Oct 09 '14 at 11:01