working for one;

This commit is contained in:
ericrius1 2016-03-22 10:07:59 -07:00
parent bc8a8ac703
commit 130eb6b619
2 changed files with 26 additions and 29 deletions

View file

@ -145,32 +145,30 @@ function virtualBatonf(options) {
// It would be great if we had a way to know how many subscribers our channel has. Failing that... // It would be great if we had a way to know how many subscribers our channel has. Failing that...
var nNack = 0, previousNSubscribers = 0, lastGathering = 0, thisTimeout = electionTimeout; var nNack = 0, previousNSubscribers = 0, lastGathering = 0, thisTimeout = electionTimeout;
function nSubscribers() { // Answer the number of subscribers. function nSubscribers() { // Answer the number of subscribers.
// // To find nQuorum, we need to know how many scripts are being run using this batonName, which isn't // To find nQuorum, we need to know how many scripts are being run using this batonName, which isn't
// // the same as the number of clients! // the same as the number of clients!
// //
// // If we overestimate by too much, we may fail to reach consensus, which triggers a new
// // election proposal, so we take the number of acceptors to be the max(nPromises, nAccepted)
// // + nNack reported in the previous round.
// //
// // If we understimate by too much, there can be different pockets on the Internet that each
// // believe they have agreement on different holders of the baton, which is precisely what
// // the virtualBaton is supposed to avoid. Therefore we need to allow 'nack' to gather stragglers.
// var now = Date.now(), elapsed = now - lastGathering; // If we overestimate by too much, we may fail to reach consensus, which triggers a new
// if (elapsed >= thisTimeout) { // election proposal, so we take the number of acceptors to be the max(nPromises, nAccepted)
// previousNSubscribers = Math.max(nPromises, nAccepted) + nNack; // + nNack reported in the previous round.
// lastGathering = now;
// } // ...otherwise we use the previous value unchanged.
// // On startup, we do one proposal that we cannot possibly close, so that we'll // If we understimate by too much, there can be different pockets on the Internet that each
// // lock things up for the full electionTimeout to gather responses. // believe they have agreement on different holders of the baton, which is precisely what
// if (!previousNSubscribers) { // the virtualBaton is supposed to avoid. Therefore we need to allow 'nack' to gather stragglers.
// var LARGE_INTEGER = Number.MAX_SAFE_INTEGER || (-1 >>> 1); // QT doesn't define the ECMA constant. Max int will do for our purposes.
// previousNSubscribers = LARGE_INTEGER; var now = Date.now(), elapsed = now - lastGathering;
// } if (elapsed >= thisTimeout) {
// return previousNSubscribers; previousNSubscribers = Math.max(nPromises, nAccepted) + nNack;
print("EBL NUMBER SUBSCRIBERS ", AvatarList.getAvatarIdentifiers().length); lastGathering = now;
return AvatarList.getAvatarIdentifiers().length; } // ...otherwise we use the previous value unchanged.
// On startup, we do one proposal that we cannot possibly close, so that we'll
// lock things up for the full electionTimeout to gather responses.
if (!previousNSubscribers) {
var LARGE_INTEGER = Number.MAX_SAFE_INTEGER || (-1 >>> 1); // QT doesn't define the ECMA constant. Max int will do for our purposes.
previousNSubscribers = LARGE_INTEGER;
}
return previousNSubscribers;
} }
// MAIN ALGORITHM // MAIN ALGORITHM
@ -373,8 +371,7 @@ function virtualBatonf(options) {
}; };
// Gather nAcceptors by making two proposals with some gathering time, even without a claim. // Gather nAcceptors by making two proposals with some gathering time, even without a claim.
print("EBL PROPOSE HAS BEEN COMMENTED OUT!"); propose();
// propose();
return exports; return exports;
} }
if (typeof module !== 'undefined') { // Allow testing in nodejs. if (typeof module !== 'undefined') { // Allow testing in nodejs.

View file

@ -30,7 +30,7 @@
// We already have our injector so just restart it // We already have our injector so just restart it
_this.soundInjector.restart(); _this.soundInjector.restart();
} }
print("EBL START UPDATE") print("EBL START UPDATE");
Entities.editEntity(_this.batonDebugModel, {visible: true}); Entities.editEntity(_this.batonDebugModel, {visible: true});
_this.playSoundInterval = Script.setInterval(function() { _this.playSoundInterval = Script.setInterval(function() {
// print("EBL PLAY THE SOUND"); // print("EBL PLAY THE SOUND");
@ -41,8 +41,8 @@
} }
function stopUpdateAndReclaim() { function stopUpdateAndReclaim() {
print("EBL STOP UPDATE AND RECLAIM")
// when the baton is release // when the baton is release
print("EBL CLAIM BATON")
if (_this.soundIntervalConnected === true) { if (_this.soundIntervalConnected === true) {
Script.clearInterval(_this.playSoundInterval); Script.clearInterval(_this.playSoundInterval);
_this.soundIntervalConnected = false; _this.soundIntervalConnected = false;
@ -69,7 +69,7 @@
baton = virtualBaton({ baton = virtualBaton({
// One winner for each entity // One winner for each entity
batonName: "io.highfidelity.soundEntityBatonTest:" + _this.entityID, batonName: "io.highfidelity.soundEntityBatonTest:" + _this.entityID,
debugFlow: true // debugFlow: true
}); });
stopUpdateAndReclaim(); stopUpdateAndReclaim();
}, },