Author: gotcha
Date: Sun Dec 23 12:06:53 2007
New Revision: 50038

Modified:
   kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
   kukit/kukit.js/branch/finish-closures/kukit/requestmanager.js
Log:
module and class closures

Modified: kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/TODO.txt        (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/TODO.txt        Sun Dec 23 
12:06:53 2007
@@ -1,7 +1,6 @@
 files where closures are missing
 
 plugin.js
-requestmanager.js
 utils.js move to kukit the names that are defined in kukit namespaces.
 
 

Modified: kukit/kukit.js/branch/finish-closures/kukit/requestmanager.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/requestmanager.js       
(original)
+++ kukit/kukit.js/branch/finish-closures/kukit/requestmanager.js       Sun Dec 
23 12:06:53 2007
@@ -19,19 +19,24 @@
 
 /* Request manager */
 
-kukit.rm = {};
+kukit.rm = new function() {   /// MODULE START
+
+var rm = this;
+
 
 /* Generation of an integer uid on request objects
 */
 
-kukit.rm._rid = 0;
+rm._rid = 0;
 
 /*
-* class RequestItem
+* class _RequestItem
 *
 * Request item. Encapsulates the sendout function and data.
 */
-kukit.rm.RequestItem = function(sendHook, url, timeoutHook, timeout, now) {
+var _RequestItem = function() {
+
+this.initialize = function(sendHook, url, timeoutHook, timeout, now) {
     if (typeof(now) == 'undefined') {
         now = (new Date()).valueOf();
     }
@@ -43,27 +48,27 @@
     this.timeoutHook = timeoutHook;
     // Generate a RID. Due to timeouting, we have enough
     // of these for not to overlap ever.
-    this.rid = kukit.rm._rid;
-    kukit.rm._rid ++;
-    if (kukit.rm._rid >= 10000000000) {
-        kukit.rm._rid = 0;
+    this.rid = rm._rid;
+    rm._rid ++;
+    if (rm._rid >= 10000000000) {
+        rm._rid = 0;
     }
 };
 
-kukit.rm.RequestItem.prototype.callTimeoutHook = function() {
+this.callTimeoutHook = function() {
     // Calls the timeout hook for this item
     if (this.timeoutHook) {
         this.timeoutHook(this);
     }
 };
 
-kukit.rm.RequestItem.prototype.setReceivedCallback = function(func) {
+this.setReceivedCallback = function(func) {
     // Sets the received callback function. It will be
     // called with the item as first parameter.
     this._receivedCallback = func;
 };
 
-kukit.rm.RequestItem.prototype.receivedResult = function(now) {
+this.receivedResult = function(now) {
     // This is called when the result response has arrived. It
     // returns a booolean value, if this is false, the caller
     // must give up processing the result that has been timed
@@ -72,35 +77,39 @@
     this._receivedCallback = null;
     return result;
 }; 
+this.initialize.apply(this, arguments);
+};
 
 /* 
-* class TimerQueue
+* class _TimerQueue
 *
 * the send queue. This handles timeouts, and executes
 * a callback for timed out items.
 * Callback is called with the request item as parameter.
 */
 
-kukit.rm.TimerQueue = function(callback) {
+var _TimerQueue = function() {
+
+this.initialize = function(callback) {
     this.callback = callback;
     this.queue = new kukit.ut.SortedQueue(this._sentSort);
     this.count = 0;
 };
 
-kukit.rm.TimerQueue.prototype._sentSort = function(a, b) {
+this._sentSort = function(a, b) {
     // sorting of the sent queue, by expiration
     if (a.expire < b.expire) return -1;
     else if (a.expire > b.expire) return +1;
     else return 0;
 };
 
-kukit.rm.TimerQueue.prototype.push = function(item) {
+this.push = function(item) {
     // push a given slot
     this.queue.push(item);
     this.count += 1;
 };
 
-kukit.rm.TimerQueue.prototype.pop = function(item) {
+this.pop = function(item) {
     // pop a given slot, return true if it was valid,
     // return false if it was already handled by timeout.
     // An object can be popped more times!
@@ -113,7 +122,7 @@
     }
 };
 
-kukit.rm.TimerQueue.prototype.handleExpiration = function(now) {
+this.handleExpiration = function(now) {
     if (typeof(now) == 'undefined') {
         now = (new Date()).valueOf();
     }
@@ -141,11 +150,15 @@
     }
     return next_expire;
 };
+this.initialize.apply(this, arguments);
+};
 
 /* 
 * class RequestManager
 */
-kukit.rm.RequestManager = function (name, maxNr, schedulerClass) {
+rm.RequestManager = function () {
+
+this.initialize = function (name, maxNr, schedulerClass) {
     // schedulerClass is mainly provided for debugging...
     this.waitingQueue = new kukit.ut.FifoQueue();
     this.sentNr = 0;
@@ -153,7 +166,7 @@
     var timeoutItem = function(item) {
        self.timeoutItem(item);
     };
-    this.timerQueue = new kukit.rm.TimerQueue(timeoutItem);
+    this.timerQueue = new _TimerQueue(timeoutItem);
     if (typeof(name) == 'undefined') {
         name = null;
     }
@@ -176,27 +189,26 @@
     this.timeoutScheduler = new schedulerClass(checkTimeout);
     this.spinnerEvents = {'off': [], 'on': []};
     this.spinnerState = false;
-};
-
-// sending timeout in millisecs
-kukit.rm.RequestManager.prototype.sendingTimeout = 8000;
+    // sending timeout in millisecs
+    this.sendingTimeout = 8000;
 
-// max request number
-kukit.rm.RequestManager.prototype.maxNr = 4;
+    // max request number
+    this.maxNr = 4;
+};
 
-;;; kukit.rm.RequestManager.prototype.getInfo = function() {
+;;; this.getInfo = function() {
 ;;;     var msg = '(RQ: ' + this.sentNr + ' OUT, ' + this.waitingQueue.size();
 ;;;     msg += ' WAI)';
 ;;;     return msg;
 ;;; };
 
-;;; kukit.rm.RequestManager.prototype.log = function(txt) {
+;;; this.log = function(txt) {
 ;;;     var msg = 'RequestManager ' + this.nameString + txt + ' ';
 ;;;     msg += this.getInfo() + '.';
 ;;;     kukit.logDebug(msg);
 ;;; };
 
-kukit.rm.RequestManager.prototype.setSpinnerState = function(newState) {
+this.setSpinnerState = function(newState) {
     if (this.spinnerState != newState) {
         this.spinnerState = newState;
         // Call the registered spinner events for this state
@@ -207,13 +219,13 @@
     }
 };
 
-kukit.rm.RequestManager.prototype.pushWaitingRequest = function(item, now) {
+this.pushWaitingRequest = function(item, now) {
     this.waitingQueue.push(item);
     // Set the timeout
     this.checkTimeout(now);
 };
 
-kukit.rm.RequestManager.prototype.popWaitingRequest = function() {
+this.popWaitingRequest = function() {
     var q = this.waitingQueue;
     // pop handled elements, we don't send them out at all
     while (! q.empty() && q.front().handled) {
@@ -227,7 +239,7 @@
     }
 };
 
-kukit.rm.RequestManager.prototype.pushSentRequest = function(item, now) {
+this.pushSentRequest = function(item, now) {
     this.sentNr += 1;
 ;;; this.log('notifies server ' + item.url + ', rid=' + item.rid);
     // Set the spinner state
@@ -245,7 +257,7 @@
     item.sendHook(item);
 };
 
-kukit.rm.RequestManager.prototype.checkTimeout = function(now) {
+this.checkTimeout = function(now) {
     var nextWake = this.timerQueue.handleExpiration(now);
     if (nextWake) {
         // To make sure, add 50ms to the nextwake
@@ -262,7 +274,7 @@
     this.timeoutScheduler.setNextWakeAtLeast(nextWake);
 };
 
-kukit.rm.RequestManager.prototype.popSentRequest = function(item) {
+this.popSentRequest = function(item) {
     var success = this.timerQueue.pop(item);
     // We remove both to be processed, and timed out requests from the queue.
     // This means: possibly more physical requests are out, but this
@@ -271,11 +283,11 @@
     return success;
 };
 
-kukit.rm.RequestManager.prototype.isSentRequestQueueFull = function() {
+this.isSentRequestQueueFull = function() {
     return (this.sentNr >= this.maxNr);
 };
 
-kukit.rm.RequestManager.prototype.receivedResult = function(item, now) {
+this.receivedResult = function(item, now) {
     // called automatically when the result gets processed.
     // Mark that we have one less request out.
     var success = this.popSentRequest(item);
@@ -298,7 +310,7 @@
 };
 
 
-kukit.rm.RequestManager.prototype.receiveItem = function(item, now) {
+this.receiveItem = function(item, now) {
     // calls result processing
     var success = this.receivedResult(item, now);
 ;;; if (success) {
@@ -311,7 +323,7 @@
     return success;
 };
 
-kukit.rm.RequestManager.prototype.timeoutItem = function(item) {
+this.timeoutItem = function(item) {
     /* Time out this item. */
 ;;; this.log('timed out request rid [' + item.rid + ']');
     // Call the timeout hook on the item
@@ -320,7 +332,7 @@
 
 /* request manager notification API */
 
-kukit.rm.RequestManager.prototype.notifyServer =
+this.notifyServer =
     function(sendHook, url, timeoutHook, timeout, now) {
     // url is only for the logging
     // sendHook is the function that actually sends out the request.
@@ -338,7 +350,7 @@
         // Default value of timeout
         timeout = this.sendingTimeout;
     }
-    var item = new kukit.rm.RequestItem(sendHook, url, timeoutHook, timeout,
+    var item = new _RequestItem(sendHook, url, timeoutHook, timeout,
         now);
     // Start timing the item immediately
     this.timerQueue.push(item);
@@ -353,7 +365,10 @@
     }
 };
 
-kukit.rm.RequestManager.prototype.registerSpinnerEvent = function(func, state) 
{
+this.registerSpinnerEvent = function(func, state) {
     this.spinnerEvents[state ? 'on' : 'off'].push(func);
 };
+this.initialize.apply(this, arguments);
+};
 
+}();                              /// MODULE END
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to