Skip to content

Commit

Permalink
Adapt forceMessageHandling
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed May 12, 2022
1 parent f5855b3 commit 46ebd66
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 46ebd66

Please sign in to comment.