summaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2019-11-12 09:30:15 +0200
committerLeif Åstrand <leif@vaadin.com>2019-11-12 09:30:15 +0200
commitdc35fdec074e14a09b8efb82ce1068338bac155d (patch)
treef6353ee04ebe97e6773582ab738c4d72fd3a8439 /server/src/main
parentfd1a8df74a6ddba0c2ff2862ee02f58deebdf6e1 (diff)
downloadvaadin-framework-dc35fdec074e14a09b8efb82ce1068338bac155d.tar.gz
vaadin-framework-dc35fdec074e14a09b8efb82ce1068338bac155d.zip
Use APPLICATION_SCOPE for the session lock (#11792)
The Vaadin session itself is also stored in APPLICATION_SCOPE. The default scope is PORTLET_SCOPE, so lock would be otherwise not be in sync with the session. To be able to do this, relevant methods in VaadinService are made protected so that VaadinPortletService can override them. Fixes #11611
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/server/VaadinPortletService.java38
-rw-r--r--server/src/main/java/com/vaadin/server/VaadinService.java4
2 files changed, 40 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/server/VaadinPortletService.java b/server/src/main/java/com/vaadin/server/VaadinPortletService.java
index 1b804ad18c..0b2d28acc6 100644
--- a/server/src/main/java/com/vaadin/server/VaadinPortletService.java
+++ b/server/src/main/java/com/vaadin/server/VaadinPortletService.java
@@ -22,6 +22,8 @@ import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -366,4 +368,40 @@ public class VaadinPortletService extends VaadinService {
getWrappedPortletSession(wrappedSession).removeAttribute(
getSessionAttributeName(), PortletSession.APPLICATION_SCOPE);
}
+
+ @Override
+ protected void setSessionLock(WrappedSession wrappedSession, Lock lock) {
+ if (wrappedSession == null) {
+ throw new IllegalArgumentException(
+ "Can't set a lock for a null session");
+ }
+ Object currentSessionLock = getWrappedPortletSession(wrappedSession)
+ .getAttribute(getLockAttributeName(),
+ PortletSession.APPLICATION_SCOPE);
+ assert (currentSessionLock == null
+ || currentSessionLock == lock) : "Changing the lock for a session is not allowed";
+
+ getWrappedPortletSession(wrappedSession).setAttribute(
+ getLockAttributeName(), lock,
+ PortletSession.APPLICATION_SCOPE);
+ }
+
+ @Override
+ protected Lock getSessionLock(WrappedSession wrappedSession) {
+ Object lock = getWrappedPortletSession(wrappedSession)
+ .getAttribute(getLockAttributeName(),
+ PortletSession.APPLICATION_SCOPE);
+
+ if (lock instanceof ReentrantLock) {
+ return (ReentrantLock) lock;
+ }
+
+ if (lock == null) {
+ return null;
+ }
+
+ throw new RuntimeException(
+ "Something else than a ReentrantLock was stored in the "
+ + getLockAttributeName() + " in the session");
+ }
}
diff --git a/server/src/main/java/com/vaadin/server/VaadinService.java b/server/src/main/java/com/vaadin/server/VaadinService.java
index 1e67db708b..9503db113f 100644
--- a/server/src/main/java/com/vaadin/server/VaadinService.java
+++ b/server/src/main/java/com/vaadin/server/VaadinService.java
@@ -622,7 +622,7 @@ public abstract class VaadinService implements Serializable {
* @param lock
* The lock object
*/
- private void setSessionLock(WrappedSession wrappedSession, Lock lock) {
+ protected void setSessionLock(WrappedSession wrappedSession, Lock lock) {
if (wrappedSession == null) {
throw new IllegalArgumentException(
"Can't set a lock for a null session");
@@ -640,7 +640,7 @@ public abstract class VaadinService implements Serializable {
*
* @return The attribute name for the lock
*/
- private String getLockAttributeName() {
+ protected String getLockAttributeName() {
return getServiceName() + ".lock";
}