ezmq 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -187,30 +187,6 @@
187
187
  <p>Creates a new Subscriber socket.</p>
188
188
  </div></span>
189
189
 
190
- </li>
191
-
192
-
193
- <li class="public ">
194
- <span class="summary_signature">
195
-
196
- <a href="#listen-instance_method" title="#listen (instance method)">- (void) <strong>listen</strong> {|message| ... }</a>
197
-
198
-
199
-
200
- </span>
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
- <span class="summary_desc"><div class='inline'>
211
- <p>By default, waits for a message and prints it to STDOUT.</p>
212
- </div></span>
213
-
214
190
  </li>
215
191
 
216
192
 
@@ -275,7 +251,7 @@
275
251
 
276
252
 
277
253
  <h3 class="inherited">Methods inherited from <span class='object_link'><a href="Socket.html" title="EZMQ::Socket (class)">Socket</a></span></h3>
278
- <p class="inherited"><span class='object_link'><a href="Socket.html#bind-instance_method" title="EZMQ::Socket#bind (method)">#bind</a></span>, <span class='object_link'><a href="Socket.html#connect-instance_method" title="EZMQ::Socket#connect (method)">#connect</a></span>, <span class='object_link'><a href="Socket.html#receive-instance_method" title="EZMQ::Socket#receive (method)">#receive</a></span>, <span class='object_link'><a href="Socket.html#send-instance_method" title="EZMQ::Socket#send (method)">#send</a></span></p>
254
+ <p class="inherited"><span class='object_link'><a href="Socket.html#bind-instance_method" title="EZMQ::Socket#bind (method)">#bind</a></span>, <span class='object_link'><a href="Socket.html#connect-instance_method" title="EZMQ::Socket#connect (method)">#connect</a></span>, <span class='object_link'><a href="Socket.html#listen-instance_method" title="EZMQ::Socket#listen (method)">#listen</a></span>, <span class='object_link'><a href="Socket.html#receive-instance_method" title="EZMQ::Socket#receive (method)">#receive</a></span>, <span class='object_link'><a href="Socket.html#send-instance_method" title="EZMQ::Socket#send (method)">#send</a></span></p>
279
255
  <div id="constructor_details" class="method_details_list">
280
256
  <h2>Constructor Details</h2>
281
257
 
@@ -362,13 +338,13 @@
362
338
  <pre class="lines">
363
339
 
364
340
 
365
- 218
366
- 219
367
- 220
368
- 221</pre>
341
+ 232
342
+ 233
343
+ 234
344
+ 235</pre>
369
345
  </td>
370
346
  <td>
371
- <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 218</span>
347
+ <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 232</span>
372
348
 
373
349
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
374
350
  <span class='kw'>super</span> <span class='symbol'>:connect</span><span class='comma'>,</span> <span class='const'>ZMQ</span><span class='op'>::</span><span class='const'>SUB</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span>
@@ -412,12 +388,12 @@
412
388
  <pre class="lines">
413
389
 
414
390
 
415
- 206
416
- 207
417
- 208</pre>
391
+ 220
392
+ 221
393
+ 222</pre>
418
394
  </td>
419
395
  <td>
420
- <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 206</span>
396
+ <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 220</span>
421
397
 
422
398
  <span class='kw'>def</span> <span class='id identifier rubyid_action'>action</span>
423
399
  <span class='ivar'>@action</span>
@@ -435,98 +411,7 @@
435
411
 
436
412
 
437
413
  <div class="method_details first">
