asir 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +11 -0
  2. data/Gemfile +16 -0
  3. data/README.textile +50 -0
  4. data/Rakefile +83 -0
  5. data/VERSION +1 -0
  6. data/asir.gemspec +36 -0
  7. data/asir.riterate.yml +114 -0
  8. data/bin/asir +6 -0
  9. data/doc/Rakefile +8 -0
  10. data/doc/asir-sequence.pic +84 -0
  11. data/doc/asir-sequence.svg +1559 -0
  12. data/doc/sequence.pic +430 -0
  13. data/example/asir_control.sh +24 -0
  14. data/example/asir_control_client_http.rb +14 -0
  15. data/example/asir_control_client_zmq.rb +15 -0
  16. data/example/config/asir_config.rb +63 -0
  17. data/example/delayed_service.rb +15 -0
  18. data/example/ex01.rb +12 -0
  19. data/example/ex02.rb +12 -0
  20. data/example/ex03.rb +19 -0
  21. data/example/ex04.rb +33 -0
  22. data/example/ex05.rb +16 -0
  23. data/example/ex06.rb +26 -0
  24. data/example/ex07.rb +28 -0
  25. data/example/ex08.rb +30 -0
  26. data/example/ex09.rb +25 -0
  27. data/example/ex10.rb +24 -0
  28. data/example/ex11.rb +48 -0
  29. data/example/ex12.rb +34 -0
  30. data/example/ex13.rb +35 -0
  31. data/example/ex14.rb +30 -0
  32. data/example/ex15.rb +13 -0
  33. data/example/ex16.rb +33 -0
  34. data/example/ex17.rb +41 -0
  35. data/example/ex18.rb +62 -0
  36. data/example/ex19.rb +32 -0
  37. data/example/ex20.rb +28 -0
  38. data/example/ex21.rb +28 -0
  39. data/example/ex22.rb +15 -0
  40. data/example/ex23.rb +20 -0
  41. data/example/ex24.rb +35 -0
  42. data/example/example_helper.rb +51 -0
  43. data/example/sample_service.rb +162 -0
  44. data/example/unsafe_service.rb +12 -0
  45. data/hack_night/README.txt +18 -0
  46. data/hack_night/exercise/prob-1.rb +18 -0
  47. data/hack_night/exercise/prob-2.rb +21 -0
  48. data/hack_night/exercise/prob-3.rb +16 -0
  49. data/hack_night/exercise/prob-4.rb +36 -0
  50. data/hack_night/exercise/prob-5.rb +36 -0
  51. data/hack_night/exercise/prob-6.rb +95 -0
  52. data/hack_night/exercise/prob-7.rb +34 -0
  53. data/hack_night/solution/math_service.rb +11 -0
  54. data/hack_night/solution/prob-1.rb +12 -0
  55. data/hack_night/solution/prob-2.rb +15 -0
  56. data/hack_night/solution/prob-3.rb +17 -0
  57. data/hack_night/solution/prob-4.rb +37 -0
  58. data/hack_night/solution/prob-5.rb +21 -0
  59. data/hack_night/solution/prob-6.rb +33 -0
  60. data/hack_night/solution/prob-7.rb +36 -0
  61. data/lab/phony_proc.rb +31 -0
  62. data/lib/asir.rb +253 -0
  63. data/lib/asir/additional_data.rb +25 -0
  64. data/lib/asir/channel.rb +130 -0
  65. data/lib/asir/client.rb +111 -0
  66. data/lib/asir/code_block.rb +57 -0
  67. data/lib/asir/code_more.rb +50 -0
  68. data/lib/asir/coder.rb +26 -0
  69. data/lib/asir/coder/base64.rb +19 -0
  70. data/lib/asir/coder/chain.rb +30 -0
  71. data/lib/asir/coder/identity.rb +23 -0
  72. data/lib/asir/coder/json.rb +30 -0
  73. data/lib/asir/coder/marshal.rb +17 -0
  74. data/lib/asir/coder/null.rb +23 -0
  75. data/lib/asir/coder/proc.rb +22 -0
  76. data/lib/asir/coder/sign.rb +48 -0
  77. data/lib/asir/coder/xml.rb +213 -0
  78. data/lib/asir/coder/yaml.rb +33 -0
  79. data/lib/asir/coder/zlib.rb +21 -0
  80. data/lib/asir/configuration.rb +32 -0
  81. data/lib/asir/error.rb +34 -0
  82. data/lib/asir/identity.rb +36 -0
  83. data/lib/asir/initialization.rb +23 -0
  84. data/lib/asir/log.rb +82 -0
  85. data/lib/asir/main.rb +396 -0
  86. data/lib/asir/message.rb +31 -0
  87. data/lib/asir/message/delay.rb +35 -0
  88. data/lib/asir/object_resolving.rb +15 -0
  89. data/lib/asir/result.rb +39 -0
  90. data/lib/asir/retry_behavior.rb +54 -0
  91. data/lib/asir/transport.rb +241 -0
  92. data/lib/asir/transport/beanstalk.rb +217 -0
  93. data/lib/asir/transport/broadcast.rb +34 -0
  94. data/lib/asir/transport/buffer.rb +115 -0
  95. data/lib/asir/transport/composite.rb +19 -0
  96. data/lib/asir/transport/connection_oriented.rb +180 -0
  97. data/lib/asir/transport/delay.rb +38 -0
  98. data/lib/asir/transport/delegation.rb +53 -0
  99. data/lib/asir/transport/fallback.rb +36 -0
  100. data/lib/asir/transport/file.rb +88 -0
  101. data/lib/asir/transport/http.rb +54 -0
  102. data/lib/asir/transport/local.rb +21 -0
  103. data/lib/asir/transport/null.rb +14 -0
  104. data/lib/asir/transport/payload_io.rb +52 -0
  105. data/lib/asir/transport/rack.rb +73 -0
  106. data/lib/asir/transport/retry.rb +41 -0
  107. data/lib/asir/transport/stream.rb +35 -0
  108. data/lib/asir/transport/subprocess.rb +30 -0
  109. data/lib/asir/transport/tcp_socket.rb +34 -0
  110. data/lib/asir/transport/webrick.rb +50 -0
  111. data/lib/asir/transport/zmq.rb +110 -0
  112. data/lib/asir/uuid.rb +32 -0
  113. data/lib/asir/version.rb +3 -0
  114. data/spec/const_get_speed_spec.rb +33 -0
  115. data/spec/debug_helper.rb +20 -0
  116. data/spec/example_spec.rb +88 -0
  117. data/spec/json_spec.rb +128 -0
  118. data/spec/spec_helper.rb +3 -0
  119. data/spec/xml_spec.rb +144 -0
  120. data/stylesheets/slides.css +105 -0
  121. metadata +173 -0
