From: Matti Tahvonen Date: Fri, 7 Mar 2008 14:15:17 +0000 (+0000) Subject: Documentation and making upload events more thread safe X-Git-Tag: 6.7.0.beta1~4960 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1262a4bbedd3112e9af77c43f520e0527eef9b7b;p=vaadin-framework.git Documentation and making upload events more thread safe svn changeset:4005/svn branch:trunk --- 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(); + } } }