Author: nbelaevski
Date: 2008-11-24 15:22:29 -0500 (Mon, 24 Nov 2008)
New Revision: 11338
Modified:
trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
Log:
Several logging statements added to queue
Modified: trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js
===================================================================
--- trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2008-11-24 20:00:12 UTC (rev
11337)
+++ trunk/framework/impl/src/main/javascript/ajaxjsf/queue.js 2008-11-24 20:22:29 UTC (rev
11338)
@@ -11,10 +11,12 @@
//queue constructor
A4J.AJAX.EventQueue = function() {
- var Pipeline = function(size, gate) {
+ var Pipeline = function(size, gate, queue) {
this.size = size || -1;
this.gate = gate;
+ this.queue = queue;
+
this.items = new Array();
};
@@ -29,6 +31,7 @@
},
createRequest: function(data) {
+ LOG.debug("Queue '" + this.queue.name + "' will submit request
NOW");
this.request = data.submit();
this.similarityGroupingId = data.getSimilarityGroupingId();
this.request.shouldNotifyQueue = true;
@@ -77,6 +80,7 @@
submitNext: function() {
this.clearRequest();
+ LOG.debug("After request: queue '" + this.queue.name +
"'");
if (this.getSize() > 0) {
this.submit();
@@ -99,6 +103,8 @@
abortCurrentRequest: function() {
if (this.request) {
+ LOG.debug("Current request in queue '" + this.queue.name + "'
has been aborted");
+
this.request.shouldNotifyQueue = false;
this.request.abort();
this.clearRequest();
@@ -113,7 +119,9 @@
}
}());
- var Gate = function() {
+ var Gate = function(queue) {
+ this.queue = queue;
+
this.eventsCounter = 0;
};
@@ -135,6 +143,9 @@
startRequestDelay: function() {
var delay = this.data.getRequestDelay();
+
+ LOG.debug("Queue will wait " + (delay || 0) + "ms before
submit");
+
if (delay) {
var _this = this;
this.timer = setTimeout(function() {
@@ -191,11 +202,13 @@
var similarityGroupingId = data.getSimilarityGroupingId();
if (this.similarityGroupingId == similarityGroupingId) {
+ LOG.debug("Similar request already in queue '" + this.queue.name +
"'");
this.data = data;
data.setEventsCounter(++this.eventsCounter);
this.resetRequestDelay();
} else {
+ LOG.debug("New event added to queue '" + this.queue.name +
"'. Queue similarityGroupingId changed to " + similarityGroupingId);
if (this.data) {
this.stopRequestDelay();
this.pipeline.addEvent(this.pop());
@@ -206,7 +219,7 @@
if (this.pipeline.isFull()) {
var behavior = data.getSizeExceededBehavior();
- var queue = data.queue;
+ var queue = this.queue;
var queueOptions = queue.queueOptions;
if (queueOptions.onsizeexceeded) {
@@ -214,7 +227,7 @@
var options = data.options;
var event = data.event;
- queueOptions.onsizeexceeded.call(data.queue, query, options, event);
+ queueOptions.onsizeexceeded.call(this.queue, query, options, event);
}
if (behavior == DROP_NEW ||
@@ -251,8 +264,8 @@
this.queueOptions = queueOptions || {};
this.requestOptions = requestOptions || {};
- this.gate = new Gate();
- this.pipeline = new Pipeline(this.queueOptions.size, this.gate);
+ this.gate = new Gate(this);
+ this.pipeline = new Pipeline(this.queueOptions.size, this.gate, this);
this.gate.pipeline = this.pipeline;
};
}();
@@ -278,8 +291,6 @@
delete A4J.AJAX._eventQueues[name];
};
-//TODO A4J.AJAX.EventQueue.getQueue ?
-
A4J.AJAX.EventQueue.getOrCreateQueue = function(){
var qualifyName = function(name, prefix) {
if (prefix) {
@@ -328,106 +339,7 @@
}
}();
-
A4J.AJAX.EventQueue.prototype = function() {
-
-
- /*
- * Queue: {
- * pop: {
- * pop();
- * barrier.unlock();
- *
- * if (!empty) {
- * submit();
- * } else {
- * barrier.transferIfReady();
- * }
- * },
- *
- * push: {
- * if (full) {
- * throw e;
- * }
- *
- * push();
- *
- * if (full) {
- * barrier.lock();
- * }
- *
- * if (!submitted) {
- * submit();
- * }
- * }
- *
- * submit: {
- * submit();
- * }
- *
- * }
- *
- * Barrier: {
- * match: {
- * //not matches if empty
- * }
- *
- * push: {
- * if (match()) {
- * //queue size stays the same
- *
- * assign();
- * increaseCounter();
- *
- * //reset can do immediate transfer
- * clearTimeout();
- * setTimeout(transferIfQueueEmpty())
- * } else {
- * //queue size increased by one
- *
- * if (!empty) {
- * clearTimeout();
- * delayPassed = true;
- * transfer();
- * }
- *
- * if (locked) {
- * //special unlock case when size = 1
- * unlock();
- * }
- *
- * assign();
- * setTimeout(transferIfQueueEmpty())
- * }
- * }
- *
- * pop: {
- * applyCounter();
- * resetCounter();
- * delayPassed = false;
- * empty = true;
- * }
- *
- * transfer: {
- * queue.push(pop());
- * }
- *
- * transferIfQueueEmpty: {
- * if (queue.isEmpty()) {
- * transfer();
- * } else {
- * delayPassed = true;
- * }
- * }
- *
- * transferIfReady: {
- * if (delayPassed) {
- * transfer();
- * }
- * }
- * }
- */
-
var EventQueueData = function(queue, query, options, event) {
this.queue = queue;
this.query = query;
@@ -477,9 +389,11 @@
// LOG.debug("Queue will wait " + (delay || 0) + "ms before
submit");
// LOG.debug("Similar request already in queue '" + this.name +
"'");
+
// LOG.debug("After request: queue '" + this.name + "' is empty
now");
// LOG.debug("Deleting transient queue '" + this.name + "' from
queues registry");
// LOG.debug("After request: queue not empty, processing next event in queue
'" + this.name + "'");
+
// LOG.debug("Queue '" + this.name + "' will submit request
NOW");
// LOG.debug("Delay for request not passed yet, have to wait");
// LOG.debug("Queue '" + this.name + "' is empty, nothing to
submit");