From 42e921c74bca0a0ca6b469c1525e5415e39404dd Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Wed, 11 May 2022 12:09:19 +0300 Subject: [PATCH 01/20] Fix issues with message handler and sender --- .../client/communication/MessageSender.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index 12381c8929e..19cdf900433 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -46,6 +46,8 @@ public class MessageSender { private final Registry registry; private final PushConnectionFactory pushConnectionFactory; + private boolean resynchronizeRequested = false; + /** * Creates a new instance connected to the given registry. * @@ -88,7 +90,7 @@ public void sendInvocationsToServer() { private void doSendInvocationsToServer() { ServerRpcQueue serverRpcQueue = registry.getServerRpcQueue(); - if (serverRpcQueue.isEmpty()) { + if (serverRpcQueue.isEmpty() && !resynchronizeRequested) { return; } @@ -96,7 +98,7 @@ private void doSendInvocationsToServer() { JsonArray reqJson = serverRpcQueue.toJson(); serverRpcQueue.clear(); - if (reqJson.length() == 0) { + if (reqJson.length() == 0 && !resynchronizeRequested) { // Nothing to send, all invocations were filtered out (for // non-existing connectors) Console.warn( @@ -105,6 +107,12 @@ private void doSendInvocationsToServer() { } JsonObject extraJson = Json.createObject(); + if (resynchronizeRequested) { + getMessageHandler().onResynchronize(); + Console.log("Resynchronizing from server"); + extraJson.put(ApplicationConstants.RESYNCHRONIZE_ID, true); + resynchronizeRequested = false; + } if (showLoadingIndicator) { ConnectionIndicator.setState(ConnectionIndicator.LOADING); } @@ -218,10 +226,9 @@ public String getCommunicationMethodName() { * state from the server */ public void resynchronize() { - Console.log("Resynchronizing from server"); - JsonObject resyncParam = Json.createObject(); - resyncParam.put(ApplicationConstants.RESYNCHRONIZE_ID, true); - send(Json.createArray(), resyncParam); + Console.log("Resynchronize from server requested"); + resynchronizeRequested = true; + sendInvocationsToServer(); } /** From b0c10236443d6170fd3192a6b414317014e1d0d4 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Wed, 11 May 2022 12:18:33 +0300 Subject: [PATCH 02/20] Fix issues with message handler and sender --- .../client/communication/MessageHandler.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java index c860e76c57d..bf981dbd9f9 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -66,6 +66,8 @@ public class MessageHandler { */ private static final int UNDEFINED_SYNC_ID = -1; + private boolean resyncInProgress; + /** * If responseHandlingLocks contains any objects, response handling is * suspended until the collection is empty or a timeout has occurred. @@ -217,7 +219,17 @@ public void handleMessage(final ValueMap json) { protected void handleJSON(final ValueMap valueMap) { final int serverId = getServerId(valueMap); - if (isResynchronize(valueMap) && !isNextExpectedMessage(serverId)) { + boolean hasResynchronize = isResynchronize(valueMap); + + if (!hasResynchronize && resyncInProgress) { + Console.warn( + "Dropping the response of a request before a resync request."); + return; + } + + resyncInProgress = false; + + if (hasResynchronize && !isNextExpectedMessage(serverId)) { // Resynchronize request. We must remove any old pending // messages and ensure this is handled next. Otherwise we // would keep waiting for an older message forever (if this @@ -820,4 +832,7 @@ public void setNextResponseSessionExpiredHandler( this.nextResponseSessionExpiredHandler = nextResponseSessionExpiredHandler; } + public void onResynchronize() { + resyncInProgress = true; + } } From f6f2e9288660c1c6ba328f3edf16c10d58bb9d44 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Wed, 11 May 2022 12:31:38 +0300 Subject: [PATCH 03/20] Fix --- .../java/com/vaadin/client/communication/MessageSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index 19cdf900433..8c1408b91f7 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -108,7 +108,7 @@ private void doSendInvocationsToServer() { JsonObject extraJson = Json.createObject(); if (resynchronizeRequested) { - getMessageHandler().onResynchronize(); + registry.getMessageHandler().onResynchronize(); Console.log("Resynchronizing from server"); extraJson.put(ApplicationConstants.RESYNCHRONIZE_ID, true); resynchronizeRequested = false; From c86d3c567eaa0a98b7d7d2540e715fac1fd8d737 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 14:33:28 +0300 Subject: [PATCH 04/20] Expose resynchronizeRequested --- .../java/com/vaadin/client/communication/MessageSender.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index 8c1408b91f7..ffed558813d 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -270,4 +270,8 @@ public void setClientToServerMessageId(int nextExpectedId, boolean force) { // Do nothing as they will arrive eventually } } + + boolean isResynchronizeRequested{ + return resynchronizeRequested; + } } From c659a8329f41b266e6696edec9cb0530b9475c81 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 14:35:18 +0300 Subject: [PATCH 05/20] Use resynchronizeRequested in end request --- .../vaadin/client/communication/RequestResponseTracker.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java index 6e5732db9a9..38cbb8b0839 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java @@ -108,8 +108,9 @@ public void endRequest() { // the call. hasActiveRequest = false; - if (registry.getUILifecycle().isRunning() - && registry.getServerRpcQueue().isFlushPending()) { + if ((registry.getUILifecycle().isRunning() + && registry.getServerRpcQueue().isFlushPending()) + || registry.getMessageSender().isResynchronizeRequested()) { // Send the pending RPCs immediately. // This might be an unnecessary optimization as ServerRpcQueue has a // finally scheduled command which trigger the send if we do not do From 3e446421757407c96ee756dd5abb51b06b0c46a1 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 14:35:49 +0300 Subject: [PATCH 06/20] Update flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java Co-authored-by: Artur --- .../java/com/vaadin/client/communication/MessageHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java index bf981dbd9f9..384e0252e34 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -223,7 +223,7 @@ protected void handleJSON(final ValueMap valueMap) { if (!hasResynchronize && resyncInProgress) { Console.warn( - "Dropping the response of a request before a resync request."); + "Ignoring message from the server as a resync request is ongoing."); return; } From cf89ec468842d71cb4554072a82b3557323ec989 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 14:38:10 +0300 Subject: [PATCH 07/20] Fix typo --- .../java/com/vaadin/client/communication/MessageSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index ffed558813d..90a013071bf 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -271,7 +271,7 @@ public void setClientToServerMessageId(int nextExpectedId, boolean force) { } } - boolean isResynchronizeRequested{ + boolean isResynchronizeRequested() { return resynchronizeRequested; } } From 925d7d04245aee1cde94303f290109d5e375b602 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 15:59:49 +0300 Subject: [PATCH 08/20] Join ResynchronizationStatus in one enum --- .../client/communication/MessageSender.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index 90a013071bf..30ae88423c7 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -37,6 +37,10 @@ */ public class MessageSender { + public enum ResynchronizationState { + NOT_ACTIVE, SEND_TO_SERVER, WAITING_FOR_RESPONSE + } + /** * Counter for the messages send to the server. First sent message has id 0. */ @@ -46,7 +50,7 @@ public class MessageSender { private final Registry registry; private final PushConnectionFactory pushConnectionFactory; - private boolean resynchronizeRequested = false; + private ResynchronizationState resynchronizationState = ResynchronizationState.NOT_ACTIVE; /** * Creates a new instance connected to the given registry. @@ -90,7 +94,8 @@ public void sendInvocationsToServer() { private void doSendInvocationsToServer() { ServerRpcQueue serverRpcQueue = registry.getServerRpcQueue(); - if (serverRpcQueue.isEmpty() && !resynchronizeRequested) { + if (serverRpcQueue.isEmpty() + && resynchronizationState != ResynchronizationState.SEND_TO_SERVER) { return; } @@ -98,7 +103,8 @@ private void doSendInvocationsToServer() { JsonArray reqJson = serverRpcQueue.toJson(); serverRpcQueue.clear(); - if (reqJson.length() == 0 && !resynchronizeRequested) { + if (reqJson.length() == 0 + && resynchronizationState != ResynchronizationState.SEND_TO_SERVER) { // Nothing to send, all invocations were filtered out (for // non-existing connectors) Console.warn( @@ -107,11 +113,10 @@ private void doSendInvocationsToServer() { } JsonObject extraJson = Json.createObject(); - if (resynchronizeRequested) { - registry.getMessageHandler().onResynchronize(); + if (resynchronizationState == ResynchronizationState.SEND_TO_SERVER) { + resynchronizationState = ResynchronizationState.WAITING_FOR_RESPONSE; Console.log("Resynchronizing from server"); extraJson.put(ApplicationConstants.RESYNCHRONIZE_ID, true); - resynchronizeRequested = false; } if (showLoadingIndicator) { ConnectionIndicator.setState(ConnectionIndicator.LOADING); @@ -271,7 +276,11 @@ public void setClientToServerMessageId(int nextExpectedId, boolean force) { } } - boolean isResynchronizeRequested() { - return resynchronizeRequested; + void setResynchronizationState(ResynchronizationState state) { + resynchronizationState = state; + } + + ResynchronizationState getResynchronizationState() { + return resynchronizationState; } } From 2eb3d47e9a571f80a55a5de938094d1313e0dd05 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:02:33 +0300 Subject: [PATCH 09/20] Use ResynchronizationState from MessageSender --- .../vaadin/client/communication/MessageHandler.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java index 384e0252e34..c7f4665d8f9 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -66,8 +66,6 @@ public class MessageHandler { */ private static final int UNDEFINED_SYNC_ID = -1; - private boolean resyncInProgress; - /** * If responseHandlingLocks contains any objects, response handling is * suspended until the collection is empty or a timeout has occurred. @@ -221,13 +219,15 @@ protected void handleJSON(final ValueMap valueMap) { boolean hasResynchronize = isResynchronize(valueMap); - if (!hasResynchronize && resyncInProgress) { + if (!hasResynchronize && registry.getMessageSender() + .getResynchronizationState() == ResynchronizationState.WAITING_FOR_RESPONSE) { Console.warn( "Ignoring message from the server as a resync request is ongoing."); return; } - resyncInProgress = false; + registry.getMessageSender() + .setResynchronizationState(ResynchronizationState.NOT_ACTIVE); if (hasResynchronize && !isNextExpectedMessage(serverId)) { // Resynchronize request. We must remove any old pending @@ -831,8 +831,4 @@ public void setNextResponseSessionExpiredHandler( Command nextResponseSessionExpiredHandler) { this.nextResponseSessionExpiredHandler = nextResponseSessionExpiredHandler; } - - public void onResynchronize() { - resyncInProgress = true; - } } From f215a769beef7e8a0542dfb0e7b967676259be16 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:04:51 +0300 Subject: [PATCH 10/20] Use ResynchronizationState from MessageSender --- .../com/vaadin/client/communication/RequestResponseTracker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java index 38cbb8b0839..b2d3db2fc9f 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java @@ -110,7 +110,7 @@ public void endRequest() { if ((registry.getUILifecycle().isRunning() && registry.getServerRpcQueue().isFlushPending()) - || registry.getMessageSender().isResynchronizeRequested()) { + || registry.getMessageSender().getResynchronizationState() == ResynchronizationState.SEND_TO_SERVER) { // Send the pending RPCs immediately. // This might be an unnecessary optimization as ServerRpcQueue has a // finally scheduled command which trigger the send if we do not do From 9aa544cc8f12f48b02fb03e4584747886cc4d493 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:07:13 +0300 Subject: [PATCH 11/20] Add import --- .../java/com/vaadin/client/communication/MessageHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java index c7f4665d8f9..b888a8fa536 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -27,6 +27,7 @@ import com.vaadin.client.UILifecycle.UIState; import com.vaadin.client.ValueMap; import com.vaadin.client.WidgetUtil; +import com.vaadin.client.communication.MessageSender.ResynchronizationState; import com.vaadin.client.flow.ConstantPool; import com.vaadin.client.flow.StateNode; import com.vaadin.client.flow.StateTree; From f08248dfea3ba25a13e70134f09dcf78c1f1dd4c Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:07:46 +0300 Subject: [PATCH 12/20] Add import --- .../com/vaadin/client/communication/RequestResponseTracker.java | 1 + 1 file changed, 1 insertion(+) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java index b2d3db2fc9f..58a90eea9ac 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java @@ -20,6 +20,7 @@ import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.HandlerRegistration; +import com.vaadin.client.communication.MessageSender.ResynchronizationState; import com.vaadin.client.ConnectionIndicator; import com.vaadin.client.Registry; import com.vaadin.client.gwt.com.google.web.bindery.event.shared.SimpleEventBus; From 356ac9cf3bdfa05d594ec36406bbc4f5a60918b1 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:12:17 +0300 Subject: [PATCH 13/20] Fix --- .../java/com/vaadin/client/communication/MessageSender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index 30ae88423c7..e05667541c0 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -232,7 +232,7 @@ public String getCommunicationMethodName() { */ public void resynchronize() { Console.log("Resynchronize from server requested"); - resynchronizeRequested = true; + resynchronizationState = ResynchronizationState.SEND_TO_SERVER; sendInvocationsToServer(); } From 0559fb992a383cb49b8846b51e1f53a9e9abcf6e Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:47:32 +0300 Subject: [PATCH 14/20] Add mock MessageSender --- .../test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java b/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java index 2e8dfad04ae..a9e793dd573 100644 --- a/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java +++ b/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java @@ -29,6 +29,7 @@ protected void gwtSetUp() throws Exception { set(RequestResponseTracker.class, new RequestResponseTracker(this)); set(MessageHandler.class, new MessageHandler(this)); + set(MessageSender.class, new MessageSender(this)); set(ServerRpcQueue.class, new ServerRpcQueue(this)); set(DependencyLoader.class, new DependencyLoader(this)); set(ResourceLoader.class, new ResourceLoader(this, false)); From f6d3fb7ea784e4a75a77fc4afc85896bd60913aa Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:52:55 +0300 Subject: [PATCH 15/20] Add mock RequestResponseTracker --- .../test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java b/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java index 30264e7026f..ba204917267 100644 --- a/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java +++ b/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java @@ -188,6 +188,8 @@ protected void gwtSetUp() throws Exception { set(ApplicationConfiguration.class, new TestApplicationConfiguration()); set(EventsOrder.class, new EventsOrder()); + set(RequestResponseTracker.class, + new RequestResponseTracker(this)); set(MessageSender.class, new TestMessageSender(this)); set(SystemErrorHandler.class, new TestSystemErrorHandler(this)); set(ExecuteJavaScriptProcessor.class, From 70a0f3b806bfefbe53c3a8cd20d062e8041e4bfc Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 16:55:26 +0300 Subject: [PATCH 16/20] Add import --- .../test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java b/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java index a9e793dd573..349d7afb61b 100644 --- a/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java +++ b/flow-client/src/test-gwt/java/com/vaadin/client/flow/dom/GwtDomApiTest.java @@ -10,6 +10,7 @@ import com.vaadin.client.UILifecycle.UIState; import com.vaadin.client.ValueMap; import com.vaadin.client.communication.MessageHandler; +import com.vaadin.client.communication.MessageSender; import com.vaadin.client.communication.RequestResponseTracker; import com.vaadin.client.communication.ServerRpcQueue; From f5855b3f3cd8f60cbd5049a72e4e23fa4f80dede Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Thu, 12 May 2022 17:08:03 +0300 Subject: [PATCH 17/20] Fix --- .../test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java b/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java index ba204917267..30264e7026f 100644 --- a/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java +++ b/flow-client/src/test-gwt/java/com/vaadin/client/GwtMessageHandlerTest.java @@ -188,8 +188,6 @@ protected void gwtSetUp() throws Exception { set(ApplicationConfiguration.class, new TestApplicationConfiguration()); set(EventsOrder.class, new EventsOrder()); - set(RequestResponseTracker.class, - new RequestResponseTracker(this)); set(MessageSender.class, new TestMessageSender(this)); set(SystemErrorHandler.class, new TestSystemErrorHandler(this)); set(ExecuteJavaScriptProcessor.class, From f27beb497cd96d419c29f282324b6e109909101d Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Fri, 13 May 2022 10:39:09 +0300 Subject: [PATCH 18/20] Code formatting --- .../vaadin/client/communication/RequestResponseTracker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java index 58a90eea9ac..3a3750cf0e4 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/RequestResponseTracker.java @@ -111,7 +111,8 @@ public void endRequest() { if ((registry.getUILifecycle().isRunning() && registry.getServerRpcQueue().isFlushPending()) - || registry.getMessageSender().getResynchronizationState() == ResynchronizationState.SEND_TO_SERVER) { + || registry.getMessageSender() + .getResynchronizationState() == ResynchronizationState.SEND_TO_SERVER) { // Send the pending RPCs immediately. // This might be an unnecessary optimization as ServerRpcQueue has a // finally scheduled command which trigger the send if we do not do From b8b393a3859df46860cb4384d97b9d39e21efc19 Mon Sep 17 00:00:00 2001 From: Mikhail Shabarov Date: Wed, 18 May 2022 16:42:54 +0300 Subject: [PATCH 19/20] fix: Ask for resynchronization before end a previous request --- .../client/communication/MessageHandler.java | 22 +++++++------ .../client/communication/MessageSender.java | 31 ++++++++++++++++--- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java index b888a8fa536..09ab36df996 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -227,8 +227,7 @@ protected void handleJSON(final ValueMap valueMap) { return; } - registry.getMessageSender() - .setResynchronizationState(ResynchronizationState.NOT_ACTIVE); + registry.getMessageSender().clearResynchronizationState(); if (hasResynchronize && !isNextExpectedMessage(serverId)) { // Resynchronize request. We must remove any old pending @@ -579,13 +578,6 @@ private int getExpectedServerId() { } private void forceMessageHandling() { - // Clear previous request if it exists. Otherwise resyncrhonize can - // trigger - // "Trying to start a new request while another is active" exception and - // fail. - if (registry.getRequestResponseTracker().hasActiveRequest()) { - registry.getRequestResponseTracker().endRequest(); - } if (!responseHandlingLocks.isEmpty()) { // Lock which was never release -> bug in locker or things just // too slow @@ -606,6 +598,18 @@ private void forceMessageHandling() { // has been lost // Drop pending messages and resynchronize pendingUIDLMessages.clear(); + + // Inform the message sender that resynchronize is desired already + // since endRequest may already send out a next request + registry.getMessageSender().requestResynchronize(); + + // Clear previous request if it exists. + if (registry.getRequestResponseTracker().hasActiveRequest()) { + registry.getRequestResponseTracker().endRequest(); + } + + // Call resynchronize to make sure a resynchronize request is sent in + // case endRequest did not already do this. registry.getMessageSender().resynchronize(); } } diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index e05667541c0..4e89be4e6c0 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -231,9 +231,9 @@ public String getCommunicationMethodName() { * state from the server */ public void resynchronize() { - Console.log("Resynchronize from server requested"); - resynchronizationState = ResynchronizationState.SEND_TO_SERVER; - sendInvocationsToServer(); + if (requestResynchronize()) { + sendInvocationsToServer(); + } } /** @@ -276,8 +276,29 @@ public void setClientToServerMessageId(int nextExpectedId, boolean force) { } } - void setResynchronizationState(ResynchronizationState state) { - resynchronizationState = state; + /** + * Modifies the resynchronize state to indicate that resynchronization is desired + * + * @return true if the resynchronize request still needs to be sent; false otherwise + */ + boolean requestResynchronize() { + switch (resynchronizationState) { + case NOT_ACTIVE: + Console.log("Resynchronize from server requested"); + resynchronizationState = ResynchronizationState.SEND_TO_SERVER; + return true; + case SEND_TO_SERVER: + // Resynchronize has already been requested, but hasn't been sent yet + return true; + case WAITING_FOR_RESPONSE: + default: + // Resynchronize has already been requested, but response hasn't been received yet + return false; + } + } + + void clearResynchronizationState() { + resynchronizationState = ResynchronizationState.NOT_ACTIVE; } ResynchronizationState getResynchronizationState() { From 7d982492afafc8b24659ace238c5d7de0a6021da Mon Sep 17 00:00:00 2001 From: Mikhail Shabarov Date: Wed, 18 May 2022 16:54:40 +0300 Subject: [PATCH 20/20] chore: fix formatting --- .../client/communication/MessageHandler.java | 3 +- .../client/communication/MessageSender.java | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java index 09ab36df996..55bfef8b259 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -608,7 +608,8 @@ private void forceMessageHandling() { registry.getRequestResponseTracker().endRequest(); } - // Call resynchronize to make sure a resynchronize request is sent in + // Call resynchronize to make sure a resynchronize request is sent + // in // case endRequest did not already do this. registry.getMessageSender().resynchronize(); } diff --git a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java index 4e89be4e6c0..4a01392237f 100644 --- a/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/flow-client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -277,23 +277,27 @@ public void setClientToServerMessageId(int nextExpectedId, boolean force) { } /** - * Modifies the resynchronize state to indicate that resynchronization is desired + * Modifies the resynchronize state to indicate that resynchronization is + * desired * - * @return true if the resynchronize request still needs to be sent; false otherwise + * @return true if the resynchronize request still needs to be sent; false + * otherwise */ boolean requestResynchronize() { switch (resynchronizationState) { - case NOT_ACTIVE: - Console.log("Resynchronize from server requested"); - resynchronizationState = ResynchronizationState.SEND_TO_SERVER; - return true; - case SEND_TO_SERVER: - // Resynchronize has already been requested, but hasn't been sent yet - return true; - case WAITING_FOR_RESPONSE: - default: - // Resynchronize has already been requested, but response hasn't been received yet - return false; + case NOT_ACTIVE: + Console.log("Resynchronize from server requested"); + resynchronizationState = ResynchronizationState.SEND_TO_SERVER; + return true; + case SEND_TO_SERVER: + // Resynchronize has already been requested, but hasn't been sent + // yet + return true; + case WAITING_FOR_RESPONSE: + default: + // Resynchronize has already been requested, but response hasn't + // been received yet + return false; } }