]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #4315 - Window name generation should be deterministic
authorArtur Signell <artur.signell@itmill.com>
Tue, 1 Jun 2010 16:18:02 +0000 (16:18 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 1 Jun 2010 16:18:02 +0000 (16:18 +0000)
svn changeset:13481/svn branch:6.4

src/com/vaadin/Application.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java

index 9a0c180a1df03468594702351318e2d9a419a3a7..61df7c9f9abfce3ab2d842e5decdc7fd2129def1 100644 (file)
@@ -17,7 +17,6 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Locale;
 import java.util.Properties;
-import java.util.Random;
 
 import com.vaadin.service.ApplicationContext;
 import com.vaadin.terminal.ApplicationResource;
@@ -92,9 +91,10 @@ public abstract class Application implements URIHandler,
         Terminal.ErrorListener, Serializable {
 
     /**
-     * Random window name generator.
+     * Id use for the next window that is opened. Access to this must be
+     * synchronized.
      */
-    private static Random nameGenerator = new Random();
+    private int nextWindowId = 1;
 
     /**
      * Application context the application is running in.
@@ -327,7 +327,11 @@ public abstract class Application implements URIHandler,
             while (!accepted) {
 
                 // Try another name
-                name = String.valueOf(Math.abs(nameGenerator.nextInt()));
+                synchronized (this) {
+                    name = String.valueOf(nextWindowId);
+                    nextWindowId++;
+                }
+
                 if (!windows.containsKey(name)) {
                     accepted = true;
                 }
index 98b95b2a7c3e41b0041346641054b81beb46987d..55f9d13fea2cd827d101e124d7d50771408f57af 100644 (file)
@@ -319,6 +319,8 @@ public abstract class AbstractCommunicationManager implements
 
     private DragAndDropService dragAndDropService;
 
+    private static int nextUnusedWindowSuffix = 1;
+
     /**
      * TODO New constructor - document me!
      * 
@@ -1543,9 +1545,12 @@ public abstract class AbstractCommunicationManager implements
         // If the requested window is already open, resolve conflict
         if (currentlyOpenWindowsInClient.containsKey(window.getName())) {
             String newWindowName = window.getName();
-            while (currentlyOpenWindowsInClient.containsKey(newWindowName)) {
-                newWindowName = window.getName() + "_"
-                        + ((int) (Math.random() * 100000000));
+
+            synchronized (AbstractCommunicationManager.class) {
+                while (currentlyOpenWindowsInClient.containsKey(newWindowName)) {
+                    newWindowName = window.getName() + "_"
+                            + nextUnusedWindowSuffix++;
+                }
             }
 
             window = application.getWindow(newWindowName);