Add identifiers to incrementAsyncProcesses and decrementAsyncProcesses calls to assist in determining the cause when translators fail to complete

This commit is contained in:
Simon Kornblith 2011-09-05 23:26:33 +00:00
parent e9127cf295
commit 7e5b48838a
2 changed files with 25 additions and 25 deletions

View File

@ -265,27 +265,27 @@ Zotero.Translate.Sandbox = {
}
if(!translatorsHandlerSet) {
translation.setHandler("translators", function() {
translate.decrementAsyncProcesses();
translate.decrementAsyncProcesses("safeTranslator#getTranslators()");
});
}
translate.incrementAsyncProcesses();
translate.incrementAsyncProcesses("safeTranslator#getTranslators()");
return translation.getTranslators();
};
var doneHandlerSet = false;
safeTranslator.translate = function() {
translate.incrementAsyncProcesses();
translate.incrementAsyncProcesses("safeTranslator#translate()");
setDefaultHandlers(translate, translation);
if(!doneHandlerSet) {
doneHandlerSet = true;
translation.setHandler("done", function() { translate.decrementAsyncProcesses() });
translation.setHandler("done", function() { translate.decrementAsyncProcesses("safeTranslator#translate()") });
}
return translation.translate(false);
};
safeTranslator.getTranslatorObject = function(callback) {
if(callback) {
translate.incrementAsyncProcesses();
translate.incrementAsyncProcesses("safeTranslator#getTranslatorObject()");
} else {
translate._debug("COMPAT WARNING: Translator must pass a callback to getTranslatorObject() to operate in connector");
}
@ -334,7 +334,7 @@ Zotero.Translate.Sandbox = {
translate.complete(false, e);
return;
}
translate.decrementAsyncProcesses();
translate.decrementAsyncProcesses("safeTranslator#getTranslatorObject()");
}
});
};
@ -426,7 +426,7 @@ Zotero.Translate.Sandbox = {
var newCallback = function(selectedItems) {
callbackExecuted = true;
callback(selectedItems);
if(haveAsyncHandler) translate.decrementAsyncProcesses();
if(haveAsyncHandler) translate.decrementAsyncProcesses("Zotero.selectItems()");
};
} else {
// if this translator doesn't provide an async callback for selectItems, set things
@ -459,7 +459,7 @@ Zotero.Translate.Sandbox = {
if(haveAsyncCallback) {
if(haveAsyncHandler) {
// we are running asynchronously, so increment async processes
translate.incrementAsyncProcesses();
translate.incrementAsyncProcesses("Zotero.selectItems()");
} else if(!callbackExecuted) {
// callback didn't get called from handler, so call it here
callback(returnedItems);
@ -781,12 +781,12 @@ Zotero.Translate.Base.prototype = {
/**
* Indicates that a new async process is running
*/
"incrementAsyncProcesses":function() {
"incrementAsyncProcesses":function(f) {
this._runningAsyncProcesses++;
if(this._parentTranslator) {
this._parentTranslator.incrementAsyncProcesses();
this._parentTranslator.incrementAsyncProcesses(f+" from child translator");
} else {
//Zotero.debug("Translate: Incremented asynchronous processes to "+this._runningAsyncProcesses, 4);
//Zotero.debug("Translate: Incremented asynchronous processes to "+this._runningAsyncProcesses+" for "+f, 4);
//Zotero.debug((new Error()).stack);
}
},
@ -794,16 +794,16 @@ Zotero.Translate.Base.prototype = {
/**
* Indicates that a new async process is finished
*/
"decrementAsyncProcesses":function(by) {
"decrementAsyncProcesses":function(f, by) {
this._runningAsyncProcesses -= (by ? by : 1);
if(!this._parentTranslator) {
//Zotero.debug("Translate: Decremented asynchronous processes to "+this._runningAsyncProcesses, 4);
//Zotero.debug("Translate: Decremented asynchronous processes to "+this._runningAsyncProcesses+" for "+f, 4);
//Zotero.debug((new Error()).stack);
}
if(this._runningAsyncProcesses === 0) {
this.complete();
}
if(this._parentTranslator) this._parentTranslator.decrementAsyncProcesses(by);
if(this._parentTranslator) this._parentTranslator.decrementAsyncProcesses(f+" from child translator", by);
},
/**
@ -985,7 +985,7 @@ Zotero.Translate.Base.prototype = {
Zotero.debug("Translate: Beginning translation with "+this.translator[0].label);
this.incrementAsyncProcesses();
this.incrementAsyncProcesses("Zotero.Translate#translate()");
// translate
try {
@ -999,7 +999,7 @@ Zotero.Translate.Base.prototype = {
}
}
this.decrementAsyncProcesses();
this.decrementAsyncProcesses("Zotero.Translate#translate()");
},
/**
@ -1054,7 +1054,7 @@ Zotero.Translate.Base.prototype = {
// reset async processes and propagate them to parent
if(this._parentTranslator && this._runningAsyncProcesses) {
this._parentTranslator.decrementAsyncProcesses(this._runningAsyncProcesses);
this._parentTranslator.decrementAsyncProcesses("Zotero.Translate#complete", this._runningAsyncProcesses);
}
this._runningAsyncProcesses = 0;
@ -1139,7 +1139,7 @@ Zotero.Translate.Base.prototype = {
"_detectTranslatorLoaded":function() {
this._prepareDetection();
this.incrementAsyncProcesses();
this.incrementAsyncProcesses("Zotero.Translate#getTranslators");
try {
var returnValue = this._sandboxManager.sandbox["detect"+this._entryFunctionSuffix].apply(null, this._getParameters());
@ -1149,7 +1149,7 @@ Zotero.Translate.Base.prototype = {
}
if(returnValue !== undefined) this._returnValue = returnValue;
this.decrementAsyncProcesses();
this.decrementAsyncProcesses("Zotero.Translate#getTranslators");
},
/**

View File

@ -227,15 +227,15 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
}
var translate = this._translate;
translate.incrementAsyncProcesses();
translate.incrementAsyncProcesses("Zotero.Utilities.Translate#processDocuments");
var hiddenBrowser = Zotero.HTTP.processDocuments(urls, processor, function() {
if(done) done();
translate.decrementAsyncProcesses();
translate.setHandler("done", function() {
try {
Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
} catch(e) {}
});
translate.decrementAsyncProcesses("Zotero.Utilities.Translate#processDocuments");
}, myException, true, translate.cookieSandbox);
}
@ -353,7 +353,7 @@ Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, res
var me = this;
this._translate.incrementAsyncProcesses();
this._translate.incrementAsyncProcesses("Zotero.Utilities.Translate#doGet");
var xmlhttp = Zotero.HTTP.doGet(url, function(xmlhttp) {
try {
if(processor) {
@ -367,7 +367,7 @@ Zotero.Utilities.Translate.prototype.doGet = function(urls, processor, done, res
done();
}
}
me._translate.decrementAsyncProcesses();
me._translate.decrementAsyncProcesses("Zotero.Utilities.Translate#doGet");
} catch(e) {
me._translate.complete(false, e);
}
@ -382,11 +382,11 @@ Zotero.Utilities.Translate.prototype.doPost = function(url, body, onDone, header
url = this._convertURL(url);
var translate = this._translate;
this._translate.incrementAsyncProcesses();
this._translate.incrementAsyncProcesses("Zotero.Utilities.Translate#doPost");
var xmlhttp = Zotero.HTTP.doPost(url, body, function(xmlhttp) {
try {
onDone(xmlhttp.responseText, xmlhttp);
translate.decrementAsyncProcesses();
translate.decrementAsyncProcesses("Zotero.Utilities.Translate#doPost");
} catch(e) {
translate.complete(false, e);
}