summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-07 14:57:53 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-07 14:59:13 +0300
commit9f6bceab2861e4d5a8bccca6c2283804def6477c (patch)
treec5857443996b2211f11d95eb1ae3f98bd70f30f4 /server
parente954dec24903ec259aa4ef1d1d88555dfb8d3ac4 (diff)
downloadvaadin-framework-9f6bceab2861e4d5a8bccca6c2283804def6477c.tar.gz
vaadin-framework-9f6bceab2861e4d5a8bccca6c2283804def6477c.zip
Use dedicated Lock for session synchronization (#9156)
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/AbstractCommunicationManager.java40
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java5
-rw-r--r--server/src/com/vaadin/server/VaadinSession.java22
3 files changed, 55 insertions, 12 deletions
diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java
index 00d508de4c..c2a5377e12 100644
--- a/server/src/com/vaadin/server/AbstractCommunicationManager.java
+++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java
@@ -300,9 +300,12 @@ public abstract class AbstractCommunicationManager implements Serializable {
cleanStreamVariable(owner, variableName);
}
} catch (Exception e) {
- synchronized (session) {
+ session.getLock().lock();
+ try {
handleChangeVariablesError(session, (Component) owner, e,
new HashMap<String, Object>());
+ } finally {
+ session.getLock().unlock();
}
}
sendUploadResponse(request, response);
@@ -345,9 +348,12 @@ public abstract class AbstractCommunicationManager implements Serializable {
cleanStreamVariable(owner, variableName);
}
} catch (Exception e) {
- synchronized (session) {
+ session.getLock().lock();
+ try {
handleChangeVariablesError(session, (Component) owner, e,
new HashMap<String, Object>());
+ } finally {
+ session.getLock().unlock();
}
}
sendUploadResponse(request, response);
@@ -379,10 +385,13 @@ public abstract class AbstractCommunicationManager implements Serializable {
filename, type, contentLength);
try {
boolean listenProgress;
- synchronized (session) {
+ session.getLock().lock();
+ try {
streamVariable.streamingStarted(startedEvent);
out = streamVariable.getOutputStream();
listenProgress = streamVariable.listenProgress();
+ } finally {
+ session.getLock().unlock();
}
// Gets the output target stream
@@ -403,10 +412,13 @@ public abstract class AbstractCommunicationManager implements Serializable {
if (listenProgress) {
// update progress if listener set and contentLength
// received
- synchronized (session) {
+ session.getLock().lock();
+ try {
StreamingProgressEventImpl progressEvent = new StreamingProgressEventImpl(
filename, type, contentLength, totalBytes);
streamVariable.onProgress(progressEvent);
+ } finally {
+ session.getLock().unlock();
}
}
if (streamVariable.isInterrupted()) {
@@ -418,8 +430,11 @@ public abstract class AbstractCommunicationManager implements Serializable {
out.close();
StreamingEndEvent event = new StreamingEndEventImpl(filename, type,
totalBytes);
- synchronized (session) {
+ session.getLock().lock();
+ try {
streamVariable.streamingFinished(event);
+ } finally {
+ session.getLock().unlock();
}
} catch (UploadInterruptedException e) {
@@ -427,20 +442,26 @@ public abstract class AbstractCommunicationManager implements Serializable {
tryToCloseStream(out);
StreamingErrorEvent event = new StreamingErrorEventImpl(filename,
type, contentLength, totalBytes, e);
- synchronized (session) {
+ session.getLock().lock();
+ try {
streamVariable.streamingFailed(event);
+ } finally {
+ session.getLock().unlock();
}
// Note, we are not throwing interrupted exception forward as it is
// not a terminal level error like all other exception.
} catch (final Exception e) {
tryToCloseStream(out);
- synchronized (session) {
+ session.getLock().lock();
+ try {
StreamingErrorEvent event = new StreamingErrorEventImpl(
filename, type, contentLength, totalBytes, e);
streamVariable.streamingFailed(event);
// throw exception for terminal to be handled (to be passed to
// terminalErrorHandler)
throw new UploadException(e);
+ } finally {
+ session.getLock().unlock();
}
}
return startedEvent.isDisposed();
@@ -551,7 +572,8 @@ public abstract class AbstractCommunicationManager implements Serializable {
// The rest of the process is synchronized with the session
// in order to guarantee that no parallel variable handling is
// made
- synchronized (session) {
+ session.getLock().lock();
+ try {
// Finds the UI within the session
if (session.isRunning()) {
@@ -592,6 +614,8 @@ public abstract class AbstractCommunicationManager implements Serializable {
paintAfterVariableChanges(request, response, callback, repaintAll,
outWriter, uI, analyzeLayouts);
postPaint(uI);
+ } finally {
+ session.getLock().unlock();
}
outWriter.close();
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index 45a952d48d..026873a04d 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -529,7 +529,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
// Finds the window within the application
UI uI = null;
- synchronized (application) {
+ application.getLock().lock();
+ try {
if (application.isRunning()) {
switch (requestType) {
case RENDER:
@@ -555,6 +556,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
}
// if window not found, not a problem - use null
}
+ } finally {
+ application.getLock().unlock();
}
// TODO Should this happen before or after the transaction
diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java
index f0e3ec4895..c6b2d91f29 100644
--- a/server/src/com/vaadin/server/VaadinSession.java
+++ b/server/src/com/vaadin/server/VaadinSession.java
@@ -28,6 +28,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.portlet.PortletSession;
@@ -76,6 +78,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
.findMethod(BootstrapListener.class, "modifyBootstrapPage",
BootstrapPageResponse.class);
+ private final Lock lock = new ReentrantLock();
+
/**
* An event sent to {@link #start(SessionStartEvent)} when a new Application
* is being started.
@@ -929,15 +933,17 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
return uI;
}
Integer uiId = getUIId(request);
-
- synchronized (this) {
+ getLock().lock();
+ try {
uI = uIs.get(uiId);
if (uI == null) {
uI = findExistingUi(request);
}
- } // end synchronized block
+ } finally {
+ getLock().unlock();
+ }
UI.setCurrent(uI);
@@ -1290,4 +1296,14 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
return Collections.unmodifiableCollection(uiProviders);
}
+ /**
+ * Gets the lock that should be used to synchronize usage of data inside
+ * this session.
+ *
+ * @return the lock that should be used for synchronization
+ */
+ public Lock getLock() {
+ return lock;
+ }
+
}