I was probably overly wordy & not very clear on the details of our 
problem. The client side isn't the issue: We display the client progress 
bar via JavaScript & it's been working fine for a number of years. Our 
challenge is on the server side: Managing the background task in a 
separate thread. We have three basic requirements for the background task. 
It must:

1. Be cancellable.

2. Report its outcome (success/failure/warning).

3. Report incremental progress. 

Graceful handling of the thread outcome is an unexpectedly a tough nut to 
crack. The vast majority of examples we've seen use the Runnable interface 
(which doesn't help us, as it can't be canceled or return a value), rather 
than Callable interface (which meets our needs, but doesn't seem to play 
well with Wicket, since java.util.concurrent.FutureTask isn't 
Serializable).




From:   Martin Grigorov <mgrigo...@apache.org>
To:     "users@wicket.apache.org" <users@wicket.apache.org>
Date:   05/05/2014 03:32 PM
Subject:        Re: Progress Bar



Hi,


On Mon, May 5, 2014 at 7:18 PM, Richard W. Adams <rwada...@up.com> wrote:

> We have a requirement to implement a progress bar for long-running 
server
> operations. We can't use the code at
> https://github.com/wicketstuff/core/wiki/Progressbar, because it doesn't
> meet our corporate user interface look-and-feel standards.
>

Have you considered providing your own .css ?
https://github.com/wicketstuff/core/blob/wicket-6.x/jdk-1.6-parent/progressbar-parent/progressbar/src/main/java/org/wicketstuff/progressbar/ProgressBar.java#L109



>
> So, we started our own implementation. Our test page contains these
> methods below (the TestExecutor below class implements
> Callable<ExecutorResult>).
>
>
> 
//----------------------------------------------------------------------------------------------
> private Component createButton() {
>         return new AjaxButton("start-button") {
>                 private static final long serialVersionUID = -1;
>
>                 @Override protected void onSubmit(final 
AjaxRequestTarget
> ajax, final Form<?> form) {
>
>                         final ExecutorService service = Executors.
> newSingleThreadExecutor();
>                         try {
>                                 final ProgressBarTestPage page =
> ProgressBarTestPage.this;
>                                 final TransactionData data = new
> TransactionData (page.getId(), false);
>                                 final TestExecutor executor = new
> TestExecutor(data, getPermissions());
>
>                                 executor.addListener(page);     // 
Request
> notification when done
>                                 future = service.submit(executor); //
> Begin execution
>                                 progressBarUpdater.start(ajax, 
executor);
> // Start polling for progress
>
>                         } catch (final Exception ex) {
>                                 throw new RuntimeException(ex);
>                         }
>                         service.shutdown();     // Terminate gracefully
> (VM probably
>                 }               //      won't exit if we fail to do 
this)
>         };
> }
>
> 
//----------------------------------------------------------------------------------------------
> /**
>    Observer Pattern method to let us know when the task is done so we 
can
> check how things went.
> */
> @Override public void executionComplete(final EnmCallableExecutor
> executor) {
>
>         try {
>                 if (!future.isCancelled()) { //
> Unless execution was canceled
>                         final ExecutorResult result = future.get(); //
> Get the outcome
>                         System.out.println(result);
>                         /*
>                          * TODO: Show success or error message
>                          */
>                 }
>         } catch (final Exception ex) {
>                 ex.printStackTrace();
>         }
> }
>
> The ProgessBarUpdater class has this method:
>
>
> 
//----------------------------------------------------------------------------------------------
> /**
>  * Displays the progress bar &amp; begins the polling. We don't start 
the
> polling until
>  * explicitly told to do, for efficiency purposes.
>  * @param ajax The Ajax request wrapper.
>  * @param reporter The object to query for progress data.
>  */
> public void start(final AjaxRequestTarget ajax, final ProgressReporter
> reporter) {
>
>         add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(2)) {
>                 private static final long serialVersionUID = 1L;
>
>                 @Override protected void onPostProcessTarget(final
> AjaxRequestTarget ajax) {
>
>                         final Progress progress = 
reporter.getProgress();
>                         final String script =                   // Build
> script to update
>                                 ProgressScript.build(progress);  //
> progress bar
>                         ajax.appendJavascript(script);
>                         if (progress == null) {                 // If
> operation is finished
>                                 final ProgressBarUpdater updater =
>                                         ProgressBarUpdater.this;
>                                 updater.remove(this); //
> Stop timer to prevent
>                                 ajax.addComponent(updater);  // 
pointless
> polling
>                         }
>                 }
>         });
>         ajax.addComponent(this);
> }
>
> The page also contains a Future object so we can check the result after
> the thread finishes:
>
>         private Future<ExecutorResult> future;
>
> __________________________________________
>
> Having said all that, here's the problem: When I click the page's 
button,
> Wicket throws this error:
>
>         Unable to serialize class: java.util.concurrent.FutureTask
>
> The FutureTask object, I believe, is coming from the service.submit call
> whose return value we store in our Future variable.
>
> Does anyone know how to get around this roadblock?
>
>
>
> **
>
> This email and any attachments may contain information that is
> confidential and/or privileged for the sole use of the intended 
recipient.
>  Any use, review, disclosure, copying, distribution or reliance by 
others,
> and any forwarding of this email or its contents, without the express
> permission of the sender is strictly prohibited by law.  If you are not 
the
> intended recipient, please contact the sender immediately, delete the
> e-mail and destroy all copies.
> **
>



**

This email and any attachments may contain information that is confidential 
and/or privileged for the sole use of the intended recipient.  Any use, review, 
disclosure, copying, distribution or reliance by others, and any forwarding of 
this email or its contents, without the express permission of the sender is 
strictly prohibited by law.  If you are not the intended recipient, please 
contact the sender immediately, delete the e-mail and destroy all copies.
**

Reply via email to