AjxRpc.js
Summary
No overview generated for 'AjxRpc.js'
function AjxRpc() {
};
AjxRpc._rpcCache = [];
AjxRpc._RPC_CACHE_MAX = 100;
AjxRpc._RPC_REAP_COUNT = 5;
AjxRpc._RPC_REAP_AGE = 300000;
AjxRpc.invoke =
function(requestStr, serverUrl, requestHeaders, callback, useGet) {
var asyncMode = (callback != null);
var rpcCtxt = AjxRpc._getFreeRpcCtxt();
try {
var response = rpcCtxt.req.invoke(requestStr, serverUrl, requestHeaders, callback, useGet);
} catch (ex) {
var newEx = new AjxException();
newEx.method = "AjxRpc.prototype._invoke";
if (ex instanceof Error) {
newEx.detail = ex.message;
newEx.code = AjxException.NETWORK_ERROR;
newEx.msg = "Network error";
} else {
newEx.detail = ex.toString();
newEx.code = AjxException.UNKNOWN_ERROR;
newEx.msg = "Unknown Error";
}
if (!asyncMode)
rpcCtxt.busy = false;
throw newEx;
}
if (!asyncMode)
rpcCtxt.busy = false;
return response;
};
AjxRpc._getFreeRpcCtxt =
function() {
var rpcCtxt = null;
for (var i = 0; i < AjxRpc._rpcCache.length; i++) {
rpcCtxt = AjxRpc._rpcCache[i];
if (!rpcCtxt.busy) {
DBG.println(AjxDebug.DBG1, "Found free RPC context: " + rpcCtxt.id);
break;
}
}
if (i == AjxRpc._rpcCache.length) {
if (AjxRpc._rpcCache.length == AjxRpc._RPC_CACHE_MAX) {
DBG.println(AjxDebug.DBG1, "Out of RPC contexts");
throw new AjxException("Out of RPC cache", AjxException.OUT_OF_RPC_CACHE, "ZmCsfeCommand._getFreeRpcCtxt");
} else if (i > 0 && (i % AjxRpc._RPC_REAP_COUNT == 0)) {
DBG.println(AjxDebug.DBG1, i + " busy RPC contexts");
AjxRpc._reap();
}
var id = "_rpcCtxt_" + i;
rpcCtxt = new _RpcCtxt(id);
DBG.println(AjxDebug.DBG1, "Created RPC " + id);
AjxRpc._rpcCache.push(rpcCtxt);
}
rpcCtxt.busy = true;
rpcCtxt.timestamp = (new Date()).getTime();
return rpcCtxt;
};
AjxRpc.getRpcRequest =
function(id) {
for (var i = 0; i < AjxRpc._rpcCache.length; i++) {
var rpcCtxt = AjxRpc._rpcCache[i];
if (rpcCtxt.id == id)
return rpcCtxt.req;
}
return null;
};
AjxRpc._reap =
function() {
var time = (new Date()).getTime();
for (var i = 0; i < AjxRpc._rpcCache.length; i++) {
var rpcCtxt = AjxRpc._rpcCache[i];
if (rpcCtxt.timestamp + AjxRpc._RPC_REAP_AGE < time) {
DBG.println(AjxDebug.DBG1, "AjxRpc._reap: cleared RPC context " + rpcCtxt.id);
rpcCtxt.req.cancel();
rpcCtxt.busy = false;
}
}
};
function _RpcCtxt(id) {
this.id = id;
this.req = new AjxRpcRequest(id, this);
this.busy = false;
};
Documentation generated by
JSDoc on Thu Apr 27 13:58:40 2006