// TODO: get path from ./configure prefix
var SHARED_WORKER_LIB = '/js/dojo/opensrf/opensrf_ws_shared.js';
+var OSRF_MAX_PARALLEL_REQUESTS = 10;
+
/* The following classes map directly to network-serializable opensrf objects */
function osrfMessage(hash) {
eval(str);
};
+// Some static request queueing functions.
+OpenSRF.throttleAlerted = false;
+OpenSRF.activeCount = 0;
/* general session superclass */
OpenSRF.Session = function() {
};
OpenSRF.Session.prototype.send = function(osrf_msg, args) {
+
+ if (osrf_msg.type() != 'DISCONNECT') {
+ // DISCONNECT messages do not return a response, so there's
+ // no way to know when have completed. Avoid tracking them
+ // as 'active'
+ OpenSRF.activeCount++;
+
+ if (OpenSRF.activeCount > OSRF_MAX_PARALLEL_REQUESTS
+ && !OpenSRF.throttleAlerted) {
+
+ OpenSRF.throttleAlerted = true;
+ console.error('Too many [' +
+ OpenSRF.activeCount + '] active network requests in progress!'
+ + ' Code requires refactoring to avoid so many active requests'
+ );
+ }
+ }
+
+ if (OpenSRF.activeCount >= OSRF_MAX_PARALLEL_REQUESTS) {
+ // Reset the alert state after the backlog clears.
+ OpenSRF.throttleAlerted = false;
+ }
+
args = (args) ? args : {};
switch(OpenSRF.Session.transport) {
case OSRF_TRANSPORT_TYPE_WS:
if(status == OSRF_STATUS_COMPLETE) {
+ OpenSRF.activeCount--;
if(req) {
req.complete = true;
if(req.oncomplete && !req.oncomplete_called) {
if(status == OSRF_STATUS_OK) {
ses.state = OSRF_APP_SESSION_CONNECTED;
+ OpenSRF.activeCount--;
/* call the connect callback */
if(ses.onconnect && !ses.onconnect_called) {
// capture all 400's and 500's as method errors
if ((status+'').match(/^4/) || (status+'').match(/^5/)) {
+ OpenSRF.activeCount--;
if(req && req.onmethoderror)
return req.onmethoderror(req, status, status_text);
}