From 9f3d8a400d8f1109f265d96a4e74321d06cd78a5 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Sat, 16 Jul 2011 14:06:36 +0000 Subject: deferred widgetloading is now less eager (slow connection previously flooded loading that should happen controlled) svn changeset:19801/svn branch:6.6 --- .../gwt/client/ApplicationConfiguration.java | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'src/com') diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index 4b6194b79b..6787b36022 100644 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -223,7 +223,6 @@ public class ApplicationConfiguration implements EntryPoint { } } - deferredWidgetLoadLoop.scheduleRepeating(100); } /** @@ -257,6 +256,7 @@ public class ApplicationConfiguration implements EntryPoint { runningApplications.add(a); return true; } else { + deferredWidgetLoader = new DeferredWidgetLoader(); return false; } } @@ -361,6 +361,8 @@ public class ApplicationConfiguration implements EntryPoint { cmd.execute(); } callbacks.clear(); + } else if(widgetsLoading == 0 && deferredWidgetLoader != null) { + deferredWidgetLoader.trigger(); } } @@ -368,22 +370,44 @@ public class ApplicationConfiguration implements EntryPoint { /* * This loop loads widget implementation that should be loaded deferred. */ - private static final Timer deferredWidgetLoadLoop = new Timer() { + static class DeferredWidgetLoader extends Timer { private static final int FREE_LIMIT = 4; + private static final int FREE_CHECK_TIMEOUT = 100; int communicationFree = 0; int nextWidgetIndex = 0; + private boolean pending; + + public DeferredWidgetLoader() { + schedule(5000); + } + + public void trigger() { + if(!pending) { + schedule(FREE_CHECK_TIMEOUT); + } + } + + @Override + public void schedule(int delayMillis) { + super.schedule(delayMillis); + pending = true; + } @Override public void run() { + pending = false; if (!isBusy()) { Class nextType = getNextType(); if (nextType == null) { // ensured that all widgets are loaded - cancel(); + deferredWidgetLoader = null; } else { + communicationFree = 0; widgetSet.loadImplementation(nextType); } + } else { + schedule(FREE_CHECK_TIMEOUT); } } @@ -400,21 +424,23 @@ public class ApplicationConfiguration implements EntryPoint { private boolean isBusy() { if (widgetsLoading > 0) { communicationFree = 0; - return false; + return true; } for (ApplicationConnection app : runningApplications) { if (app.hasActiveRequest()) { // if an UIDL request or widget loading is active, mark as // busy communicationFree = 0; - return false; + return true; } } communicationFree++; return communicationFree < FREE_LIMIT; } - }; - + } + + private static DeferredWidgetLoader deferredWidgetLoader; + public void onModuleLoad() { // Enable IE6 Background image caching -- cgit v1.2.3