Small improvements to timeouting in pullbox/OperationRouter
This commit is contained in:
parent
5fe87cbfc1
commit
63e4207fa0
@ -59,12 +59,11 @@ define("webodf/editor/server/pullbox/OperationRouter", [], function () {
|
|||||||
var operationFactory,
|
var operationFactory,
|
||||||
/**@type{function(!ops.Operation)}*/
|
/**@type{function(!ops.Operation)}*/
|
||||||
playbackFunction,
|
playbackFunction,
|
||||||
|
idleTimeout = null,
|
||||||
syncOpsTimeout = null,
|
syncOpsTimeout = null,
|
||||||
/**@type{!boolean}*/
|
/**@type{!boolean}*/
|
||||||
isInstantSyncRequested = false,
|
isInstantSyncRequested = false,
|
||||||
/**@type{!boolean}*/
|
/**@type{!boolean}*/
|
||||||
isPushingOpsTriggered = false,
|
|
||||||
/**@type{!boolean}*/
|
|
||||||
isPlayingUnplayedServerOpSpecs = false,
|
isPlayingUnplayedServerOpSpecs = false,
|
||||||
/**@type{!boolean}*/
|
/**@type{!boolean}*/
|
||||||
isSyncCallRunning = false,
|
isSyncCallRunning = false,
|
||||||
@ -90,8 +89,8 @@ define("webodf/editor/server/pullbox/OperationRouter", [], function () {
|
|||||||
hasPushedModificationOps = false,
|
hasPushedModificationOps = false,
|
||||||
operationTransformer = new ops.OperationTransformer(),
|
operationTransformer = new ops.OperationTransformer(),
|
||||||
/**@const*/replayTime = 500,
|
/**@const*/replayTime = 500,
|
||||||
/**@const*/pushingIntervall = 3000,
|
/**@const*/syncOpsDelay = 3000,
|
||||||
/**@const*/pullingIntervall = 8000;
|
/**@const*/idleDelay = 5000;
|
||||||
|
|
||||||
|
|
||||||
function updateHasLocalUnsyncedOpsState() {
|
function updateHasLocalUnsyncedOpsState() {
|
||||||
@ -254,6 +253,17 @@ runtime.log("Merged: from "+opspecs.length+" to "+result.length+" specs");
|
|||||||
var syncedClientOpspecs,
|
var syncedClientOpspecs,
|
||||||
syncRequestCallbacksArray;
|
syncRequestCallbacksArray;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {undefined}
|
||||||
|
*/
|
||||||
|
function startSyncOpsTimeout() {
|
||||||
|
idleTimeout = null;
|
||||||
|
syncOpsTimeout = runtime.getWindow().setTimeout(function() {
|
||||||
|
syncOpsTimeout = null;
|
||||||
|
syncOps();
|
||||||
|
}, syncOpsDelay);
|
||||||
|
}
|
||||||
|
|
||||||
if (isSyncCallRunning || hasUnresolvableConflict) {
|
if (isSyncCallRunning || hasUnresolvableConflict) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -262,8 +272,8 @@ runtime.log("Merged: from "+opspecs.length+" to "+result.length+" specs");
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no more timeout or instant pull request in any case
|
runtime.log("OperationRouter: sending sync_ops call");
|
||||||
syncOpsTimeout = null;
|
// no more instant pull request in any case
|
||||||
isInstantSyncRequested = false;
|
isInstantSyncRequested = false;
|
||||||
// set lock
|
// set lock
|
||||||
isSyncCallRunning = true;
|
isSyncCallRunning = true;
|
||||||
@ -290,7 +300,7 @@ runtime.log("Merged: from "+opspecs.length+" to "+result.length+" specs");
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.log("sync-ops reply: " + responseData);
|
runtime.log("sync_ops reply: " + responseData);
|
||||||
|
|
||||||
// just new ops?
|
// just new ops?
|
||||||
if (response.result === "new_ops") {
|
if (response.result === "new_ops") {
|
||||||
@ -307,6 +317,8 @@ runtime.log("Merged: from "+opspecs.length+" to "+result.length+" specs");
|
|||||||
}
|
}
|
||||||
// and note server state
|
// and note server state
|
||||||
lastServerSeq = response.head_seq;
|
lastServerSeq = response.head_seq;
|
||||||
|
} else {
|
||||||
|
receiveOpSpecsFromNetwork([], syncRequestCallbacksArray);
|
||||||
}
|
}
|
||||||
} else if (response.result === "added") {
|
} else if (response.result === "added") {
|
||||||
runtime.log("All added to server");
|
runtime.log("All added to server");
|
||||||
@ -347,10 +359,12 @@ runtime.log("Merged: from "+opspecs.length+" to "+result.length+" specs");
|
|||||||
if (isInstantSyncRequested) {
|
if (isInstantSyncRequested) {
|
||||||
syncOps();
|
syncOps();
|
||||||
} else {
|
} else {
|
||||||
syncOpsTimeout = runtime.getWindow().setTimeout(function() {
|
// nothing on client to sync?
|
||||||
syncOpsTimeout = null;
|
if (unsyncedClientOpspecQueue.length === 0) {
|
||||||
syncOps();
|
idleTimeout = runtime.getWindow().setTimeout(startSyncOpsTimeout, idleDelay);
|
||||||
}, (unsyncedClientOpspecQueue.length === 0) ? pullingIntervall : pushingIntervall);
|
} else {
|
||||||
|
startSyncOpsTimeout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
playUnplayedServerOpSpecs();
|
playUnplayedServerOpSpecs();
|
||||||
}
|
}
|
||||||
@ -358,25 +372,20 @@ runtime.log("Merged: from "+opspecs.length+" to "+result.length+" specs");
|
|||||||
}
|
}
|
||||||
|
|
||||||
function triggerPushingOps() {
|
function triggerPushingOps() {
|
||||||
if (isSyncCallRunning || isPushingOpsTriggered) {
|
// disable any idle timeout
|
||||||
return;
|
if (idleTimeout) {
|
||||||
|
runtime.clearTimeout(idleTimeout);
|
||||||
|
idleTimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
isPushingOpsTriggered = true;
|
// enable syncOps timeout, if needed
|
||||||
// disable current pulling timeout
|
if (!syncOpsTimeout && !isSyncCallRunning) {
|
||||||
if (syncOpsTimeout) {
|
runtime.log("OperationRouter: opsSync requested for pushing");
|
||||||
runtime.clearTimeout(syncOpsTimeout);
|
syncOpsTimeout = runtime.getWindow().setTimeout(function() {
|
||||||
syncOpsTimeout = null;
|
syncOpsTimeout = null;
|
||||||
|
syncOps();
|
||||||
|
}, syncOpsDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: how stupid! if the pulling timeout was close to done, this will extend it
|
|
||||||
// solution: split pulling into two timeouts, with second as short as pushing,
|
|
||||||
// and only cancel the first half
|
|
||||||
runtime.getWindow().setTimeout(function() {
|
|
||||||
runtime.log("Pushing activated");
|
|
||||||
isPushingOpsTriggered = false;
|
|
||||||
syncOps();
|
|
||||||
}, pushingIntervall);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -384,14 +393,23 @@ runtime.log("Pushing activated");
|
|||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
function requestInstantOpsSync(cb) {
|
function requestInstantOpsSync(cb) {
|
||||||
|
// register callback
|
||||||
syncRequestCallbacksQueue.push(cb);
|
syncRequestCallbacksQueue.push(cb);
|
||||||
|
|
||||||
// disable current pulling timeout
|
// disable any idle timeout
|
||||||
|
if (idleTimeout) {
|
||||||
|
runtime.clearTimeout(idleTimeout);
|
||||||
|
idleTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// disable any syncOps timeout
|
||||||
if (syncOpsTimeout) {
|
if (syncOpsTimeout) {
|
||||||
runtime.clearTimeout(syncOpsTimeout);
|
runtime.clearTimeout(syncOpsTimeout);
|
||||||
syncOpsTimeout = null;
|
syncOpsTimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime.log("OperationRouter: instant opsSync requested");
|
||||||
|
isInstantSyncRequested = true;
|
||||||
syncOps();
|
syncOps();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user