438
- <h3 class="signature first" id="listen-instance_method">
439
-
440
- - (<tt>void</tt>) <strong>listen</strong> {|message| ... }
441
-
442
-
443
-
444
-
445
-
446
- </h3><div class="docstring">
447
- <div class="discussion">
448
- <p class="note returns_void">This method returns an undefined value.</p>
449
- <p>By default, waits for a message and prints it to STDOUT.</p>
450
-
451
-
452
- </div>
453
- </div>
454
- <div class="tags">
455
-
456
- <p class="tag_title">Yields:</p>
457
- <ul class="yield">
458
-
459
- <li>
460
-
461
-
462
- <span class='type'></span>
463
-
464
-
465
-
466
-
467
- <div class='inline'>
468
- <p>message passes the message received to the block.</p>
469
- </div>
470
-
471
- </li>
472
-
473
- </ul>
474
- <p class="tag_title">Yield Parameters:</p>
475
- <ul class="yieldparam">
476
-
477
- <li>
478
-
479
- <span class='name'>message</span>
480
-
481
-
482
- <span class='type'>(<tt>String</tt>)</span>
483
-
484
-
485
-
486
- &mdash;
487
- <div class='inline'>
488
- <p>the message received.</p>
489
- </div>
490
-
491
- </li>
492
-
493
- </ul>
494
-
495
- </div><table class="source_code">
496
- <tr>
497
- <td>
498
- <pre class="lines">
499
-
500
-
501
- 256
502
- 257
503
- 258
504
- 259
505
- 260
506
- 261
507
- 262
508
- 263
509
- 264</pre>
510
- </td>
511
- <td>
512
- <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 256</span>
513
-
514
- <span class='kw'>def</span> <span class='id identifier rubyid_listen'>listen</span>
515
- <span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span>
516
- <span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
517
- <span class='kw'>yield</span> <span class='id identifier rubyid_receive'>receive</span>
518
- <span class='kw'>else</span>
519
- <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_receive'>receive</span>
520
- <span class='kw'>end</span>
521
- <span class='kw'>end</span>
522
- <span class='kw'>end</span></pre>
523
- </td>
524
- </tr>
525
- </table>
526
- </div>
527
-
528
- <div class="method_details ">
529
- <h3 class="signature " id="subscribe-instance_method">
414
+ <h3 class="signature first" id="subscribe-instance_method">
530
415
 
531
416
  - (<tt>Boolean</tt>) <strong>subscribe</strong>(topic)
532
417
 
@@ -602,12 +487,12 @@ provided, #initialize calls #subscribe automatically.</p>
602
487
  <pre class="lines">
603
488
 
604
489
 
605
- 234
606
- 235
607
- 236</pre>
490
+ 248
491
+ 249
492
+ 250</pre>
608
493
  </td>
609
494
  <td>
610
- <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 234</span>
495
+ <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 248</span>
611
496
 
612
497
  <span class='kw'>def</span> <span class='id identifier rubyid_subscribe'>subscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_topic'>topic</span><span class='rparen'>)</span>
