|
Lazy downloads in JWSPage Contents
IntroductionJava WebStart supposedly offers a lazy download facility, but developers report that it is difficult to get JWS to honor the 'lazy' attribute. The JNLP Specification notes in the first paragraph of section 4.4 "Parts and Lazy Downloads".
One hopes this vague warning only applies to two situations
Note that (old) examples 1-5 can be seen at javasaver.com. Example 6Example of 'lazy' download (of media) that provides a progress dialog for the end user.
Result 6
This example uses reflection to load media referenced in the
JNLP file. The web-start The entire process is called from a new thread, to ensure that it does not block the Event Dispatch Thread. Still broken?!
Java Web Start 1.6.0 Using JRE version 1.6.0 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\Administrator ---------------------------------------------------- c: clear console window ... v: dump thread stack 0-5: set trace level to <n> ---------------------------------------------------- DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@fec107 Part animal downloading! jar:http://www.physci.org/jws/cache/media/animalmedia.jar!/image/DCP_7940.jpg user cancelled action? ..proceed and try DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@fec107 Part plant downloading! java.lang.RuntimeException: canceled by user at com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl.progress(Unknown Source) at com.sun.jnlp.DownloadServiceImpl$ProgressHelper. Java Web Start 1.6.0 Using JRE version 1.5.0_08 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\Administrator ---------------------------------------------------- c: clear console window ... v: dump thread stack 0-5: set trace level to <n> ---------------------------------------------------- DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@d9896e Part animal downloading! jar:http://www.physci.org/jws/cache/media/animalmedia.jar!/image/DCP_7940.jpg Part plant cached! jar:http://www.physci.org/jws/cache/media/plantmedia.jar!/image/100_1829-800x600.jpg user cancelled action? ..proceed and try DownloadServiceListener com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl@d9896e Part art downloading! java.lang.RuntimeException: canceled by user at com.sun.jnlp.DownloadServiceImpl$DefaultProgressImpl.progress(Unknown Source) at com.sun.jnlp.DownloadServiceImpl$ProgressHelper.
I am getting runtime exceptions 'cancelled by user', for any call after the 1st download (2nd call, 3rd call etc.) of each program run. On-screen, the dialog 'Verifying application' appears, while the console gets a stacktrace. The odd thing is this example works as expected from the local file system! It is only the version running off the internet that has the 'cancelled by user' problem. Other resultsThis example was also mentioned on the usenet newsgroup comp.lang.java.programmer on the thread WebStart caching test., here are the results.
Download Example 6The source, (current) media files and build script can be found in cache6.zip (903 KB). Download and expand the archive, run the build script. The build file's default task launches the application off the local filesystem. Example 7Abandoned the default progress dialog in favor of a simpler 'home rolled' solution. This was largely for the purposes of testing whether I had made some incorrect assumptions in my earlier coding, and partly because I am sick of trying to make the default dialog work reliably.
Result 7Initial testing locally, suggests the custom progress dialog appears, updates and disappears reliably. Update! It was later discovered that the download might be so fast that the test condition of the download percentage reaching 100, used to set the dialog invisible, was never met. Or to put that the short way, for fast downloads, the dialog stayed on-screen. Download Example 7I never got around to uploading e.g. 7, which was found to be flawed in any case. See e.g. 8 download. Example 8Example 8 implements a simple and kludgy fix for the failure of the dialog to disappear, for fast downloads. Setting a 'past high percent' flag once the download reaches 95% complete, and watching for a later progress of '0' (the value returned after the download is complete) allows the code to know it can hide the dialog.
Result 8Hooray! We seem to have sucess.. Download Example 8The source, (current) media files and build script can be found in cache8.zip (<100 Kb, without the media). ReferencesIt has been mentioned on the comp.lang.java.programmer usenet newsgroup under the title WebStart caching test Also mentioned on the Sun forum for Java Web Start & JNLP as 'lazy' download test |