diff options
author | Artur Signell <artur@vaadin.com> | 2013-03-22 17:55:15 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-04-02 10:47:49 +0300 |
commit | 507a520f0c042e2593eac196b7a1daa9de814bed (patch) | |
tree | 99b0766477e31a9c9087de3246b00a9b1d1665c6 /server/src/com/vaadin/ui/AbstractMedia.java | |
parent | d4fcfdf7aa21899e8a621d48b8c1bb75fbd46c62 (diff) | |
download | vaadin-framework-507a520f0c042e2593eac196b7a1daa9de814bed.tar.gz vaadin-framework-507a520f0c042e2593eac196b7a1daa9de814bed.zip |
Fixed locking in RequestHandlers and documented that RequestHandlers are called without locking (#9945)
* Added SynchronizedRequestHandler which locks the session for the whole request
* Made request handlers which do not do do heavy IO implement SynchronizedRequestHandler
* Fixed locking for GlobalResourceHandler, ConnectorResourceHandler, PublishedFileHandler
Change-Id: I0e7b442a9392828f1930685f194dc4f898d0f525
Diffstat (limited to 'server/src/com/vaadin/ui/AbstractMedia.java')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractMedia.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/server/src/com/vaadin/ui/AbstractMedia.java b/server/src/com/vaadin/ui/AbstractMedia.java index 41677467bb..97947b568d 100644 --- a/server/src/com/vaadin/ui/AbstractMedia.java +++ b/server/src/com/vaadin/ui/AbstractMedia.java @@ -25,6 +25,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.vaadin.server.ConnectorResource; +import com.vaadin.server.DownloadStream; import com.vaadin.server.Resource; import com.vaadin.server.ResourceReference; import com.vaadin.server.VaadinRequest; @@ -83,7 +84,14 @@ public abstract class AbstractMedia extends AbstractComponent { public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { Matcher matcher = Pattern.compile("(\\d+)(/.*)?").matcher(path); - if (matcher.matches()) { + if (!matcher.matches()) { + return super.handleConnectorRequest(request, response, path); + } + + DownloadStream stream; + + getSession().lock(); + try { List<URLReference> sources = getState().sources; int sourceIndex = Integer.parseInt(matcher.group(1)); @@ -98,11 +106,13 @@ public abstract class AbstractMedia extends AbstractComponent { URLReference reference = sources.get(sourceIndex); ConnectorResource resource = (ConnectorResource) ResourceReference .getResource(reference); - resource.getStream().writeResponse(request, response); - return true; - } else { - return super.handleConnectorRequest(request, response, path); + stream = resource.getStream(); + } finally { + getSession().unlock(); } + + stream.writeResponse(request, response); + return true; } private Logger getLogger() { |