Browse Source

Use queue for resync requests. (#12043)

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
tags/8.12.0.alpha1
Anna Koskinen 3 years ago
parent
commit
9d027171e6
No account linked to committer's email address

+ 13
- 7
client/src/main/java/com/vaadin/client/communication/MessageSender.java View File



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


/** /**
* Counter for the messages send to the server. First sent message has id 0. * Counter for the messages send to the server. First sent message has id 0.
private void doSendInvocationsToServer() { private void doSendInvocationsToServer() {


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


JsonArray reqJson = serverRpcQueue.toJson(); JsonArray reqJson = serverRpcQueue.toJson();
serverRpcQueue.clear(); serverRpcQueue.clear();


if (reqJson.length() == 0) {
if (reqJson.length() == 0 && !resynchronizeRequested) {
// Nothing to send, all invocations were filtered out (for // Nothing to send, all invocations were filtered out (for
// non-existing connectors) // non-existing connectors)
getLogger().warning( getLogger().warning(
Version.getFullVersion()); Version.getFullVersion());
connection.getConfiguration().setWidgetsetVersionSent(); connection.getConfiguration().setWidgetsetVersionSent();
} }
if (resynchronizeRequested) {
getLogger().info("Resynchronizing from server");
extraJson.put(ApplicationConstants.RESYNCHRONIZE_ID, true);
resynchronizeRequested = false;
}
if (showLoadingIndicator) { if (showLoadingIndicator) {
connection.getLoadingIndicator().trigger(); connection.getLoadingIndicator().trigger();
} }
hasActiveRequest = false; hasActiveRequest = false;


if (connection.isApplicationRunning()) { if (connection.isApplicationRunning()) {
if (getServerRpcQueue().isFlushPending()) {
if (getServerRpcQueue().isFlushPending()
|| resynchronizeRequested) {
sendInvocationsToServer(); sendInvocationsToServer();
} }
runPostRequestHooks(connection.getConfiguration().getRootPanelId()); runPostRequestHooks(connection.getConfiguration().getRootPanelId());
*/ */
public void resynchronize() { public void resynchronize() {
getMessageHandler().onResynchronize(); 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();
} }


/** /**

Loading…
Cancel
Save