613
498
  <span class='ivar'>@socket</span><span class='period'>.</span><span class='id identifier rubyid_setsockopt'>setsockopt</span><span class='lparen'>(</span><span class='const'>ZMQ</span><span class='op'>::</span><span class='const'>SUBSCRIBE</span><span class='comma'>,</span> <span class='id identifier rubyid_topic'>topic</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='int'>0</span>
@@ -682,12 +567,12 @@ set, this will only remove one.</p>
682
567
  <pre class="lines">
683
568
 
684
569
 
685
- 245
686
- 246
687
- 247</pre>
570
+ 259
571
+ 260
572
+ 261</pre>
688
573
  </td>
689
574
  <td>
690
- <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 245</span>
575
+ <pre class="code"><span class="info file"># File 'lib/ezmq.rb', line 259</span>
691
576
 
692
577
  <span class='kw'>def</span> <span class='id identifier rubyid_unsubscribe'>unsubscribe</span><span class='lparen'>(</span><span class='id identifier rubyid_topic'>topic</span><span class='rparen'>)</span>
693
578
  <span class='ivar'>@socket</span><span class='period'>.</span><span class='id identifier rubyid_setsockopt'>setsockopt</span><span class='lparen'>(</span><span class='const'>ZMQ</span><span class='op'>::</span><span class='const'>UNSUBSCRIBE</span><span class='comma'>,</span> <span class='id identifier rubyid_topic'>topic</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='int'>0</span>
@@ -702,7 +587,7 @@ set, this will only remove one.</p>
702
587
  </div>
703
588
 
704
589
  <div id="footer">
705
- Generated on Fri Jan 9 13:06:27 2015 by
590
+ Generated on Sun Jan 11 14:20:10 2015 by
706
591
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
707
592
  0.8.7.6 (ruby-2.0.0).
708
593
  </div>
@@ -119,6 +119,20 @@
119
119
 
120
120
  </li>
121
121
 
122
+ <li>
123
+ <span class='object_link'><a href="EZMQ/Puller.html" title="EZMQ::Puller (class)">Puller</a></span>
124
+
125
+ <small>(EZMQ)</small>
126
+
127
+ </li>
128
+
129
+ <li>
130
+ <span class='object_link'><a href="EZMQ/Pusher.html" title="EZMQ::Pusher (class)">Pusher</a></span>
131
+
132
+ <small>(EZMQ)</small>
133
+
134
+ </li>
135
+
122
136
  </ul>
123
137
  </ul>
124
138
 
@@ -160,7 +174,7 @@
160
174
  </div>
161
175
 
162
176
  <div id="footer">
163
- Generated on Fri Jan 9 13:06:26 2015 by
177
+ Generated on Sun Jan 11 14:20:10 2015 by
164
178
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
165
179
  0.8.7.6 (ruby-2.0.0).
166
180
  </div>
@@ -50,7 +50,7 @@
50
50
 
51
51
  <ul id="full_list" class="class">
52
52
  <li><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></li>
53
- <li><a class='toggle'></a> <span class='object_link'><a href="EZMQ.html" title="EZMQ (module)">EZMQ</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="EZMQ/Client.html" title="EZMQ::Client (class)">Client</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Publisher.html" title="EZMQ::Publisher (class)">Publisher</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Server.html" title="EZMQ::Server (class)">Server</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Socket.html" title="EZMQ::Socket (class)">Socket</a></span> &lt; Object<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Subscriber.html" title="EZMQ::Subscriber (class)">Subscriber</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li></ul>
53
+ <li><a class='toggle'></a> <span class='object_link'><a href="EZMQ.html" title="EZMQ (module)">EZMQ</a></span><small class='search_info'>Top Level Namespace</small></li><ul><li><span class='object_link'><a href="EZMQ/Client.html" title="EZMQ::Client (class)">Client</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Publisher.html" title="EZMQ::Publisher (class)">Publisher</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Puller.html" title="EZMQ::Puller (class)">Puller</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Pusher.html" title="EZMQ::Pusher (class)">Pusher</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Server.html" title="EZMQ::Server (class)">Server</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Socket.html" title="EZMQ::Socket (class)">Socket</a></span> &lt; Object<small class='search_info'>EZMQ</small></li><li><span class='object_link'><a href="EZMQ/Subscriber.html" title="EZMQ::Subscriber (class)">Subscriber</a></span> &lt; Socket<small class='search_info'>EZMQ</small></li></ul>
54
54
 
55
55
  </ul>
56
56
  </div>
@@ -97,25 +97,25 @@
97
97
 
98
98
  <p>Waits for a request, prints it to STDOUT, and thanks the client for it.</p>
99
99
 
100
- <pre class="code ruby"><code class="ruby">require &#39;ezmq&#39;
101
-
102
- server = EZMQ::Server.new
103
- server.listen do |message|
104
- puts message
105
- &#39;Thanks for the message!&#39; # The return of the block is sent to the client.
106
- end
100
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
107
101
 
108
- JSON Echo Server
109
- ----------------
110
- Waits for JSON message, decodes it, re-encodes it, and sends it back.
102
+ <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
103
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
104
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_message'>message</span>
105
+ <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Thanks for the message!</span><span class='tstring_end'>&#39;</span></span> <span class='comment'># The return of the block is sent to the client.
106
+ </span><span class='kw'>end</span>
111
107
  </code></pre>
112
108
 
113
- <p>require 'ezmq'
114
- require 'json'</p>
109
+ <h2>JSON Echo Server</h2>
115
110
 
116
- <p>server = EZMQ::Server.new encode: -> m { JSON.dump m }, decode: -> m { JSON.load m }
117
- server.listen
118
- ```</p>
111
+ <p>Waits for JSON message, decodes it, re-encodes it, and sends it back.</p>
112
+
113
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
114
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
115
+
116
+ <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>decode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
117
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
118
+ </code></pre>
119
119
 
120
120
  <h2>JSON Synchronous Client Request</h2>
121
121
 
@@ -153,6 +153,60 @@ server.listen
153
153
  <span class='id identifier rubyid_subscriber'>subscriber</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
154
154
  </code></pre>
155
155
 
156
+ <h2>Pipeline Work Generator</h2>
157
+
158
+ <p>Generates work, distributes it to workers via PUSH socket.</p>
159
+
160
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
161
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
162
+
163
+ <span class='id identifier rubyid_generator'>generator</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Pusher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:bind</span><span class='comma'>,</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
164
+
165
+ <span class='int'>15</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_id'>id</span><span class='op'>|</span>
166
+ <span class='id identifier rubyid_work'>work</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>id</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>task_</span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_id'>id</span> <span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>request</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>100</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
167
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Generated work </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_work'>work</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
168
+ <span class='id identifier rubyid_generator'>generator</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='id identifier rubyid_work'>work</span>
169
+ <span class='kw'>end</span>
170
+ </code></pre>
171
+
172
+ <h2>Pipeline Workers</h2>
173
+
174
+ <p>3 worker threads PULL work from the Generator and PUSH results to the Collector.</p>
175
+
176
+ <p>The 'work' here is generating a random number between 1 and a requested maximum.</p>
177
+
178
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
179
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
180
+
181
+ <span class='id identifier rubyid_workers'>workers</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
182
+
183
+ <span class='int'>3</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_id'>id</span><span class='op'>|</span>
184
+ <span class='id identifier rubyid_workers'>workers</span> <span class='op'>&lt;&lt;</span> <span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
185
+ <span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Puller</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:connect</span><span class='comma'>,</span> <span class='label'>decode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
186
+ <span class='id identifier rubyid_output'>output</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Pusher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>port:</span> <span class='int'>5556</span><span class='comma'>,</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
187
+ <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_work'>work</span><span class='op'>|</span>
188
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Worker </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_content'> pulled </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_work'>work</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
189
+ <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_rand'>rand</span><span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='id identifier rubyid_work'>work</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>request</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='rparen'>)</span>
190
+ <span class='id identifier rubyid_report'>report</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>id</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_work'>work</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>id</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_result'>result</span> <span class='rbrace'>}</span>
191
+ <span class='id identifier rubyid_output'>output</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='id identifier rubyid_report'>report</span>
192
+ <span class='kw'>end</span>
193
+ <span class='kw'>end</span>
194
+ <span class='kw'>end</span>
195
+
196
+ <span class='id identifier rubyid_workers'>workers</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:join</span><span class='rparen'>)</span>
197
+ </code></pre>
198
+
199
+ <h2>Pipeline Results Collector</h2>
200
+
201
+ <p>PULLs results from workers and prints it to STDOUT.</p>
202
+
203
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
204
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
205
+
206
+ <span class='id identifier rubyid_collector'>collector</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Puller</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>port:</span> <span class='int'>5556</span>
207
+ <span class='id identifier rubyid_collector'>collector</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
208
+ </code></pre>
209
+
156
210
  <h1>Operating System Notes</h1>
157
211
 
158
212
  <p>As this relies on <a href="https://github.com/chuckremes/ffi-rzmq">ffi-rzmq</a>, you will need to have the zeromq libraries available.</p>
@@ -172,7 +226,7 @@ sudo aptitude install libzmq3-dev
172
226
  </div></div>
173
227
 
174
228
  <div id="footer">
175
- Generated on Fri Jan 9 13:06:26 2015 by
229
+ Generated on Sun Jan 11 14:20:10 2015 by
176
230
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
177
231
  0.8.7.6 (ruby-2.0.0).
178
232
  </div>
@@ -97,25 +97,25 @@
97
97
 
98
98
  <p>Waits for a request, prints it to STDOUT, and thanks the client for it.</p>
99
99
 
100
- <pre class="code ruby"><code class="ruby">require &#39;ezmq&#39;
101
-
102
- server = EZMQ::Server.new
103
- server.listen do |message|
104
- puts message
105
- &#39;Thanks for the message!&#39; # The return of the block is sent to the client.
106
- end
100
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
107
101
 
108
- JSON Echo Server
109
- ----------------
110
- Waits for JSON message, decodes it, re-encodes it, and sends it back.
102
+ <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
103
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_message'>message</span><span class='op'>|</span>
104
+ <span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_message'>message</span>
105
+ <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>Thanks for the message!</span><span class='tstring_end'>&#39;</span></span> <span class='comment'># The return of the block is sent to the client.
106
+ </span><span class='kw'>end</span>
111
107
  </code></pre>
112
108
 
113
- <p>require 'ezmq'
114
- require 'json'</p>
109
+ <h2>JSON Echo Server</h2>
115
110
 
116
- <p>server = EZMQ::Server.new encode: -> m { JSON.dump m }, decode: -> m { JSON.load m }
117
- server.listen
118
- ```</p>
111
+ <p>Waits for JSON message, decodes it, re-encodes it, and sends it back.</p>
112
+
113
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
114
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
115
+
116
+ <span class='id identifier rubyid_server'>server</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Server</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>decode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
117
+ <span class='id identifier rubyid_server'>server</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
118
+ </code></pre>
119
119
 
120
120
  <h2>JSON Synchronous Client Request</h2>
121
121
 
@@ -153,6 +153,60 @@ server.listen
153
153
  <span class='id identifier rubyid_subscriber'>subscriber</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
154
154
  </code></pre>
155
155
 
156
+ <h2>Pipeline Work Generator</h2>
157
+
158
+ <p>Generates work, distributes it to workers via PUSH socket.</p>
159
+
160
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
161
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
162
+
163
+ <span class='id identifier rubyid_generator'>generator</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Pusher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:bind</span><span class='comma'>,</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
164
+
165
+ <span class='int'>15</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_id'>id</span><span class='op'>|</span>
166
+ <span class='id identifier rubyid_work'>work</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>id</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>task_</span><span class='embexpr_beg'>#{</span> <span class='id identifier rubyid_id'>id</span> <span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>request</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>100</span><span class='tstring_end'>&#39;</span></span> <span class='rbrace'>}</span>
167
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Generated work </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_work'>work</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
168
+ <span class='id identifier rubyid_generator'>generator</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='id identifier rubyid_work'>work</span>
169
+ <span class='kw'>end</span>
170
+ </code></pre>
171
+
172
+ <h2>Pipeline Workers</h2>
173
+
174
+ <p>3 worker threads PULL work from the Generator and PUSH results to the Collector.</p>
175
+
176
+ <p>The 'work' here is generating a random number between 1 and a requested maximum.</p>
177
+
178
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
179
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
180
+
181
+ <span class='id identifier rubyid_workers'>workers</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
182
+
183
+ <span class='int'>3</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_id'>id</span><span class='op'>|</span>
184
+ <span class='id identifier rubyid_workers'>workers</span> <span class='op'>&lt;&lt;</span> <span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
185
+ <span class='id identifier rubyid_input'>input</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Puller</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='symbol'>:connect</span><span class='comma'>,</span> <span class='label'>decode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
186
+ <span class='id identifier rubyid_output'>output</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Pusher</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>port:</span> <span class='int'>5556</span><span class='comma'>,</span> <span class='label'>encode:</span> <span class='tlambda'>-&gt;</span> <span class='id identifier rubyid_m'>m</span> <span class='tlambeg'>{</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span> <span class='id identifier rubyid_m'>m</span> <span class='rbrace'>}</span>
187
+ <span class='id identifier rubyid_input'>input</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_work'>work</span><span class='op'>|</span>
188
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Worker </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_content'> pulled </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_work'>work</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
189
+ <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_rand'>rand</span><span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='id identifier rubyid_work'>work</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>request</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='rparen'>)</span>
190
+ <span class='id identifier rubyid_report'>report</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>id</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_work'>work</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>id</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>result</span><span class='tstring_end'>&#39;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_result'>result</span> <span class='rbrace'>}</span>
191
+ <span class='id identifier rubyid_output'>output</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='id identifier rubyid_report'>report</span>
192
+ <span class='kw'>end</span>
193
+ <span class='kw'>end</span>
194
+ <span class='kw'>end</span>
195
+
196
+ <span class='id identifier rubyid_workers'>workers</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:join</span><span class='rparen'>)</span>
197
+ </code></pre>
198
+
199
+ <h2>Pipeline Results Collector</h2>
200
+
201
+ <p>PULLs results from workers and prints it to STDOUT.</p>
202
+
203
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ezmq</span><span class='tstring_end'>&#39;</span></span>
204
+ <span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>json</span><span class='tstring_end'>&#39;</span></span>
205
+
206
+ <span class='id identifier rubyid_collector'>collector</span> <span class='op'>=</span> <span class='const'>EZMQ</span><span class='op'>::</span><span class='const'>Puller</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='label'>port:</span> <span class='int'>5556</span>
207
+ <span class='id identifier rubyid_collector'>collector</span><span class='period'>.</span><span class='id identifier rubyid_listen'>listen</span>
208
+ </code></pre>
209
+
156
210
  <h1>Operating System Notes</h1>
157
211
 
158
212
  <p>As this relies on <a href="https://github.com/chuckremes/ffi-rzmq">ffi-rzmq</a>, you will need to have the zeromq libraries available.</p>
@@ -172,7 +226,7 @@ sudo aptitude install libzmq3-dev
172
226
  </div></div>
173
227
 
174
228
  <div id="footer">
175
- Generated on Fri Jan 9 13:06:26 2015 by
229
+ Generated on Sun Jan 11 14:20:10 2015 by
176
230
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
177
231
  0.8.7.6 (ruby-2.0.0).
178
232
  </div>