summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-05-28 15:39:02 +0300
committerLeif Åstrand <leif@vaadin.com>2013-05-28 15:39:02 +0300
commitd34583895c884767537ad866de942d23c044af52 (patch)
tree5d3e693f3b0dfb2b12c7e337518e795f3d5bd7af /server
parent2b5ba963af81bb8a21f51ab29bd47ecd0054daa6 (diff)
downloadvaadin-framework-d34583895c884767537ad866de942d23c044af52.tar.gz
vaadin-framework-d34583895c884767537ad866de942d23c044af52.zip
Remove ThreadLocal references from CurrentInstance (#11914)
Change-Id: Ic7389a06726026383b96de80b0d038ed11e9d273
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/ConnectorResourceHandler.java6
-rw-r--r--server/src/com/vaadin/server/GlobalResourceHandler.java8
-rw-r--r--server/src/com/vaadin/server/VaadinSession.java11
-rw-r--r--server/src/com/vaadin/ui/UI.java4
-rw-r--r--server/src/com/vaadin/util/CurrentInstance.java34
5 files changed, 36 insertions, 27 deletions
diff --git a/server/src/com/vaadin/server/ConnectorResourceHandler.java b/server/src/com/vaadin/server/ConnectorResourceHandler.java
index 00d82988d3..3f3f41a179 100644
--- a/server/src/com/vaadin/server/ConnectorResourceHandler.java
+++ b/server/src/com/vaadin/server/ConnectorResourceHandler.java
@@ -77,8 +77,8 @@ public class ConnectorResourceHandler implements RequestHandler {
session.unlock();
}
- Map<Class<?>, CurrentInstance> oldThreadLocals = CurrentInstance
- .setThreadLocals(ui);
+ Map<Class<?>, CurrentInstance> oldInstances = CurrentInstance
+ .setCurrent(ui);
try {
if (!connector.handleConnectorRequest(request, response, key)) {
return error(request, response, connector.getClass()
@@ -88,7 +88,7 @@ public class ConnectorResourceHandler implements RequestHandler {
+ ") did not handle connector request for " + key);
}
} finally {
- CurrentInstance.restoreThreadLocals(oldThreadLocals);
+ CurrentInstance.restoreInstances(oldInstances);
}
return true;
diff --git a/server/src/com/vaadin/server/GlobalResourceHandler.java b/server/src/com/vaadin/server/GlobalResourceHandler.java
index d411b286d0..4235d85024 100644
--- a/server/src/com/vaadin/server/GlobalResourceHandler.java
+++ b/server/src/com/vaadin/server/GlobalResourceHandler.java
@@ -87,14 +87,14 @@ public class GlobalResourceHandler implements RequestHandler {
+ " is not a valid global resource path");
}
session.lock();
- Map<Class<?>, CurrentInstance> oldThreadLocals = null;
+ Map<Class<?>, CurrentInstance> oldInstances = null;
DownloadStream stream = null;
try {
UI ui = session.getUIById(Integer.parseInt(uiid));
if (ui == null) {
return error(request, response, "No UI found for id " + uiid);
}
- oldThreadLocals = CurrentInstance.setThreadLocals(ui);
+ oldInstances = CurrentInstance.setCurrent(ui);
ConnectorResource resource;
if (LEGACY_TYPE.equals(type)) {
resource = legacyResources.get(key);
@@ -115,8 +115,8 @@ public class GlobalResourceHandler implements RequestHandler {
}
} finally {
session.unlock();
- if (oldThreadLocals != null) {
- CurrentInstance.restoreThreadLocals(oldThreadLocals);
+ if (oldInstances != null) {
+ CurrentInstance.restoreInstances(oldInstances);
}
}
diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java
index eaf611caad..9939ad709e 100644
--- a/server/src/com/vaadin/server/VaadinSession.java
+++ b/server/src/com/vaadin/server/VaadinSession.java
@@ -1153,15 +1153,15 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
Map<Class<?>, CurrentInstance> old = null;
lock();
try {
- old = CurrentInstance.setThreadLocals(this);
+ old = CurrentInstance.setCurrent(this);
runnable.run();
} finally {
unlock();
if (old != null) {
- CurrentInstance.restoreThreadLocals(old);
+ CurrentInstance.restoreInstances(old);
}
}
-
+
}
/**
@@ -1262,14 +1262,13 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
while ((pendingAccess = pendingAccessQueue.poll()) != null) {
if (!pendingAccess.isCancelled()) {
CurrentInstance.clearAll();
- CurrentInstance
- .restoreThreadLocals(pendingAccess.instances);
+ CurrentInstance.restoreInstances(pendingAccess.instances);
accessSynchronously(pendingAccess);
}
}
} finally {
CurrentInstance.clearAll();
- CurrentInstance.restoreThreadLocals(oldInstances);
+ CurrentInstance.restoreInstances(oldInstances);
}
}
diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java
index 0b21112c97..508564ac0f 100644
--- a/server/src/com/vaadin/ui/UI.java
+++ b/server/src/com/vaadin/ui/UI.java
@@ -1157,12 +1157,12 @@ public abstract class UI extends AbstractSingleComponentContainer implements
// acquired the lock.
throw new UIDetachedException();
}
- old = CurrentInstance.setThreadLocals(this);
+ old = CurrentInstance.setCurrent(this);
runnable.run();
} finally {
session.unlock();
if (old != null) {
- CurrentInstance.restoreThreadLocals(old);
+ CurrentInstance.restoreInstances(old);
}
}
diff --git a/server/src/com/vaadin/util/CurrentInstance.java b/server/src/com/vaadin/util/CurrentInstance.java
index 8e6ef8266e..b97bab3d8a 100644
--- a/server/src/com/vaadin/util/CurrentInstance.java
+++ b/server/src/com/vaadin/util/CurrentInstance.java
@@ -174,13 +174,15 @@ public class CurrentInstance implements Serializable {
}
/**
- * Restores the given thread locals to the given values. Note that this
- * should only be used internally to restore Vaadin classes.
+ * Restores the given instances to the given values. Note that this should
+ * only be used internally to restore Vaadin classes.
+ *
+ * @since 7.1
*
* @param old
- * A Class -> Object map to set as thread locals
+ * A Class -> CurrentInstance map to set as current instances
*/
- public static void restoreThreadLocals(Map<Class<?>, CurrentInstance> old) {
+ public static void restoreInstances(Map<Class<?>, CurrentInstance> old) {
for (Class c : old.keySet()) {
CurrentInstance ci = old.get(c);
set(c, ci.instance, ci.inheritable);
@@ -189,7 +191,7 @@ public class CurrentInstance implements Serializable {
/**
* Gets the currently set instances so that they can later be restored using
- * {@link #restoreThreadLocals(Map)}.
+ * {@link #restoreInstances(Map)}.
*
* @since 7.1
*
@@ -216,30 +218,38 @@ public class CurrentInstance implements Serializable {
}
/**
- * Sets thread locals for the UI and all related classes
+ * Sets current instances for the UI and all related classes. The previously
+ * defined values can be restored by passing the returned map to
+ * {@link #restoreInstances(Map)}.
+ *
+ * @since 7.1
*
* @param ui
* The UI
- * @return A map containing the old values of the thread locals this method
+ * @return A map containing the old values of the instances that this method
* updated.
*/
- public static Map<Class<?>, CurrentInstance> setThreadLocals(UI ui) {
+ public static Map<Class<?>, CurrentInstance> setCurrent(UI ui) {
Map<Class<?>, CurrentInstance> old = new HashMap<Class<?>, CurrentInstance>();
old.put(UI.class, new CurrentInstance(UI.getCurrent(), true));
UI.setCurrent(ui);
- old.putAll(setThreadLocals(ui.getSession()));
+ old.putAll(setCurrent(ui.getSession()));
return old;
}
/**
- * Sets thread locals for the {@link VaadinSession} and all related classes
+ * Sets current instances for the {@link VaadinSession} and all related
+ * classes. The previously defined values can be restored by passing the
+ * returned map to {@link #restoreInstances(Map)}.
+ *
+ * @since 7.1
*
* @param session
* The VaadinSession
- * @return A map containing the old values of the thread locals this method
+ * @return A map containing the old values of the instances this method
* updated.
*/
- public static Map<Class<?>, CurrentInstance> setThreadLocals(
+ public static Map<Class<?>, CurrentInstance> setCurrent(
VaadinSession session) {
Map<Class<?>, CurrentInstance> old = new HashMap<Class<?>, CurrentInstance>();
old.put(VaadinSession.class,