@@ -0,0 +1,430 @@
1
+ #/usr/bin/pic2plot -Tps
2
+ #
3
+ # Pic macros for drawing UML sequence diagrams
4
+ #
5
+ # (C) Copyright 2004-2005 Diomidis Spinellis.
6
+ #
7
+ # Permission to use, copy, and distribute this software and its
8
+ # documentation for any purpose and without fee is hereby granted,
9
+ # provided that the above copyright notice appear in all copies and that
10
+ # both that copyright notice and this permission notice appear in
11
+ # supporting documentation.
12
+ #
13
+ # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
14
+ # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
15
+ # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
+ #
17
+ # $Id: sequence.pic,v 1.11 2009/02/10 10:12:05 dds Exp $
18
+ #
19
+
20
+
21
+ # Default parameters (can be redefined)
22
+
23
+ # Spacing between messages
24
+ spacing = 0.25;
25
+ # Active box width
26
+ awid = .10;
27
+ # Box height
28
+ boxht = 0.3;
29
+ # Commend folding
30
+ corner_fold=awid
31
+ # Comment distance
32
+ define comment_default_move {up 0.25 right 0.25};
33
+ # Comment height
34
+ comment_default_ht=0.5;
35
+ # Comment width
36
+ comment_default_wid=1;
37
+ # Underline object name
38
+ underline=1;
39
+ # Invisbox
40
+ object_box=0;
41
+
42
+ # Create a new object(name,label)
43
+ define object {
44
+ if (object_box) then {
45
+ $1: box $2; move;
46
+ } else {
47
+ $1: box invis $2; move;
48
+ }
49
+ # Could also underline text with \mk\ul\ul\ul...\rt
50
+ if (underline) then {
51
+ line from $1.w + (boxht * -.3, boxht * -.5) to $1.e + (boxht * .3, boxht * -.5);
52
+ }
53
+ move to $1.e;
54
+ move right;
55
+ # Active is the level of activations of the object
56
+ # 0 : inactive : draw thin line swimlane
57
+ # 1 : active : draw thick swimlane
58
+ # > 1: nested : draw nested swimlane
59
+ active_$1 = 0;
60
+ lifestart_$1 = $1.s.y;
61
+ }
62
+
63
+ # Create a new external actor(name,label)
64
+ define actor {
65
+ $1: [
66
+ XSEQC: circle rad 0.06;
67
+ XSEQL: line from XSEQC.s down .12;
68
+ line from XSEQL.start - (.15,.02) to XSEQL.start + (.15,-.02);
69
+ XSEQL1: line from XSEQL.end left .08 down .15;
70
+ XSEQL2: line from XSEQL.end right .08 down .15;
71
+ line at XSEQC.n invis "" "" "" $2;
72
+ ]
73
+ move to $1.e;
74
+ move right;
75
+ active_$1 = 0;
76
+ lifestart_$1 = $1.s.y - .05;
77
+ }
78
+
79
+ # Create a new placeholder object(name)
80
+ define placeholder_object {
81
+ $1: box invisible;
82
+ move;
83
+ move to $1.e;
84
+ move right;
85
+ active_$1 = 0;
86
+ lifestart_$1 = $1.s.y;
87
+ }
88
+
89
+ define pobject {
90
+ placeholder_object($1);
91
+ }
92
+
93
+ define extend_lifeline {
94
+ if (active_$1 > 0) then {
95
+ # draw the left edges of the boxes
96
+ move to ($1.x - awid/2, Here.y);
97
+ for level = 1 to active_$1 do {
98
+ line from (Here.x, lifestart_$1) to Here;
99
+ move right awid/2
100
+ }
101
+
102
+ # draw the right edge of the innermost box
103
+ move right awid/2;
104
+ line from (Here.x, lifestart_$1) to Here;
105
+ } else {
106
+ line from ($1.x, lifestart_$1) to ($1.x, Here.y) dashed;
107
+ }
108
+ lifestart_$1 = Here.y;
109
+ }
110
+
111
+ # complete(name)
112
+ # Complete the lifeline of the object with the given name
113
+ define complete {
114
+ extend_lifeline($1)
115
+ if (active_$1) then {
116
+ # draw bottom of all active boxes
117
+ line right ((active_$1 + 1) * awid/2) from ($1.x - awid/2, Here.y);
118
+ }
119
+ }
120
+
121
+ # Draw a message(from_object,to_object,label)
122
+ define message {
123
+ down;
124
+ move spacing;
125
+ # Adjust so that lines and arrows do not fall into the
126
+ # active box. Should be .5, but the arrow heads tend to
127
+ # overshoot.
128
+ if ($1.x <= $2.x) then {
129
+ off_from = awid * .6;
130
+ off_to = -awid * .6;
131
+ } else {
132
+ off_from = -awid * .6;
133
+ off_to = awid * .6;
134
+ }
135
+
136
+ # add half a box width for each level of nesting
137
+ if (active_$1 > 1) then {
138
+ off_from = off_from + (active_$1 - 1) * awid/2;
139
+ }
140
+
141
+ # add half a box width for each level of nesting
142
+ if (active_$2 > 1) then {
143
+ off_to = off_to + (active_$2 - 1) * awid/2;
144
+ }
145
+
146
+ if ($1.x == $2.x) then {
147
+ arrow from ($1.x + off_from, Here.y) right then down .25 then left $3 ljust " " " " " " ;
148
+ } else {
149
+ arrow from ($1.x + off_from, Here.y) to ($2.x + off_to, Here.y) $3 " ";
150
+ }
151
+ }
152
+
153
+ # Display a lifeline constraint(object,label)
154
+ define lifeline_constraint {
155
+ off_from = awid;
156
+ # add half a box width for each level of nesting
157
+ if (active_$1 > 1) then {
158
+ off_from = off_from + (active_$1 - 1) * awid/2;
159
+ }
160
+
161
+ box at ($1.x + off_from, Here.y) invis $2 ljust " " ;
162
+ }
163
+
164
+ define lconstraint {
165
+ lifeline_constraint($1,$2);
166
+ }
167
+
168
+ # Display an object constraint(label)
169
+ # for the last object drawn
170
+ define object_constraint {
171
+ { box invis with .s at last box .nw $1 ljust; }
172
+ }
173
+
174
+ define oconstraint {
175
+ object_constraint($1);
176
+ }
177
+
178
+ # Draw a creation message(from_object,to_object,object_label)
179
+ define create_message {
180
+ down;
181
+ move spacing;
182
+ if ($1.x <= $2.x) then {
183
+ off_from = awid * .6;
184
+ off_to = -boxwid * .51;
185
+ } else {
186
+ off_from = -awid * .6;
187
+ off_to = boxwid * .51;
188
+ }
189
+
190
+ # add half a box width for each level of nesting
191
+ if (active_$1 > 1) then {
192
+ off_from = off_from + (active_$1 - 1) * awid/2;
193
+ }
194
+
195
+ # See comment in destroy_message
196
+ XSEQA: arrow from ($1.x + off_from, Here.y) to ($2.x + off_to, Here.y) "<<create>>" " ";
197
+ if ($1.x <= $2.x) then {
198
+ { XSEQB: box invis $3 with .w at XSEQA.end; }
199
+ } else {
200
+ { XSEQB: box invis $3 with .e at XSEQA.end; }
201
+ }
202
+ {
203
+ line from XSEQB.w + (.1, boxht * -.3) to XSEQB.e + (-.1, boxht * -.3);
204
+ }
205
+ lifestart_$2 = XSEQB.s.y;
206
+ move (spacing + boxht) / 2;
207
+ }
208
+
209
+ define cmessage {
210
+ create_message($1,$2,$3);
211
+ }
212
+
213
+ # Draw an X for a given object
214
+ define drawx {
215
+ {
216
+ line from($1.x - awid, lifestart_$1 - awid) to ($1.x + awid, lifestart_$1 + awid);
217
+ line from($1.x - awid, lifestart_$1 + awid) to ($1.x + awid, lifestart_$1 - awid);
218
+ }
219
+ }
220
+
221
+ # Draw a destroy message(from_object,to_object)
222
+ define destroy_message {
223
+ down;
224
+ move spacing;
225
+ # The troff code is \(Fo \(Fc
226
+ # The groff code is also \[Fo] \[Fc]
227
+ # The pic2plot code is \Fo \Fc
228
+ # See http://www.delorie.com/gnu/docs/plotutils/plotutils_71.html
229
+ # To stay compatible with all we have to hardcode the characters
230
+ message($1,$2,"<<destroy>>");
231
+ complete($2);
232
+ drawx($2);
233
+ }
234
+
235
+ define dmessage {
236
+ destroy_message($1,$2);
237
+ }
238
+
239
+ # An object deletes itself: delete(object)
240
+ define delete {
241
+ complete($1);
242
+ lifestart_$1 = lifestart_$1 - awid;
243
+ drawx($1);
244
+ }
245
+
246
+ # Draw a message return(from_object,to_object,label)
247
+ define return_message {
248
+ down;
249
+ move spacing;
250
+ # See comment in message
251
+ if ($1.x <= $2.x) then {
252
+ off_from = awid * .6;
253
+ off_to = -awid * .6;
254
+ } else {
255
+ off_from = -awid * .6;
256
+ off_to = awid * .6;
257
+ }
258
+
259
+ # add half a box width for each level of nesting
260
+ if (active_$1 > 1) then {
261
+ off_from = off_from + (active_$1 - 1) * awid/2;
262
+ }
263
+
264
+ # add half a box width for each level of nesting
265
+ if (active_$2 > 1) then {
266
+ off_to = off_to + (active_$2 - 1) * awid/2;
267
+ }
268
+
269
+ if ($1.x == $2.x) then {
270
+ arrow from ($1.x + off_from, Here.y) dashed right then down .25 then left $3 ljust " " " " " " ;
271
+ } else {
272
+ arrow from ($1.x + off_from, Here.y) to ($2.x + off_to, Here.y) dashed $3 " ";
273
+ }
274
+ }
275
+
276
+ define rmessage {
277
+ return_message($1,$2,$3);
278
+ }
279
+ define r_message {
280
+ return_message($2,$1,$3);
281
+ inactive($2);
282
+ }
283
+ define s_message {
284
+ message($1,$2,$3);
285
+ active($2);
286
+ }
287
+ define c_message {
288
+ create_message($1,$2,$3)
289
+ active($2);
290
+ }
291
+
292
+
293
+ # Object becomes active
294
+ # Can be nested to show recursion
295
+ define active {
296
+ extend_lifeline($1);
297
+ # draw top of new active box
298
+ line right awid from ($1.x + (active_$1 - 1) * awid/2, Here.y);
299
+ active_$1 = active_$1 + 1;
300
+ }
301
+
302
+ # Object becomes inactive
303
+ # Can be nested to show recursion
304
+ define inactive {
305
+ extend_lifeline($1);
306
+ active_$1 = active_$1 - 1;
307
+ # draw bottom of innermost active box
308
+ line right awid from ($1.x + (active_$1 - 1) * awid/2, Here.y);
309
+ }
310
+
311
+ # Time step
312
+ # Useful at the beginning and the end
313
+ # to show object states
314
+ define step {
315
+ down;
316
+ move spacing;
317
+ }
318
+
319
+ # Switch to asynchronous messages
320
+ define async {
321
+ arrowhead = 0;
322
+ arrowwid = arrowwid * 2;
323
+ }
324
+
325
+ # Switch to synchronous messages
326
+ define sync {
327
+ arrowhead = 1;
328
+ arrowwid = arrowwid / 2;
329
+ }
330
+
331
+ # same as lifeline_constraint, but Text and empty string are exchanged.
332
+ define lconstraint_below{
333
+ off_from = awid;
334
+ # add half a box width for each level of nesting
335
+ if (active_$1 > 1) then {
336
+ off_from = off_from + (active_$1 - 1) * awid/2;
337
+ }
338
+
339
+ box at ($1.x + off_from, Here.y) invis "" $2 ljust;
340
+ }
341
+
342
+ # begin_frame(left_object,name,label_text);
343
+ define begin_frame {
344
+ # The lifeline will be cut here
345
+ extend_lifeline($1);
346
+ # draw the frame-label
347
+ $2: box $3 invis with .n at ($1.x, Here.y);
348
+ d = $2.e.y - $2.se.y;
349
+ line from $2.ne to $2.e then down d left d then to $2.sw;
350
+ # continue the lifeline below the frame-label
351
+ move to $2.s;
352
+ lifestart_$1 = Here.y;
353
+ }
354
+
355
+ # end_frame(right_object,name);
356
+ define end_frame {
357
+ # dummy-box for the lower right corner:
358
+ box invis "" with .s at ($1.x, Here.y);
359
+ # draw the frame
360
+ frame_wid = last box.se.x - $2.nw.x
361
+ frame_ht = - last box.se.y + $2.nw.y
362
+ box with .nw at $2.nw wid frame_wid ht frame_ht;
363
+ # restore Here.y
364
+ move to last box.s;
365
+ }
366
+
367
+ # comment(object,[name],[line_movement], [box_size] text);
368
+ define comment {
369
+ old_y = Here.y
370
+ # draw the first connecting line, at which's end the box wil be positioned
371
+ move to ($1.x, Here.y)
372
+ if "$3" == "" then {
373
+ line comment_default_move() dashed;
374
+ } else {
375
+ line $3 dashed;
376
+ }
377
+
378
+ # draw the box, use comment_default_xx if no explicit
379
+ # size is given together with the text in parameter 4
380
+ old_boxht=boxht;
381
+ old_boxwid=boxwid;
382
+ boxht=comment_default_ht;
383
+ boxwid=comment_default_wid;
384
+ if "$2" == "" then {
385
+ box invis $4;
386
+ } else {
387
+ $2: box invis $4;
388
+ }
389
+ boxht=old_boxht;
390
+ boxwid=old_boxwid;
391
+
392
+ # draw the frame of the comment
393
+ line from last box.nw \
394
+ to last box.ne - (corner_fold, 0) \
395
+ then to last box.ne - (0, corner_fold) \
396
+ then to last box.se \
397
+ then to last box.sw \
398
+ then to last box.nw ;
399
+ line from last box.ne - (corner_fold, 0) \
400
+ to last box.ne - (corner_fold, corner_fold) \
401
+ then to last box.ne - (0, corner_fold) ;
402
+
403
+ # restore Here.y
404
+ move to ($1.x, old_y)
405
+ }
406
+
407
+ # connect_to_comment(object,name);
408
+ define connect_to_comment {
409
+ old_y = Here.y
410
+ # start at the object
411
+ move to ($1.x, Here.y)
412
+ # find the best connection-point of the comment to use as line-end
413
+ if $1.x < $2.w.x then {
414
+ line to $2.w dashed;
415
+ } else {
416
+ if $1.x > $2.e.x then {
417
+ line to $2.e dashed;
418
+ } else {
419
+ if Here.y < $2.s.y then {
420
+ line to $2.s dashed;
421
+ } else {
422
+ if Here.y > $2.n.y then {
423
+ line to $2.n dashed;
424
+ }
425
+ }
426
+ }
427
+ }
428
+ # restore Here.y
429
+ move to ($1.x, old_y)
430
+ }
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+ set -x
3
+ dir="$(cd "$(dirname $0)" && /bin/pwd)"
4
+ PATH="$dir/../bin:$PATH"
5
+ export RUBYLIB="$dir/../example:$dir/../lib"
6
+ asir="asir verbose=9 config_rb=$dir/config/asir_config.rb"
7
+
8
+ # set -e
9
+ $asir start webrick worker
10
+ sleep 1
11
+
12
+ ruby "$dir/asir_control_client_http.rb"
13
+ sleep 1
14
+
15
+ $asir stop webrick worker
16
+ sleep 1
17
+
18
+ $asir start zmq worker
19
+ sleep 1
20
+
21
+ ruby "$dir/asir_control_client_zmq.rb"
22
+ sleep 1
23
+
24
+ exit 0