-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathque.html
437 lines (318 loc) · 18.6 KB
/
que.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Модуль очередей</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="Модуль очередей"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2014-10-25T04:15+0400"/>
<meta name="author" content="rigidus"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
html { font-family: Times, serif; font-size: 12pt; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color: #add8e6; font-weight:normal }
.target { }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right {margin-left:auto; margin-right:0px; text-align:right;}
.left {margin-left:0px; margin-right:auto; text-align:left;}
.center {margin-left:auto; margin-right:auto; text-align:center;}
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: courier, monospace;
font-size: 90%;
overflow:auto;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; }
th.right { text-align:center; }
th.left { text-align:center; }
th.center { text-align:center; }
td.right { text-align:right; }
td.left { text-align:left; }
td.center { text-align:center; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
div.inlinetask {
padding:10px;
border:2px solid gray;
margin:10px;
background: #ffffcc;
}
textarea { overflow-x: auto; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
/*]]>*/-->
</style>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
</head>
<body>
<div id="preamble">
</div>
<div id="content">
<h1 class="title">Модуль очередей</h1>
<link rel="stylesheet" type="text/css" href="css/css.css" />
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Введение</a></li>
<li><a href="#sec-2">2 Функционал</a>
<ul>
<li><a href="#sec-2-1">2.1 Поиск очередей и получение списка имен всех очередей.</a></li>
<li><a href="#sec-2-2">2.2 операции создания и удаления очередей</a></li>
<li><a href="#sec-2-3">2.3 перации очистки очереди и получения содержимого всех ее элементов</a></li>
<li><a href="#sec-2-4">2.4 Операции добавления удаления и поиска элементов очереди</a></li>
<li><a href="#sec-2-5">2.5 Операцию подписки и отписки на очередь</a></li>
<li><a href="#sec-2-6">2.6 Операцию <code>mapcar-que</code>, которая применяет переданную функцию к каждому элементу очереди.</a></li>
<li><a href="#sec-2-7">2.7 Операцию посылки сообщения элементам очереди</a></li>
</ul>
</li>
<li><a href="#sec-3">3 Тесты</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> Введение</h2>
<div class="outline-text-2" id="text-1">
<p>
Очереди используются для фолловинга и прочей подписки на обновления.
</p>
<p>
Нам нужна некоторая инфраструктура чтобы абстрагироваться от операций управления
очередями, подписчиками и посылки сообщений. Потом ее можно будет изменить для поддержки
RabbitMQ, Mbus или ZMQ или даже использовать все их одновременно для разных целей.
</p>
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Функционал</h2>
<div class="outline-text-2" id="text-2">
<p>
Соберем контроллеры и все функции, которые контроллеры вызывают
</p>
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<<que_contents>>
<<que_test>>
</pre>
<p>
Мы вводим:
</p>
</div>
<div id="outline-container-2-1" class="outline-3">
<h3 id="sec-2-1"><span class="section-number-3">2.1</span> Поиск очередей и получение списка имен всех очередей.</h3>
<div class="outline-text-3" id="text-2-1">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">search</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">search-que</span> (name)
(aif (find-que <span style="color: #0000ee; font-weight: bold;">:name</span> name)
(id (car it))
nil))
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">all</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">all-que-names</span> ()
(mapcar #'name (all-que)))
</pre>
</div>
</div>
<div id="outline-container-2-2" class="outline-3">
<h3 id="sec-2-2"><span class="section-number-3">2.2</span> операции создания и удаления очередей</h3>
<div class="outline-text-3" id="text-2-2">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">make</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">ensure-que</span> (name)
(aif (search-que name)
it
(<span style="color: #00cdcd; font-weight: bold;">prog1</span> (make-que <span style="color: #0000ee; font-weight: bold;">:name</span> name)
(dbg <span style="color: #00cd00;">"Создана очередь ~A"</span> name))))
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">del</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">destroy-que</span> (name)
(aif (search-que name)
(<span style="color: #00cdcd; font-weight: bold;">prog1</span> (del-que (id it))
(dbg <span style="color: #00cd00;">"Удалена очередь ~A"</span> name))
(err <span style="color: #00cd00;">"destroy-que error: que not found"</span>)))
</pre>
</div>
</div>
<div id="outline-container-2-3" class="outline-3">
<h3 id="sec-2-3"><span class="section-number-3">2.3</span> перации очистки очереди и получения содержимого всех ее элементов</h3>
<div class="outline-text-3" id="text-2-3">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">clear</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">clear-que</span> (name)
(aif (search-que name)
(<span style="color: #00cdcd; font-weight: bold;">progn</span>
(<span style="color: #00cdcd; font-weight: bold;">with-connection</span> *db-spec*
(query (<span style="color: #0000ee; font-weight: bold;">:delete-from</span> 'quelt <span style="color: #0000ee; font-weight: bold;">:where</span> (<span style="color: #0000ee; font-weight: bold;">:=</span> 'que_id it))))
(dbg <span style="color: #00cd00;">"Очередь ~A очищена"</span> name))
(err <span style="color: #00cd00;">"clear-que error: que not found"</span>)))
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">all</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">all-que-elts</span> (name)
(aif (search-que name)
(mapcar #'text
(find-quelt <span style="color: #0000ee; font-weight: bold;">:que-id</span> it))
(err <span style="color: #00cd00;">"all-que-elts: que not found"</span>)))
</pre>
</div>
</div>
<div id="outline-container-2-4" class="outline-3">
<h3 id="sec-2-4"><span class="section-number-3">2.4</span> Операции добавления удаления и поиска элементов очереди</h3>
<div class="outline-text-3" id="text-2-4">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">add</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">add-to-que</span> (que-name text)
(aif (search-que que-name)
(make-quelt <span style="color: #0000ee; font-weight: bold;">:que-id</span> it <span style="color: #0000ee; font-weight: bold;">:text</span> text)
(err <span style="color: #00cd00;">"add-to-que error: que not found"</span>)))
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">del</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">del-from-que</span> (que-name text)
(aif (search-que que-name)
(aif (find-quelt <span style="color: #0000ee; font-weight: bold;">:que-id</span> it <span style="color: #0000ee; font-weight: bold;">:text</span> text)
(del-quelt (id (car it)))
(err <span style="color: #00cd00;">"add-to-que error: quelt not found"</span>))
(err <span style="color: #00cd00;">"add-to-que error: que not found"</span>)))
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">find</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">find-in-que</span> (que-name text)
(aif (search-que que-name)
(aif (find-quelt <span style="color: #0000ee; font-weight: bold;">:que-id</span> it <span style="color: #0000ee; font-weight: bold;">:text</span> text)
(car it)
(err <span style="color: #00cd00;">"add-to-que error: quelt not found"</span>))
(err <span style="color: #00cd00;">"add-to-que error: que not found"</span>)))
</pre>
</div>
</div>
<div id="outline-container-2-5" class="outline-3">
<h3 id="sec-2-5"><span class="section-number-3">2.5</span> Операцию подписки и отписки на очередь</h3>
<div class="outline-text-3" id="text-2-5">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">subscribe</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">subscribe</span> (que elt)
(add-to-que que elt))
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">unsubscribe</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">unsubscribe</span> (que elt)
(del-from-que que elt))
</pre>
</div>
</div>
<div id="outline-container-2-6" class="outline-3">
<h3 id="sec-2-6"><span class="section-number-3">2.6</span> Операцию <code>mapcar-que</code>, которая применяет переданную функцию к каждому элементу очереди.</h3>
<div class="outline-text-3" id="text-2-6">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">mapcar-que</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">mapcar-que</span> (que-name fn)
(aif (search-que que-name)
(mapcar #'(<span style="color: #00cdcd; font-weight: bold;">lambda</span> (x)
(apply fn (list (text x))))
(find-quelt <span style="color: #0000ee; font-weight: bold;">:que-id</span> it))))
</pre>
</div>
</div>
<div id="outline-container-2-7" class="outline-3">
<h3 id="sec-2-7"><span class="section-number-3">2.7</span> Операцию посылки сообщения элементам очереди</h3>
<div class="outline-text-3" id="text-2-7">
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">snd</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">snd</span> (que-name msg)
(mapcar-que que-name msg))
</pre>
</div>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3"><span class="section-number-2">3</span> Тесты</h2>
<div class="outline-text-2" id="text-3">
<p>
Теперь у нас есть весь необходимый функционал, для работы авторизации. Мы можем его
протестировать, для этого сформируем тест:
</p>
<pre class="src src-lisp"><span style="color: #cd0000;">;; </span><span style="color: #cd0000;">Тестируем авторизацию</span>
(<span style="color: #00cdcd; font-weight: bold;">defun</span> <span style="color: #0000ee; font-weight: bold;">que-test</span> ()
<<que_test_contents>>
(dbg <span style="color: #00cd00;">"passed: que-test~%"</span>))
(que-test)
</pre>
<pre class="src src-lisp">(<span style="color: #00cdcd; font-weight: bold;">in-package</span> #<span style="color: #0000ee; font-weight: bold;">:moto</span>)
<span style="color: #cd0000;">;; </span><span style="color: #cd0000;">tests</span>
(<span style="color: #00cdcd; font-weight: bold;">progn</span>
(ensure-que <span style="color: #00cd00;">"Q-1"</span>)
(ensure-que <span style="color: #00cd00;">"Q-2"</span>)
(ensure-que <span style="color: #00cd00;">"Q-3"</span>)
(<span style="color: #cd0000; font-weight: bold;">assert</span> (string= (bprint (all-que-names))
<span style="color: #00cd00;">"(\"Q-1\" \"Q-2\" \"Q-3\")"</span>))
(add-to-que <span style="color: #00cd00;">"Q-1"</span> <span style="color: #00cd00;">"test"</span>)
(add-to-que <span style="color: #00cd00;">"Q-1"</span> 7)
(<span style="color: #cd0000; font-weight: bold;">assert</span> (string= (bprint (all-que-elts <span style="color: #00cd00;">"Q-1"</span>))
<span style="color: #00cd00;">"(\"test\" \"7\")"</span>))
(<span style="color: #cd0000; font-weight: bold;">assert</span> (find-in-que <span style="color: #00cd00;">"Q-1"</span> <span style="color: #00cd00;">"7"</span>))
(del-from-que <span style="color: #00cd00;">"Q-1"</span> <span style="color: #00cd00;">"test"</span>)
(<span style="color: #cd0000; font-weight: bold;">assert</span> (string= (bprint (all-que-elts <span style="color: #00cd00;">"Q-1"</span>))
<span style="color: #00cd00;">"(\"7\")"</span>))
(<span style="color: #cd0000; font-weight: bold;">assert</span> (equal (bprint (snd <span style="color: #00cd00;">"Q-1"</span> #'(<span style="color: #00cdcd; font-weight: bold;">lambda</span> (x) x)))
<span style="color: #00cd00;">"(\"7\")"</span>)))
</pre>
</div>
</div>
</div>
<div id="postamble">
<p class="date">Date: 2014-10-25T04:15+0400</p>
<p class="author">Author: rigidus</p>
<p class="creator"><a href="http://orgmode.org">Org</a> version 7.9.3f with <a href="http://www.gnu.org/software/emacs/">Emacs</a> version 24</p>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
</div>
</body>
</html>