]> source.dussan.org Git - vaadin-framework.git/commitdiff
Remove ThreadLocal references from CurrentInstance (#11914)
authorLeif Åstrand <leif@vaadin.com>
Tue, 28 May 2013 12:39:02 +0000 (15:39 +0300)
committerLeif Åstrand <leif@vaadin.com>
Tue, 28 May 2013 12:39:02 +0000 (15:39 +0300)
Change-Id: Ic7389a06726026383b96de80b0d038ed11e9d273

server/src/com/vaadin/server/ConnectorResourceHandler.java
server/src/com/vaadin/server/GlobalResourceHandler.java
server/src/com/vaadin/server/VaadinSession.java
server/src/com/vaadin/ui/UI.java
server/src/com/vaadin/util/CurrentInstance.java

index 00d82988d34bd799d52b69eb6892205876f1d44b..3f3f41a179af4e538295bec02a2c18d289b3cf50 100644 (file)
@@ -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;
index d411b286d0f2ce3e327b9319c7c722f4f526a406..4235d850249520159638f6b204e352dbf33a3c67 100644 (file)
@@ -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);
             }
         }
 
index eaf611caad6c8134bbc3c525b513e38f8f5f8893..9939ad709e18591d5f8365c2ae6b09cbd1d11029 100644 (file)
@@ -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);
         }
     }
 
index 0b21112c97563de0b50f983a6cdbfaff21f19800..508564ac0f87dc53199630f044c5e1f7812c1556 100644 (file)
@@ -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);
             }
         }
 
index 8e6ef8266e146a439ee4fb234101e7df67284bb5..b97bab3d8a18b27c0efaa3619d6ba2dfa320edea 100644 (file)
@@ -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,