]> source.dussan.org Git - vaadin-framework.git/commitdiff
Applications started in-order, one-at-a-time, to avoid session-id problems. Fixes...
authorMarc Englund <marc.englund@itmill.com>
Thu, 2 Oct 2008 11:52:42 +0000 (11:52 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 2 Oct 2008 11:52:42 +0000 (11:52 +0000)
svn changeset:5584/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java
src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java

index 65b77505987f8aba8f8ed9896709b6a808972cce..10738998f3f4ea987c8ede64067e79149f673a5d 100644 (file)
@@ -1,6 +1,7 @@
 package com.itmill.toolkit.terminal.gwt.client;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 
 import com.google.gwt.core.client.JavaScriptObject;
 
@@ -12,6 +13,8 @@ public class ApplicationConfiguration {
     private String appUri;
     private JavaScriptObject versionInfo;
 
+    private static ArrayList unstartedApplications = new ArrayList();
+
     public String getRootPanelId() {
         return id;
     }
@@ -59,7 +62,47 @@ public class ApplicationConfiguration {
      
      }-*/;
 
-    public native static void loadAppIdListFromDOM(ArrayList list)
+    /**
+     * Inits the ApplicationConfiguration by reading the DOM and instantiating
+     * ApplicationConenctions accordingly. Call {@link #startNextApplication()}
+     * to actually start the applications.
+     * 
+     * @param widgetset
+     *            the widgetset that is running the apps
+     */
+    public static void initConfigurations(WidgetSet widgetset) {
+        ArrayList appIds = new ArrayList();
+        loadAppIdListFromDOM(appIds);
+
+        for (Iterator it = appIds.iterator(); it.hasNext();) {
+            String appId = (String) it.next();
+            ApplicationConfiguration appConf = getConfigFromDOM(appId);
+            ApplicationConnection a = new ApplicationConnection(widgetset,
+                    appConf);
+            unstartedApplications.add(a);
+        }
+    }
+
+    /**
+     * Starts the next unstarted application. The WidgetSet should call this
+     * once to start the first application; after that, each application should
+     * call this once it has started. This ensures that the applications are
+     * started synchronously, which is neccessary to avoid session-id problems.
+     * 
+     * @return true if an unstarted application was found
+     */
+    public static boolean startNextApplication() {
+        if (unstartedApplications.size() > 0) {
+            ApplicationConnection a = (ApplicationConnection) unstartedApplications
+                    .remove(0);
+            a.start();
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private native static void loadAppIdListFromDOM(ArrayList list)
     /*-{
      
          var j;
index 76c70c36b39132722a8adc07729552eba6fb77e0..e6499e6408d5116db9475daf5cc28d399aec9e8c 100755 (executable)
@@ -149,6 +149,16 @@ public class ApplicationConnection {
         view = new IView(cnf.getRootPanelId());
         showLoadingIndicator();
 
+    }
+
+    /**
+     * Starts this application. Don't call this method directly - it's called by
+     * {@link ApplicationConfiguration#startNextApplication()}, which should be
+     * called once this application has started (first response received) or
+     * failed to start. This ensures that the applications are started in order,
+     * to avoid session-id problems.
+     */
+    void start() {
         makeUidlRequest("", true, false);
     }
 
@@ -276,6 +286,10 @@ public class ApplicationConnection {
                         // TODO Better reporting to user
                         console.error("Got error");
                         endRequest();
+                        if (!applicationRunning) {
+                            // start failed, let's try to start the next app
+                            configuration.startNextApplication();
+                        }
                     }
 
                     public void onResponseReceived(Request request,
@@ -285,6 +299,7 @@ public class ApplicationConnection {
                         } else {
                             applicationRunning = true;
                             handleWhenCSSLoaded(response);
+                            configuration.startNextApplication();
                         }
                     }
 
@@ -603,7 +618,7 @@ public class ApplicationConnection {
                 }
 
                 if (html.length() != 0) {
-                    INotification n = new INotification(1000 * 60 * 45); // 45min
+                    INotification n = new INotification(1000 * 60 * 45); //45min
                     n.addEventListener(new NotificationRedirect(url));
                     n.show(html, INotification.CENTERED_TOP,
                             INotification.STYLE_SYSTEM);
@@ -1009,11 +1024,11 @@ public class ApplicationConnection {
      * @param container
      */
     public void runDescendentsLayout(HasWidgets container) {
-//        getConsole().log(
-//                "runDescendentsLayout("
-//                        + container.getClass().getName().replaceAll(
-//                                "[^\\.]*\\.", "") + "/" + container.hashCode()
-//                        + ")");
+        // getConsole().log(
+        // "runDescendentsLayout("
+        // + container.getClass().getName().replaceAll(
+        // "[^\\.]*\\.", "") + "/" + container.hashCode()
+        // + ")");
         final Iterator childWidgets = container.iterator();
         while (childWidgets.hasNext()) {
             final Widget child = (Widget) childWidgets.next();
@@ -1048,11 +1063,11 @@ public class ApplicationConnection {
                 width *= relativeSize.getWidth() / 100.0;
 
                 if (width >= 0) {
-//                    getConsole().log(
-//                            "Widget " + widget.getClass().getName() + "/"
-//                                    + widget.hashCode() + " relative width "
-//                                    + relativeSize.getWidth() + "%: " + width
-//                                    + "px");
+                    // getConsole().log(
+                    // "Widget " + widget.getClass().getName() + "/"
+                    // + widget.hashCode() + " relative width "
+                    // + relativeSize.getWidth() + "%: " + width
+                    // + "px");
                     widget.setWidth(width + "px");
                 }
             } else {
@@ -1070,11 +1085,11 @@ public class ApplicationConnection {
                 height *= relativeSize.getHeight() / 100.0;
 
                 if (height >= 0) {
-//                    getConsole().log(
-//                            "Widget " + widget.getClass().getName() + "/"
-//                                    + widget.hashCode() + " relative height "
-//                                    + relativeSize.getHeight() + "%: " + height
-//                                    + "px");
+                    // getConsole().log(
+                    // "Widget " + widget.getClass().getName() + "/"
+                    // + widget.hashCode() + " relative height "
+                    // + relativeSize.getHeight() + "%: " + height
+                    // + "px");
                     widget.setHeight(height + "px");
                 }
             } else {
index 560ea4524d1055f71f016d7de94714ffb34d20aa..e68a7bac7e9d7c863bd60540d4eddd2770de51bf 100644 (file)
@@ -4,9 +4,6 @@
 
 package com.itmill.toolkit.terminal.gwt.client;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ui.IAccordion;
 import com.itmill.toolkit.terminal.gwt.client.ui.IButton;
@@ -54,17 +51,11 @@ import com.itmill.toolkit.terminal.gwt.client.ui.richtextarea.IRichTextArea;
 public class DefaultWidgetSet implements WidgetSet {
 
     /**
-     * This is the entry point method.
+     * This is the entry point method. It will start the first
      */
     public void onModuleLoad() {
-        ArrayList appIds = new ArrayList();
-        ApplicationConfiguration.loadAppIdListFromDOM(appIds);
-        for (Iterator iterator = appIds.iterator(); iterator.hasNext();) {
-            String appId = (String) iterator.next();
-            ApplicationConfiguration appConf = ApplicationConfiguration
-                    .getConfigFromDOM(appId);
-            new ApplicationConnection(this, appConf);
-        }
+        ApplicationConfiguration.initConfigurations(this);
+        ApplicationConfiguration.startNextApplication(); // start first app
     }
 
     public Paintable createWidget(UIDL uidl) {