From: Marc Englund Date: Thu, 2 Oct 2008 11:52:42 +0000 (+0000) Subject: Applications started in-order, one-at-a-time, to avoid session-id problems. Fixes... X-Git-Tag: 6.7.0.beta1~4035 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aceb3bfd645db0b202668c4691606f4ca1db3707;p=vaadin-framework.git Applications started in-order, one-at-a-time, to avoid session-id problems. Fixes #2134. svn changeset:5584/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java index 65b7750598..10738998f3 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConfiguration.java @@ -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; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java index 76c70c36b3..e6499e6408 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java @@ -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 { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java index 560ea4524d..e68a7bac7e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java @@ -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) {