1 /* Licensed to the Apache Software Foundation (ASF) under one or more
  2  * contributor license agreements.  See the NOTICE file distributed with
  3  * this work for additional information regarding copyright ownership.
  4  * The ASF licenses this file to you under the Apache License, Version 2.0
  5  * (the "License"); you may not use this file except in compliance with
  6  * the License.  You may obtain a copy of the License at
  7  *
  8  *      http://www.apache.org/licenses/LICENSE-2.0
  9  *
 10  * Unless required by applicable law or agreed to in writing, software
 11  * distributed under the License is distributed on an "AS IS" BASIS,
 12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  * See the License for the specific language governing permissions and
 14  * limitations under the License.
 15 */
 16 /** @namespace myfaces._impl.xhrCore._AjaxRequestQueue */
 17 myfaces._impl.core._Runtime.extendClass("myfaces._impl.xhrCore._AjaxRequestQueue", myfaces._impl._util._Queue, {
 18 
 19     /**
 20      * a pointer towards the currently processed
 21      * request in our queue
 22      */
 23     _curReq : null,
 24 
 25 
 26     /**
 27      * the standard constructur of our class
 28      */
 29     constructor_: function() {
 30         this._callSuper("constructor");
 31     },
 32 
 33     /**
 34      * delay request, then call enqueue
 35      * @param {Object} request (myfaces._impl.xhrCore._AjaxRequest) request to send
 36      */
 37     enqueue : function(request) {
 38 
 39         if (typeof request._delay == "number") {
 40             this.clearDelayTimeout();
 41             var _Lang = myfaces._impl._util._Lang;
 42             this._delayTimeoutId = window.setTimeout(
 43                     _Lang.hitch(this, function() {
 44                         this.clearDelayTimeout();
 45                         //lets clear the delay time to enqueue correctly 
 46                         delete request._delay;
 47                         this.enqueue(request);
 48                     }), request._delay);
 49         } else {
 50             if (this._curReq == null) {
 51                 this._curReq = request;
 52                 this._curReq.send();
 53             } else {
 54                 this._callSuper("enqueue", request);
 55                 if (request._queueSize != this._size) {
 56                     this.setQueueSize(request._queueSize);
 57                 }
 58             }
 59         }
 60     },
 61 
 62     /**
 63      * timeout clearing routine
 64      * for timeout requests
 65      */
 66     clearDelayTimeout : function() {
 67         try {
 68             if (typeof this._delayTimeoutId == "number") {
 69                 window.clearTimeout(this._delayTimeoutId);
 70                 delete this._delayTimeoutId;
 71             }
 72         } catch (e) {
 73             // already timed out
 74         }
 75     },
 76 
 77 
 78     /**
 79      * process queue, send request, if exists
 80      */
 81     processQueue: function() {
 82         this._curReq = this.dequeue();
 83         if (this._curReq) {
 84             this._curReq.send();
 85         }
 86     },
 87 
 88     /**
 89      * cleanup queue
 90      */
 91     cleanup: function() {
 92         this._curReq = null;
 93         this._callSuper("cleanup");
 94     }
 95 });
 96 
 97