summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-09-27 16:02:28 +0300
committerLeif Åstrand <leif@vaadin.com>2012-09-28 14:14:13 +0300
commit01ff5a924b8fdeeda8cbd21973fc1ecd206ef043 (patch)
tree3d2492e4a284a3ff5f5b278920cd490614238f56 /server
parentea08980bf3686051b61705d3abb838b720ec8a4f (diff)
downloadvaadin-framework-01ff5a924b8fdeeda8cbd21973fc1ecd206ef043.tar.gz
vaadin-framework-01ff5a924b8fdeeda8cbd21973fc1ecd206ef043.zip
Use one VaadinSession per VaadinServlet (#9733)
Change-Id: I98639e88cc772e4370ebba836f270c44258613fa
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/AbstractCommunicationManager.java6
-rw-r--r--server/src/com/vaadin/server/BootstrapHandler.java3
-rw-r--r--server/src/com/vaadin/server/GAEVaadinServlet.java4
-rw-r--r--server/src/com/vaadin/server/LegacyVaadinPortlet.java2
-rw-r--r--server/src/com/vaadin/server/LegacyVaadinServlet.java2
-rw-r--r--server/src/com/vaadin/server/ServletPortletHelper.java6
-rw-r--r--server/src/com/vaadin/server/VaadinService.java126
-rw-r--r--server/src/com/vaadin/server/VaadinServletSession.java3
-rw-r--r--server/src/com/vaadin/server/VaadinSession.java117
9 files changed, 73 insertions, 196 deletions
diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java
index b4f7ad4207..69b664339c 100644
--- a/server/src/com/vaadin/server/AbstractCommunicationManager.java
+++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java
@@ -2460,10 +2460,10 @@ public abstract class AbstractCommunicationManager implements Serializable {
private UI getBrowserDetailsUI(VaadinRequest request) {
VaadinService vaadinService = request.getService();
- VaadinSession session = VaadinSession.getForSession(request
- .getWrappedSession());
+ VaadinSession session = VaadinSession.getForSession(vaadinService,
+ request.getWrappedSession());
- List<UIProvider> uiProviders = vaadinService.getUIProviders(session);
+ List<UIProvider> uiProviders = session.getUIProviders();
UIClassSelectionEvent classSelectionEvent = new UIClassSelectionEvent(
request);
diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java
index a6c72b9885..25d0f9ed52 100644
--- a/server/src/com/vaadin/server/BootstrapHandler.java
+++ b/server/src/com/vaadin/server/BootstrapHandler.java
@@ -116,8 +116,7 @@ public abstract class BootstrapHandler implements RequestHandler {
VaadinResponse response) throws IOException {
try {
- List<UIProvider> uiProviders = request.getService().getUIProviders(
- session);
+ List<UIProvider> uiProviders = session.getUIProviders();
UIClassSelectionEvent classSelectionEvent = new UIClassSelectionEvent(
request);
diff --git a/server/src/com/vaadin/server/GAEVaadinServlet.java b/server/src/com/vaadin/server/GAEVaadinServlet.java
index 6ef107eabe..6c46b0d70b 100644
--- a/server/src/com/vaadin/server/GAEVaadinServlet.java
+++ b/server/src/com/vaadin/server/GAEVaadinServlet.java
@@ -321,8 +321,8 @@ public class GAEVaadinServlet extends VaadinServlet {
ois = new ObjectInputStream(bais);
VaadinSession applicationContext = (VaadinSession) ois
.readObject();
- applicationContext.storeInSession(new WrappedHttpSession(
- session));
+ applicationContext.storeInSession(getService(),
+ new WrappedHttpSession(session));
} catch (IOException e) {
getLogger().log(
Level.WARNING,
diff --git a/server/src/com/vaadin/server/LegacyVaadinPortlet.java b/server/src/com/vaadin/server/LegacyVaadinPortlet.java
index a49bea29c4..0c6f7afd93 100644
--- a/server/src/com/vaadin/server/LegacyVaadinPortlet.java
+++ b/server/src/com/vaadin/server/LegacyVaadinPortlet.java
@@ -84,7 +84,7 @@ public class LegacyVaadinPortlet extends VaadinPortlet {
private void onVaadinSessionStarted(VaadinPortletRequest request,
VaadinPortletSession session) throws PortletException {
- getService().addUIProvider(session, provider);
+ session.addUIProvider(provider);
}
protected boolean shouldCreateApplication(PortletRequest request) {
diff --git a/server/src/com/vaadin/server/LegacyVaadinServlet.java b/server/src/com/vaadin/server/LegacyVaadinServlet.java
index 6e6bd17bbb..bb71889f51 100644
--- a/server/src/com/vaadin/server/LegacyVaadinServlet.java
+++ b/server/src/com/vaadin/server/LegacyVaadinServlet.java
@@ -89,7 +89,7 @@ public class LegacyVaadinServlet extends VaadinServlet {
private void onVaadinSessionStarted(VaadinRequest request,
VaadinSession session) throws ServletException {
- getService().addUIProvider(session, provider);
+ session.addUIProvider(provider);
}
}
diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java
index f408fffdb1..91748080ff 100644
--- a/server/src/com/vaadin/server/ServletPortletHelper.java
+++ b/server/src/com/vaadin/server/ServletPortletHelper.java
@@ -127,7 +127,7 @@ class ServletPortletHelper implements Serializable {
// (providers are FILO)
if (uiProperty != null) {
verifyUIClass(uiProperty, vaadinService.getClassLoader());
- vaadinService.addUIProvider(session, new DefaultUIProvider());
+ session.addUIProvider(new DefaultUIProvider());
}
String uiProviderProperty = vaadinService.getDeploymentConfiguration()
@@ -137,7 +137,7 @@ class ServletPortletHelper implements Serializable {
if (uiProviderProperty != null) {
UIProvider uiProvider = getUIProvider(uiProviderProperty,
vaadinService.getClassLoader());
- vaadinService.addUIProvider(session, uiProvider);
+ session.addUIProvider(uiProvider);
}
}
@@ -165,7 +165,7 @@ class ServletPortletHelper implements Serializable {
public static void checkUiProviders(VaadinSession session,
VaadinService vaadinService) throws ServiceException {
- if (vaadinService.getUIProviders(session).isEmpty()) {
+ if (session.getUIProviders().isEmpty()) {
throw new ServiceException(
"No UIProvider has been added and there is no \""
+ VaadinSession.UI_PARAMETER + "\" init parameter.");
diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java
index b99d4d2e55..b960409030 100644
--- a/server/src/com/vaadin/server/VaadinService.java
+++ b/server/src/com/vaadin/server/VaadinService.java
@@ -23,10 +23,7 @@ import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Locale;
import java.util.ServiceLoader;
@@ -52,70 +49,6 @@ import com.vaadin.util.ReflectTools;
* @since 7.0
*/
public abstract class VaadinService implements Serializable {
-
- /**
- * Service specific data that is stored in VaadinSession separately for each
- * VaadinService using that particular session.
- *
- * @author Vaadin Ltd
- */
- public static class VaadinServiceData implements Serializable {
- private final VaadinService vaadinService;
- private LinkedList<UIProvider> uiProviders = new LinkedList<UIProvider>();
-
- /**
- * Create a new service data object for the given Vaadin service
- *
- * @param vaadinService
- * the Vaadin service to which the data belongs
- */
- public VaadinServiceData(VaadinService vaadinService) {
- this.vaadinService = vaadinService;
- }
-
- /**
- * Gets a list of all the UI providers registered for a particular
- * Vaadin service
- *
- * @see #addUIProvider(UIProvider)
- *
- * @return and unmodifiable list of UI providers
- */
- public List<UIProvider> getUIProviders() {
- return Collections.unmodifiableList(uiProviders);
- }
-
- /**
- * Adds a UI provider for a Vaadin service.
- *
- * @param uiProvider
- * the UI provider to add
- */
- public void addUIProvider(UIProvider uiProvider) {
- uiProviders.addFirst(uiProvider);
- }
-
- /**
- * Removes a UI provider from a Vaadin service.
- *
- * @param uiProvider
- * the UI provider to remove
- */
- public void removeUIProvider(UIProvider uiProvider) {
- uiProviders.remove(uiProvider);
- }
-
- /**
- * Gets the Vaadin service that this data belongs to.
- *
- * @return the Vaadin service that htis data belongs to
- */
- public VaadinService getService() {
- return vaadinService;
- }
-
- }
-
private static final Method SESSION_INIT_METHOD = ReflectTools.findMethod(
SessionInitListener.class, "sessionInit", SessionInitEvent.class);
@@ -375,13 +308,6 @@ public abstract class VaadinService implements Serializable {
if (vaadinSession == null) {
return null;
}
- if (!vaadinSession.hasVaadinServiceData(this)) {
- vaadinSession.addVaadinServiceData(new VaadinServiceData(this));
-
- ServletPortletHelper.initDefaultUIProvider(vaadinSession, this);
-
- onVaadinSessionStarted(request, vaadinSession);
- }
VaadinSession.setCurrent(vaadinSession);
request.setAttribute(VaadinSession.class.getName(), vaadinSession);
@@ -441,7 +367,7 @@ public abstract class VaadinService implements Serializable {
throws ServiceException {
VaadinSession session = createVaadinSession(request);
- session.storeInSession(request.getWrappedSession());
+ session.storeInSession(this, request.getWrappedSession());
URL applicationUrl;
try {
@@ -457,6 +383,9 @@ public abstract class VaadinService implements Serializable {
getDeploymentConfiguration(),
createCommunicationManager(session)));
+ ServletPortletHelper.initDefaultUIProvider(session, this);
+ onVaadinSessionStarted(request, session);
+
return session;
}
@@ -514,7 +443,7 @@ public abstract class VaadinService implements Serializable {
}
if (session != null) {
- vaadinSession.removeFromSession();
+ vaadinSession.removeFromSession(this);
}
}
@@ -528,7 +457,8 @@ public abstract class VaadinService implements Serializable {
throw new SessionExpiredException();
}
- VaadinSession vaadinSession = VaadinSession.getForSession(session);
+ VaadinSession vaadinSession = VaadinSession
+ .getForSession(this, session);
if (vaadinSession == null) {
return null;
@@ -636,18 +566,6 @@ public abstract class VaadinService implements Serializable {
public abstract String getServiceName();
/**
- * Gets all the UI providers from a session that are configured for this
- * service.
- *
- * @param session
- * the Vaadin session to get the UI providers from
- * @return an unmodifiable list of UI providers
- */
- public List<UIProvider> getUIProviders(VaadinSession session) {
- return session.getServiceData(this).getUIProviders();
- }
-
- /**
* Finds the {@link UI} that belongs to the provided request. This is
* generally only supported for UIDL requests as other request types are not
* related to any particular UI or have the UI information encoded in a
@@ -660,8 +578,8 @@ public abstract class VaadinService implements Serializable {
*
*/
public UI findUI(VaadinRequest request) {
- VaadinSession session = VaadinSession.getForSession(request
- .getWrappedSession());
+ VaadinSession session = VaadinSession.getForSession(this,
+ request.getWrappedSession());
// Get UI id from the request
String uiIdString = request.getParameter(UIConstants.UI_ID_PARAMETER);
@@ -680,32 +598,6 @@ public abstract class VaadinService implements Serializable {
}
/**
- * Adds a UI provider to a Vaadin session and associates it with this Vaadin
- * service.
- *
- * @param vaadinSession
- * the Vaadin session to store the UI provider in
- * @param uiProvider
- * the UI provider that should be added
- */
- public void addUIProvider(VaadinSession vaadinSession, UIProvider uiProvider) {
- vaadinSession.getServiceData(this).addUIProvider(uiProvider);
- }
-
- /**
- * Removes a UI provider association for this service from a Vaadin session.
- *
- * @param vaadinSession
- * the Vaadin session where the UI provider is stored
- * @param uiProvider
- * the UI provider that should be removed
- */
- public void removeUIProvider(VaadinSession vaadinSession,
- UIProvider uiProvider) {
- vaadinSession.getServiceData(this).removeUIProvider(uiProvider);
- }
-
- /**
* Check if the given UI should be associated with the
* <code>window.name</code> so that it can be re-used if the browser window
* is reloaded. This is typically determined by the UI provider which
diff --git a/server/src/com/vaadin/server/VaadinServletSession.java b/server/src/com/vaadin/server/VaadinServletSession.java
index 6d2658f8b8..365b1bc46d 100644
--- a/server/src/com/vaadin/server/VaadinServletSession.java
+++ b/server/src/com/vaadin/server/VaadinServletSession.java
@@ -91,7 +91,8 @@ public class VaadinServletSession extends VaadinSession {
}
// Update the "current session" variable
- storeInSession(new WrappedHttpSession(newSession));
+ storeInSession(VaadinService.getCurrent(), new WrappedHttpSession(
+ newSession));
}
/**
diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java
index febdc5dad5..7c23e6474f 100644
--- a/server/src/com/vaadin/server/VaadinSession.java
+++ b/server/src/com/vaadin/server/VaadinSession.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.EventObject;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.locks.Lock;
@@ -42,7 +43,6 @@ import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.ConverterFactory;
import com.vaadin.data.util.converter.DefaultConverterFactory;
import com.vaadin.event.EventRouter;
-import com.vaadin.server.VaadinService.VaadinServiceData;
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.Table;
import com.vaadin.ui.UI;
@@ -193,7 +193,9 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
private final Map<String, Object> attributes = new HashMap<String, Object>();
- private Map<String, VaadinServiceData> serviceData = new HashMap<String, VaadinServiceData>();
+ private LinkedList<UIProvider> uiProviders = new LinkedList<UIProvider>();
+
+ private VaadinService service;
/**
* @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
@@ -210,10 +212,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
public void valueUnbound(HttpSessionBindingEvent event) {
// If we are going to be unbound from the session, the session must be
// closing
- // Notify all services that have used this session.
- for (VaadinServiceData vaadinServiceData : serviceData.values()) {
- vaadinServiceData.getService().fireSessionDestroy(this);
- }
+ // Notify the service
+ service.fireSessionDestroy(this);
}
/**
@@ -294,15 +294,18 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
}
/**
+ * @param service
+ * TODO
* @param underlyingSession
* @return
*
* @deprecated might be refactored or removed before 7.0.0
*/
@Deprecated
- public static VaadinSession getForSession(WrappedSession underlyingSession) {
+ public static VaadinSession getForSession(VaadinService service,
+ WrappedSession underlyingSession) {
Object attribute = underlyingSession.getAttribute(VaadinSession.class
- .getName());
+ .getName() + "." + service.getServiceName());
if (attribute instanceof VaadinSession) {
VaadinSession vaadinSession = (VaadinSession) attribute;
vaadinSession.session = underlyingSession;
@@ -314,13 +317,17 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
/**
*
+ * @param service
+ * TODO
* @deprecated might be refactored or removed before 7.0.0
*/
@Deprecated
- public void removeFromSession() {
- assert (getForSession(session) == this);
+ public void removeFromSession(VaadinService service) {
+ assert (getForSession(service, session) == this);
- session.setAttribute(VaadinSession.class.getName(), null);
+ session.setAttribute(
+ VaadinSession.class.getName() + "." + service.getServiceName(),
+ null);
}
/**
@@ -329,8 +336,10 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
* @deprecated might be refactored or removed before 7.0.0
*/
@Deprecated
- public void storeInSession(WrappedSession session) {
- session.setAttribute(VaadinSession.class.getName(), this);
+ public void storeInSession(VaadinService service, WrappedSession session) {
+ session.setAttribute(
+ VaadinSession.class.getName() + "." + service.getServiceName(),
+ this);
this.session = session;
}
@@ -1045,59 +1054,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
}
/**
- * Checks whether there this session has any Vaadin service data for a
- * particular Vaadin service.
- *
- * @see #addVaadinServiceData(VaadinServiceData)
- * @see VaadinServiceData
- *
- * @param vaadinService
- * the Vaadin service to check for
- * @return <code>true</code> if there is a Vaadin service data object for
- * the passed Vaadin service; otherwise <code>false</code>
- */
- public boolean hasVaadinServiceData(VaadinService vaadinService) {
- return getServiceData(vaadinService) != null;
- }
-
- /**
- * Gets the data stored for the passed Vaadin service.
- *
- * @see #addVaadinServiceData(VaadinServiceData)
- * @see VaadinServiceData
- *
- * @param vaadinService
- * the Vaadin service to get the data for
- * @return the Vaadin service data for the provided Vaadin service; or
- * <code>null</code> if there is no data for the service
- */
- public VaadinServiceData getServiceData(VaadinService vaadinService) {
- return serviceData.get(getServiceKey(vaadinService));
- }
-
- /**
- * Adds Vaadin service specific data to this session.
- *
- * @see #getServiceData(VaadinService)
- * @see VaadinServiceData
- *
- * @param serviceData
- * the Vaadin service data to add
- */
- public void addVaadinServiceData(VaadinServiceData serviceData) {
- VaadinService vaadinService = serviceData.getService();
- assert !hasVaadinServiceData(vaadinService);
-
- this.serviceData.put(getServiceKey(vaadinService), serviceData);
- }
-
- private static String getServiceKey(VaadinService vaadinService) {
- String serviceKey = vaadinService.getClass().getName() + "."
- + vaadinService.getServiceName();
- return serviceKey;
- }
-
- /**
* Creates a new unique id for a UI.
*
* @return a unique UI id
@@ -1138,4 +1094,33 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
uIs.put(Integer.valueOf(ui.getUIId()), ui);
}
+ /**
+ * Adds a UI provider to this session.
+ *
+ * @param uiProvider
+ * the UI provider that should be added
+ */
+ public void addUIProvider(UIProvider uiProvider) {
+ uiProviders.addFirst(uiProvider);
+ }
+
+ /**
+ * Removes a UI provider association from this session.
+ *
+ * @param uiProvider
+ * the UI provider that should be removed
+ */
+ public void removeUIProvider(UIProvider uiProvider) {
+ uiProviders.remove(uiProvider);
+ }
+
+ /**
+ * Gets the UI providers configured for this session.
+ *
+ * @return an unmodifiable list of UI providers
+ */
+ public List<UIProvider> getUIProviders() {
+ return Collections.unmodifiableList(uiProviders);
+ }
+
}