summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2013-04-05 18:33:55 +0300
committerLeif Åstrand <leif@vaadin.com>2013-04-10 14:47:37 +0300
commit150352f64cdb49a27b110bd32e049c307fcf3486 (patch)
tree5a40f4a276d3f22d639ba2eb0cfd1e59e27b8049 /client
parent2700cd2fe6c48b29478f1b8e14fde1d405a6ab7d (diff)
downloadvaadin-framework-150352f64cdb49a27b110bd32e049c307fcf3486.tar.gz
vaadin-framework-150352f64cdb49a27b110bd32e049c307fcf3486.zip
Implemented poll interval for UI (#11495)
Change-Id: Ic56b0123970f18e282c75d67863569ac55c72ea8
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java17
-rw-r--r--client/src/com/vaadin/client/ui/ui/UIConnector.java38
2 files changed, 55 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index 2fa82c6004..2cc5a85996 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -2388,6 +2388,23 @@ public class ApplicationConnection {
}
/**
+ * Removes any pending invocation of the given method from the queue
+ *
+ * @param invocation
+ * The invocation to remove
+ */
+ public void removePendingInvocations(MethodInvocation invocation) {
+ Iterator<MethodInvocation> iter = pendingInvocations.values()
+ .iterator();
+ while (iter.hasNext()) {
+ MethodInvocation mi = iter.next();
+ if (mi.equals(invocation)) {
+ iter.remove();
+ }
+ }
+ }
+
+ /**
* This method sends currently queued variable changes to server. It is
* called when immediate variable update must happen.
*
diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java
index 07481063c3..f3b4f36670 100644
--- a/client/src/com/vaadin/client/ui/ui/UIConnector.java
+++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java
@@ -37,6 +37,7 @@ import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.History;
+import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
@@ -61,6 +62,7 @@ import com.vaadin.client.ui.layout.MayScrollChildren;
import com.vaadin.client.ui.window.WindowConnector;
import com.vaadin.server.Page.Styles;
import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.communication.MethodInvocation;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.Connect.LoadStyle;
@@ -417,6 +419,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
};
+ private Timer pollTimer = null;
+
@Override
public void updateCaption(ComponentConnector component) {
// NOP The main view never draws caption for its layout
@@ -580,5 +584,39 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
getConnection().getLoadingIndicator().setDelayStateDelay(
getState().loadingIndicatorConfiguration.delayStateDelay);
}
+
+ if (stateChangeEvent.hasPropertyChanged("pollInterval")) {
+ configurePolling();
+ }
+ }
+
+ private void configurePolling() {
+ if (pollTimer != null) {
+ pollTimer.cancel();
+ pollTimer = null;
+ }
+ if (getState().pollInterval >= 0) {
+ pollTimer = new Timer() {
+ @Override
+ public void run() {
+ /*
+ * Verify that polling has not recently been canceled. This
+ * is needed because Timer.cancel() does not always work
+ * properly in IE 8 until GWT issue 8101 has been fixed.
+ */
+ if (pollTimer != null) {
+ getRpcProxy(UIServerRpc.class).poll();
+ // Send changes even though poll is @Delayed
+ getConnection().sendPendingVariableChanges();
+ }
+ }
+ };
+ pollTimer.scheduleRepeating(getState().pollInterval);
+ } else {
+ // Ensure no more polls are sent as polling has been disabled
+ getConnection().removePendingInvocations(
+ new MethodInvocation(getConnectorId(), UIServerRpc.class
+ .getName(), "poll"));
+ }
}
}