Skip to content

Commit

Permalink
Use queue for resync requests.
Browse files Browse the repository at this point in the history
There might be pending requests in the queue when a resync request is
made (e.g. through a theme change). This can cause conflicts if the
resync request is handled immediately. Therefore the resync request
should also be added to the queue and only get resolved when
doSendInvocationsToServer() gets triggered again.

Fixes #11954
  • Loading branch information
Ansku committed Jul 30, 2020
1 parent 17baaf0 commit e0fd385
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MessageSender {

private ApplicationConnection connection;
private boolean hasActiveRequest = false;
private boolean resynchronizeRequested = false;

/**
* Counter for the messages send to the server. First sent message has id 0.
Expand Down Expand Up @@ -98,7 +99,7 @@ public void sendInvocationsToServer() {
private void doSendInvocationsToServer() {

ServerRpcQueue serverRpcQueue = getServerRpcQueue();
if (serverRpcQueue.isEmpty()) {
if (serverRpcQueue.isEmpty() && !resynchronizeRequested) {
return;
}

Expand All @@ -110,7 +111,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)
getLogger().warning(
Expand All @@ -124,6 +125,11 @@ private void doSendInvocationsToServer() {
Version.getFullVersion());
connection.getConfiguration().setWidgetsetVersionSent();
}
if (resynchronizeRequested) {
getLogger().info("Resynchronizing from server");
extraJson.put(ApplicationConstants.RESYNCHRONIZE_ID, true);
resynchronizeRequested = false;
}
if (showLoadingIndicator) {
connection.getLoadingIndicator().trigger();
}
Expand Down Expand Up @@ -239,7 +245,8 @@ public void endRequest() {
hasActiveRequest = false;

if (connection.isApplicationRunning()) {
if (getServerRpcQueue().isFlushPending()) {
if (getServerRpcQueue().isFlushPending()
|| resynchronizeRequested) {
sendInvocationsToServer();
}
runPostRequestHooks(connection.getConfiguration().getRootPanelId());
Expand Down Expand Up @@ -350,10 +357,9 @@ private VLoadingIndicator getLoadingIndicator() {
*/
public void resynchronize() {
getMessageHandler().onResynchronize();
getLogger().info("Resynchronizing from server");
JsonObject resyncParam = Json.createObject();
resyncParam.put(ApplicationConstants.RESYNCHRONIZE_ID, true);
send(Json.createArray(), resyncParam);
getLogger().info("Resynchronize from server requested");
resynchronizeRequested = true;
sendInvocationsToServer();
}

/**
Expand Down

0 comments on commit e0fd385

Please sign in to comment.