~ubuntu-branches/ubuntu/lucid/loggerhead/lucid-security

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/yui/build/io/io-queue.js

  • Committer: Bazaar Package Importer
  • Author(s): James Westby, Roland Mas, Jelmer Vernooij, James Westby
  • Date: 2009-08-26 13:18:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090826131803-0ce1fhaetci8b0c5
Tags: 1.17-0ubuntu1
[ Roland Mas ]
* Use the YUI library provided by libjs-yui. (Closes: #511286)

[ Jelmer Vernooij ]
* Use my debian.org address in Uploaders field.
* Add ${misc:Depends} to please lintian.
* Suggest recent version of paste, which doesn't expose internal port
  numbers in links. (Closes: #507000)
* Bump standards version to 3.8.1.

[ James Westby ]
* New upstream release.
* Drop get-orig-source rule in favour of debian/watch.
* Add python-pkg-resources and python-paste to Build-Depends,
  python-pkg-resources to Depends and python-simplejson to
  Recommends due to dependency changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
 
3
Code licensed under the BSD License:
 
4
http://developer.yahoo.net/yui/license.txt
 
5
version: 3.0.0pr2
 
6
*/
 
7
YUI.add('io-queue', function(Y) {
 
8
 
 
9
   /*
 
10
    * Extends the IO base class to include basic queue interfaces for transaction
 
11
    * queuing.
 
12
        * @module io-base
 
13
        * @submodule io-queue
 
14
        */
 
15
 
 
16
   /**
 
17
        * @description Array of transactions queued for processing
 
18
        *
 
19
        * @property _q
 
20
        * @private
 
21
        * @static
 
22
        * @type array
 
23
        */
 
24
        var _q = [],
 
25
 
 
26
   /**
 
27
        * @description Property to determine whether the queue is set to
 
28
        * 1 (active) or 0 (inactive).  When inactive, transactions
 
29
        * will be stored in the queue until the queue is set to active.
 
30
        *
 
31
        * @property _qState
 
32
        * @private
 
33
        * @static
 
34
        * @type int
 
35
        */
 
36
        _qState = 1,
 
37
 
 
38
   /**
 
39
        * @description Queue property to set a maximum queue storage size.  When
 
40
        * this property is set, the queue will not store any more transactions
 
41
        * until the queue size os reduced below this threshold. There is no
 
42
        * maximum queue size until it is explicitly set.
 
43
        *
 
44
        * @property _qMaxSize
 
45
        * @private
 
46
        * @static
 
47
        * @type int
 
48
        */
 
49
        _qMaxSize = false;
 
50
 
 
51
   /**
 
52
        * @description Method for requesting a transaction, and queueing the
 
53
        * request before it is sent to the resource.
 
54
        *
 
55
        * @method _queue
 
56
        * @private
 
57
        * @static
 
58
        * @return int
 
59
        */
 
60
        function _queue(uri, c) {
 
61
 
 
62
                if (_qMaxSize === false || _q.length < _qMaxSize) {
 
63
                        var id = Y.io._id();
 
64
                        _q.push({ uri: uri, id: id, cfg:c });
 
65
                }
 
66
                else {
 
67
                        return false;
 
68
                }
 
69
 
 
70
                if (_qState === 1) {
 
71
                        _shift();
 
72
                }
 
73
 
 
74
                return id;
 
75
        };
 
76
 
 
77
   /**
 
78
        * @description Method for promoting a transaction to the top of the queue.
 
79
        *
 
80
        * @method _unshift
 
81
        * @private
 
82
        * @static
 
83
        * @return void
 
84
        */
 
85
        function _unshift(id) {
 
86
                var r;
 
87
 
 
88
                for (var i = 0; i < _q.length; i++) {
 
89
                        if (_q[i].id === id) {
 
90
                                r = _q.splice(i, 1);
 
91
                                var p = _q.unshift(r[0]);
 
92
                                break;
 
93
                        }
 
94
                }
 
95
        };
 
96
 
 
97
   /**
 
98
        * @description Method for removing a transaction from the top of the
 
99
        * queue, and sending the transaction to _io().
 
100
        *
 
101
        * @method _shift
 
102
        * @private
 
103
        * @static
 
104
        * @return void
 
105
        */
 
106
        function _shift() {
 
107
                var c = _q.shift();
 
108
                Y.io(c.uri, c.cfg, c.id);
 
109
        };
 
110
 
 
111
   /**
 
112
        * @description Method to query the current size of the queue, or to
 
113
        * set a maximum queue size.
 
114
        *
 
115
        * @method _size
 
116
        * @private
 
117
        * @static
 
118
        * @return int
 
119
        */
 
120
        function _size(i) {
 
121
                if (i) {
 
122
                        _qMaxSize = i;
 
123
                        return i;
 
124
                }
 
125
                else {
 
126
                        return _q.length;
 
127
                }
 
128
        };
 
129
 
 
130
   /**
 
131
        * @description Method for setting the queue to active. If there are
 
132
        * transactions pending in the queue, they will be processed from the
 
133
        * queue in FIFO order.
 
134
        *
 
135
        * @method _start
 
136
        * @private
 
137
        * @static
 
138
        * @return void
 
139
        */
 
140
        function _start() {
 
141
                var len = (_q.length > _qMaxSize > 0) ? _qMaxSize : _q.length;
 
142
 
 
143
                if (len > 1) {
 
144
                        for (var i=0; i < len; i++) {
 
145
                                _shift();
 
146
                        }
 
147
                }
 
148
                else {
 
149
                        _shift();
 
150
                }
 
151
 
 
152
        };
 
153
 
 
154
   /**
 
155
        * @description Method for setting queue processing to inactive.
 
156
        * Transaction requests to YUI.io.queue() will be stored in the queue, but
 
157
        * not processed until the queue is reset to "active".
 
158
        *
 
159
        * @method _stop
 
160
        * @private
 
161
        * @static
 
162
        * @return void
 
163
        */
 
164
        function _stop() {
 
165
                _qState = 0;
 
166
        };
 
167
 
 
168
   /**
 
169
        * @description Method for removing a specific, pending transaction from
 
170
        * the queue.
 
171
        *
 
172
        * @method _purge
 
173
        * @private
 
174
        * @static
 
175
        * @return void
 
176
        */
 
177
        function _purge(id) {
 
178
                if (Y.Lang.isNumber(id)) {
 
179
                        for (var i = 0; i < _q.length; i++) {
 
180
                                if (_q[i].id === id) {
 
181
                                        _q.splice(i, 1);
 
182
                                        break;
 
183
                                }
 
184
                        }
 
185
                }
 
186
        };
 
187
 
 
188
   /**
 
189
        * @description Method to query the current size of the queue, or to
 
190
        * set a maximum queue size.  This is the interface for _size().
 
191
        *
 
192
        * @method size
 
193
        * @public
 
194
        * @static
 
195
        * @param {number} i - Specified maximum size of queue.
 
196
    * @return number
 
197
        */
 
198
        _queue.size = _size;
 
199
 
 
200
   /**
 
201
        * @description Method for setting the queue to "active". If there are
 
202
        * transactions pending in the queue, they will be processed from the
 
203
        * queue in FIFO order. This is the interface for _start().
 
204
        *
 
205
        * @method start
 
206
        * @public
 
207
        * @static
 
208
    * @return void
 
209
        */
 
210
        _queue.start = _start;
 
211
 
 
212
   /**
 
213
        * @description Method for setting queue processing to inactive.
 
214
        * Transaction requests to YUI.io.queue() will be stored in the queue, but
 
215
        * not processed until the queue is set to "active". This is the
 
216
        * interface for _stop().
 
217
        *
 
218
        * @method stop
 
219
        * @public
 
220
        * @static
 
221
    * @return void
 
222
        */
 
223
        _queue.stop = _stop;
 
224
 
 
225
   /**
 
226
        * @description Method for promoting a transaction to the top of the queue.
 
227
        * This is the interface for _unshift().
 
228
        *
 
229
        * @method promote
 
230
        * @public
 
231
        * @static
 
232
        * @param {number} i - ID of queued transaction.
 
233
    * @return void
 
234
        */
 
235
        _queue.promote = _unshift;
 
236
 
 
237
   /**
 
238
        * @description Method for removing a specific, pending transaction from
 
239
        * the queue. This is the interface for _purge().
 
240
        *
 
241
        * @method purge
 
242
        * @public
 
243
        * @static
 
244
        * @param {number} i - ID of queued transaction.
 
245
    * @return void
 
246
        */
 
247
        _queue.purge = _purge;
 
248
 
 
249
    Y.mix(Y.io, {
 
250
                queue: _queue,
 
251
    }, true);
 
252
 
 
253
 
 
254
 
 
255
}, '3.0.0pr2' ,{requires:['io-base']});