diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2008-03-07 14:15:17 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2008-03-07 14:15:17 +0000 |
commit | 1262a4bbedd3112e9af77c43f520e0527eef9b7b (patch) | |
tree | 51b7db271389269dacfcdf986c38a4d0ccdee305 | |
parent | 3a7672a07651ac11b42a80fcd0ba83983f752a24 (diff) | |
download | vaadin-framework-1262a4bbedd3112e9af77c43f520e0527eef9b7b.tar.gz vaadin-framework-1262a4bbedd3112e9af77c43f520e0527eef9b7b.zip |
Documentation and making upload events more thread safe
svn changeset:4005/svn branch:trunk
-rw-r--r-- | src/com/itmill/toolkit/ui/Upload.java | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/com/itmill/toolkit/ui/Upload.java b/src/com/itmill/toolkit/ui/Upload.java index efe1f697e4..fb64489fb0 100644 --- a/src/com/itmill/toolkit/ui/Upload.java +++ b/src/com/itmill/toolkit/ui/Upload.java @@ -105,6 +105,14 @@ public class Upload extends AbstractComponent implements Component.Focusable { return "upload"; } + /** + * This method is called by terminal when upload is received. + * + * Note, this method is called outside synchronized (Application) block, so + * overriding this may be dangerous. + * + * @param upload + */ public void receiveUpload(UploadStream upload) { if (!isUploading) { throw new IllegalStateException("uploading not started"); @@ -114,13 +122,19 @@ public class Upload extends AbstractComponent implements Component.Focusable { final String filename = upload.getContentName(); final String type = upload.getContentType(); - fireStarted(filename, type); + final Application application = getApplication(); + + synchronized (application) { + fireStarted(filename, type); + } // Gets the output target stream final OutputStream out = receiver.receiveUpload(filename, type); if (out == null) { - fireNoOutputStream(filename, type, 0); - endUpload(); + synchronized (application) { + fireNoOutputStream(filename, type, 0); + endUpload(); + } return; } @@ -128,8 +142,10 @@ public class Upload extends AbstractComponent implements Component.Focusable { if (null == in) { // No file, for instance non-existent filename in html upload - fireNoInputStream(filename, type, 0); - endUpload(); + synchronized (application) { + fireNoInputStream(filename, type, 0); + endUpload(); + } return; } @@ -143,21 +159,27 @@ public class Upload extends AbstractComponent implements Component.Focusable { if (progressListener != null && contentLength > 0) { // update progress if listener set and contentLength // received - progressListener.updateProgress(totalBytes, contentLength); + synchronized (application) { + progressListener.updateProgress(totalBytes, + contentLength); + } } } // upload successful out.close(); - fireUploadSuccess(filename, type, totalBytes); - endUpload(); - requestRepaint(); + synchronized (application) { + fireUploadSuccess(filename, type, totalBytes); + endUpload(); + requestRepaint(); + } } catch (final Exception e) { - - // Download interrupted - fireUploadInterrupted(filename, type, totalBytes, e); - endUpload(); + synchronized (application) { + // Download interrupted + fireUploadInterrupted(filename, type, totalBytes, e); + endUpload(); + } } } |