slave 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: @object</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <h1>@object <sup class="type-note">(Class)</sup></h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>In:</strong></td>
54
+ <td>
55
+ <a href="../files/lib/slave_rb.html">
56
+ lib/slave.rb
57
+ </a>
58
+ <br />
59
+ </td>
60
+ </tr>
61
+
62
+ </table>
63
+ </div>
64
+ <!-- banner header -->
65
+
66
+ <div id="bodyContent">
67
+
68
+
69
+ <div id="contextContent">
70
+ <div id="diagram">
71
+ <map name="map">
72
+ <area shape="RECT" coords="123,98,195,50" href=".././classes" alt="@object.html @object">
73
+ <area shape="RECT" coords="27,98,99,50" href="Slave.html" alt="Slave">
74
+ </map>
75
+ <img src="../dot/f_1.jpg" usemap="#map" border=0 alt="TopLevel">
76
+ </div>
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ <div id="attribute-list">
85
+ <h2 class="section-bar">Attributes</h2>
86
+
87
+ <div class="name-list">
88
+ <table>
89
+ <tr class="top-aligned-row context-row">
90
+ <td class="context-item-name">__slave_object_failure__</td>
91
+ <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
92
+ <td class="context-item-desc"></td>
93
+ </tr>
94
+ </table>
95
+ </div>
96
+ </div>
97
+
98
+
99
+ </div>
100
+
101
+
102
+
103
+ <!-- if includes -->
104
+
105
+
106
+ <!-- if method_list -->
107
+
108
+
109
+ </div>
110
+
111
+
112
+ <div id="validator-badges">
113
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
114
+ </div>
115
+
116
+ </body>
117
+ </html>
@@ -75,7 +75,8 @@
75
75
  <div id="contextContent">
76
76
  <div id="diagram">
77
77
  <map name="map">
78
- <area shape="RECT" coords="28,88,99,40" href="Slave.html" alt="Slave">
78
+ <area shape="RECT" coords="123,98,195,50" href="o.html" alt="o">
79
+ <area shape="RECT" coords="27,98,99,50" href="Slave.html" alt="Slave">
79
80
  </map>
80
81
  <img src="../dot/f_1.jpg" usemap="#map" border=0 alt="TopLevel">
81
82
  </div>
@@ -100,11 +101,27 @@ multi-threaded one. eg
100
101
  end
101
102
  end
102
103
 
103
- slave = Slave.new Server.new
104
+ slave = Slave.new 'object' =&gt; Server.new
104
105
  server = slave.object
105
106
 
106
107
  p server.add_two(40) #=&gt; 42
107
108
  </pre>
109
+ <p>
110
+ two other methods of providing server objects exist:
111
+ </p>
112
+ <p>
113
+ a) server = Server.new &quot;this is called the parent&quot; }
114
+ </p>
115
+ <pre>
116
+ Slave.new(:object=&gt;server){|s| puts &quot;#{ s.inspect } passed to block in child process&quot;}
117
+ </pre>
118
+ <p>
119
+ b) <a href="Slave.html#M000005">Slave.new</a>{ Server.new &quot;this is
120
+ called only in the child&quot; }
121
+ </p>
122
+ <p>
123
+ of the two &#8216;b&#8217; is preferred.
124
+ </p>
108
125
 
109
126
  </div>
110
127
 
@@ -113,16 +130,20 @@ multi-threaded one. eg
113
130
  <h2 class="section-bar">Methods</h2>
114
131
 
115
132
  <div class="name-list">
116
- <a href="#M000004">detach</a>&nbsp;&nbsp;
117
- <a href="#M000002">fork</a>&nbsp;&nbsp;
118
- <a href="#M000008">gen_psname</a>&nbsp;&nbsp;
119
- <a href="#M000001">getval</a>&nbsp;&nbsp;
120
- <a href="#M000009">getval</a>&nbsp;&nbsp;
121
- <a href="#M000003">new</a>&nbsp;&nbsp;
122
- <a href="#M000007">shutdown</a>&nbsp;&nbsp;
123
- <a href="#M000010">trace</a>&nbsp;&nbsp;
124
- <a href="#M000005">wait</a>&nbsp;&nbsp;
125
- <a href="#M000006">wait2</a>&nbsp;&nbsp;
133
+ <a href="#M000012">default</a>&nbsp;&nbsp;
134
+ <a href="#M000002">default</a>&nbsp;&nbsp;
135
+ <a href="#M000006">detach</a>&nbsp;&nbsp;
136
+ <a href="#M000004">fork</a>&nbsp;&nbsp;
137
+ <a href="#M000011">gen_psname</a>&nbsp;&nbsp;
138
+ <a href="#M000003">getopts</a>&nbsp;&nbsp;
139
+ <a href="#M000013">getopts</a>&nbsp;&nbsp;
140
+ <a href="#M000005">new</a>&nbsp;&nbsp;
141
+ <a href="#M000009">shutdown</a>&nbsp;&nbsp;
142
+ <a href="#M000010">shutdown?</a>&nbsp;&nbsp;
143
+ <a href="#M000014">trace</a>&nbsp;&nbsp;
144
+ <a href="#M000001">version</a>&nbsp;&nbsp;
145
+ <a href="#M000007">wait</a>&nbsp;&nbsp;
146
+ <a href="#M000008">wait2</a>&nbsp;&nbsp;
126
147
  </div>
127
148
  </div>
128
149
 
@@ -134,7 +155,7 @@ multi-threaded one. eg
134
155
  <tr class="top-aligned-row context-row">
135
156
  <td class="context-item-name">VERSION</td>
136
157
  <td>=</td>
137
- <td class="context-item-value">'0.0.1'</td>
158
+ <td class="context-item-value">'1.0.0'</td>
138
159
  </tr>
139
160
  <tr class="top-aligned-row context-row">
140
161
  <td class="context-item-name">DEFAULT_SOCKET_CREATION_ATTEMPTS</td>
@@ -170,7 +191,7 @@ config
170
191
  <div class="name-list">
171
192
  <table>
172
193
  <tr class="top-aligned-row context-row">
173
- <td class="context-item-name">debug</td>
194
+ <td class="context-item-name">at_exit</td>
174
195
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
175
196
  <td class="context-item-desc"></td>
176
197
  </tr>
@@ -183,6 +204,11 @@ on STDERR
183
204
 
184
205
  </td>
185
206
  </tr>
207
+ <tr class="top-aligned-row context-row">
208
+ <td class="context-item-name">debug</td>
209
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
210
+ <td class="context-item-desc"></td>
211
+ </tr>
186
212
  <tr class="top-aligned-row context-row">
187
213
  <td class="context-item-name">obj</td>
188
214
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
@@ -222,6 +248,11 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
222
248
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
223
249
  <td class="context-item-desc"></td>
224
250
  </tr>
251
+ <tr class="top-aligned-row context-row">
252
+ <td class="context-item-name">shutdown</td>
253
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
254
+ <td class="context-item-desc"></td>
255
+ </tr>
225
256
  <tr class="top-aligned-row context-row">
226
257
  <td class="context-item-name">socket</td>
227
258
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
@@ -232,6 +263,11 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
232
263
  <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
233
264
  <td class="context-item-desc"></td>
234
265
  </tr>
266
+ <tr class="top-aligned-row context-row">
267
+ <td class="context-item-name">socket_creation_attempts</td>
268
+ <td class="context-item-value">&nbsp;[R]&nbsp;</td>
269
+ <td class="context-item-desc"></td>
270
+ </tr>
235
271
  <tr class="top-aligned-row context-row">
236
272
  <td class="context-item-name">status</td>
237
273
  <td class="context-item-value">&nbsp;[R]&nbsp;</td>
@@ -269,60 +305,58 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
269
305
 
270
306
  <div class="method-heading">
271
307
  <a href="#M000002" class="method-signature">
272
- <span class="method-name">fork</span><span class="method-args">(&amp;block)</span>
308
+ <span class="method-name">default</span><span class="method-args">key</span>
273
309
  </a>
274
310
  </div>
275
311
 
276
312
  <div class="method-description">
277
313
  <p>
278
- just fork with out silly warnings
314
+ get a default value
279
315
  </p>
280
316
  <p><a class="source-toggle" href="#"
281
317
  onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
282
318
  <div class="method-source-code" id="M000002-source">
283
319
  <pre>
284
- <span class="ruby-comment cmt"># File lib/slave.rb, line 71</span>
285
- 71: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
286
- 72: <span class="ruby-comment cmt">#--{{{</span>
287
- 73: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
288
- 74: <span class="ruby-keyword kw">begin</span>
289
- 75: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-keyword kw">nil</span>
290
- 76: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
291
- 77: <span class="ruby-keyword kw">ensure</span>
292
- 78: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
293
- 79: <span class="ruby-keyword kw">end</span>
294
- 80: <span class="ruby-comment cmt">#--}}}</span>
295
- 81: <span class="ruby-keyword kw">end</span>
320
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 73</span>
321
+ 73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
322
+ 74: <span class="ruby-comment cmt">#--{{{</span>
323
+ 75: <span class="ruby-identifier">send</span> <span class="ruby-identifier">key</span>
324
+ 76: <span class="ruby-comment cmt">#--}}}</span>
325
+ 77: <span class="ruby-keyword kw">end</span>
296
326
  </pre>
297
327
  </div>
298
328
  </div>
299
329
  </div>
300
330
 
301
- <div id="method-M000001" class="method-detail">
302
- <a name="M000001"></a>
331
+ <div id="method-M000004" class="method-detail">
332
+ <a name="M000004"></a>
303
333
 
304
334
  <div class="method-heading">
305
- <a href="#M000001" class="method-signature">
306
- <span class="method-name">getval</span><span class="method-args">key, opts = {}</span>
335
+ <a href="#M000004" class="method-signature">
336
+ <span class="method-name">fork</span><span class="method-args">(&amp;block)</span>
307
337
  </a>
308
338
  </div>
309
339
 
310
340
  <div class="method-description">
311
341
  <p>
312
- look up a value in an option hash failing back to class defaults
342
+ just fork with out silly warnings
313
343
  </p>
314
344
  <p><a class="source-toggle" href="#"
315
- onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
316
- <div class="method-source-code" id="M000001-source">
345
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
346
+ <div class="method-source-code" id="M000004-source">
317
347
  <pre>
318
- <span class="ruby-comment cmt"># File lib/slave.rb, line 63</span>
319
- 63: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getval</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">opts</span> = {}
320
- 64: <span class="ruby-comment cmt">#--{{{</span>
321
- 65: <span class="ruby-identifier">keys</span> = [<span class="ruby-identifier">key</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">intern</span>]
322
- 66: <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">k</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">k</span>)}
323
- 67: <span class="ruby-identifier">send</span> <span class="ruby-identifier">key</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
324
- 68: <span class="ruby-comment cmt">#--}}}</span>
325
- 69: <span class="ruby-keyword kw">end</span>
348
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 94</span>
349
+ 94: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
350
+ 95: <span class="ruby-comment cmt">#--{{{</span>
351
+ 96: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
352
+ 97: <span class="ruby-keyword kw">begin</span>
353
+ 98: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-keyword kw">nil</span>
354
+ 99: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span> <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
355
+ 100: <span class="ruby-keyword kw">ensure</span>
356
+ 101: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
357
+ 102: <span class="ruby-keyword kw">end</span>
358
+ 103: <span class="ruby-comment cmt">#--}}}</span>
359
+ 104: <span class="ruby-keyword kw">end</span>
326
360
  </pre>
327
361
  </div>
328
362
  </div>
@@ -333,120 +367,233 @@ look up a value in an option hash failing back to class defaults
333
367
 
334
368
  <div class="method-heading">
335
369
  <a href="#M000003" class="method-signature">
336
- <span class="method-name">new</span><span class="method-args">obj = nil, opts = {}, &amp;block</span>
370
+ <span class="method-name">getopts</span><span class="method-args">opts</span>
337
371
  </a>
338
372
  </div>
339
373
 
340
374
  <div class="method-description">
341
- <p>
342
- &#8216;obj&#8217; can be any object and &#8216;opts&#8217; may contain the
343
- keys &#8216;socket_creation_attempts&#8217;, &#8216;pulse_rate&#8217;,
344
- &#8216;psname&#8217;, or &#8216;debug&#8217;
345
- </p>
346
375
  <p><a class="source-toggle" href="#"
347
376
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
348
377
  <div class="method-source-code" id="M000003-source">
349
378
  <pre>
350
- <span class="ruby-comment cmt"># File lib/slave.rb, line 100</span>
351
- 100: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">obj</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
352
- 101: <span class="ruby-comment cmt">#--{{{</span>
353
- 102: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">obj</span>
354
- 103:
355
- 104: <span class="ruby-ivar">@socket_creation_attempts</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'socket_creation_attempts'</span>, <span class="ruby-identifier">opts</span>)
356
- 105: <span class="ruby-ivar">@pulse_rate</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'pulse_rate'</span>, <span class="ruby-identifier">opts</span>)
357
- 106: <span class="ruby-ivar">@debug</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'debug'</span>, <span class="ruby-identifier">opts</span>)
358
- 107: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'psname'</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@obj</span>)
359
- 108:
360
- 109: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;socket_creation_attempts &lt;#{ @socket_creation_attempts }&gt;&quot;</span> }
361
- 110: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;pulse_rate &lt;#{ @pulse_rate }&gt;&quot;</span> }
362
- 111: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;psname &lt;#{ @psname }&gt;&quot;</span> }
363
- 112:
364
- 113: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
365
- 114: <span class="ruby-ivar">@waiter</span> = <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
366
- 115:
367
- 116: <span class="ruby-ivar">@heartbeat</span> = <span class="ruby-constant">Heartbeat</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-ivar">@pulse_rate</span>, <span class="ruby-ivar">@debug</span>
368
- 117: <span class="ruby-ivar">@r</span>, <span class="ruby-ivar">@w</span> = <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-identifier">pipe</span>
369
- 118: <span class="ruby-comment cmt">#</span>
370
- 119: <span class="ruby-comment cmt"># child</span>
371
- 120: <span class="ruby-comment cmt">#</span>
372
- 121: <span class="ruby-keyword kw">unless</span>((<span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Slave</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span>))
373
- 122: <span class="ruby-identifier">e</span> = <span class="ruby-keyword kw">nil</span>
374
- 123: <span class="ruby-keyword kw">begin</span>
375
- 124: <span class="ruby-identifier">$0</span> = <span class="ruby-ivar">@psname</span>
376
- 125: <span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">pid</span>
377
- 126: <span class="ruby-ivar">@ppid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">ppid</span>
378
- 127:
379
- 128: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
380
- 129: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
381
- 130: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
379
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 79</span>
380
+ 79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
381
+ 80: <span class="ruby-comment cmt">#--{{{</span>
382
+ 81: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">class</span> <span class="ruby-keyword kw">unless</span>
383
+ 82: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'has_key?'</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'[]'</span>)
384
+ 83:
385
+ 84: <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">defval</span><span class="ruby-operator">|</span>
386
+ 85: <span class="ruby-identifier">defval</span> = <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">shift</span>
387
+ 86: <span class="ruby-identifier">keys</span> = [<span class="ruby-identifier">key</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">intern</span>]
388
+ 87: <span class="ruby-identifier">key</span> = <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">detect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">k</span> } <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">break</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">key</span>]
389
+ 88: <span class="ruby-identifier">defval</span>
390
+ 89: <span class="ruby-keyword kw">end</span>
391
+ 90: <span class="ruby-comment cmt">#--}}}</span>
392
+ 91: <span class="ruby-keyword kw">end</span>
393
+ </pre>
394
+ </div>
395
+ </div>
396
+ </div>
397
+
398
+ <div id="method-M000005" class="method-detail">
399
+ <a name="M000005"></a>
400
+
401
+ <div class="method-heading">
402
+ <a href="#M000005" class="method-signature">
403
+ <span class="method-name">new</span><span class="method-args">opts = {}, &amp;block</span>
404
+ </a>
405
+ </div>
406
+
407
+ <div class="method-description">
408
+ <p>
409
+ opts may contain the keys &#8216;object&#8217;,
410
+ &#8216;socket_creation_attempts&#8217;, &#8216;pulse_rate&#8217;,
411
+ &#8216;psname&#8217;, &#8216;dumped&#8217;, or &#8216;debug&#8217;
412
+ </p>
413
+ <p><a class="source-toggle" href="#"
414
+ onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
415
+ <div class="method-source-code" id="M000005-source">
416
+ <pre>
417
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 128</span>
418
+ 128: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
419
+ 129: <span class="ruby-comment cmt">#--{{{</span>
420
+ 130: <span class="ruby-identifier">getopt</span> = <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
382
421
  131:
383
- 132: <span class="ruby-identifier">tmpdir</span> = <span class="ruby-constant">Dir</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmpdir</span>
384
- 133: <span class="ruby-identifier">basename</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">basename</span> <span class="ruby-ivar">@psname</span>
385
- 134:
386
- 135: <span class="ruby-ivar">@socket_creation_attempts</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attempt</span><span class="ruby-operator">|</span>
387
- 136: <span class="ruby-keyword kw">begin</span>
388
- 137: <span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">join</span>(<span class="ruby-identifier">tmpdir</span>, <span class="ruby-node">&quot;#{ basename }_#{ attempt }&quot;</span>)
389
- 138: <span class="ruby-identifier">u</span> = <span class="ruby-node">&quot;drbunix://#{ s }&quot;</span>
390
- 139: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span> <span class="ruby-identifier">u</span>, <span class="ruby-identifier">obj</span>
391
- 140: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
392
- 141: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
393
- 142: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - socket &lt;#{ @socket }&gt;&quot;</span> }
394
- 143: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - uri &lt;#{ @uri }&gt;&quot;</span> }
395
- 144: <span class="ruby-keyword kw">break</span>
396
- 145: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EADDRINUSE</span>
397
- 146: <span class="ruby-keyword kw">nil</span>
398
- 147: <span class="ruby-keyword kw">end</span>
399
- 148: <span class="ruby-keyword kw">end</span>
422
+ 132: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'object'</span>]
423
+ 133: <span class="ruby-ivar">@socket_creation_attempts</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'socket_creation_attempts'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'socket_creation_attempts'</span>)
424
+ 134: <span class="ruby-ivar">@pulse_rate</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'pulse_rate'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'pulse_rate'</span>)
425
+ 135: <span class="ruby-ivar">@debug</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'debug'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'debug'</span>)
426
+ 136: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'psname'</span>]
427
+ 137: <span class="ruby-ivar">@at_exit</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'at_exit'</span>]
428
+ 138: <span class="ruby-ivar">@dumped</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'dumped'</span>]
429
+ 139:
430
+ 140: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'no slave object!'</span> <span class="ruby-keyword kw">if</span>
431
+ 141: <span class="ruby-ivar">@obj</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">nil?</span>
432
+ 142:
433
+ 143: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
434
+ 144: <span class="ruby-ivar">@waiter</span> = <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
435
+ 145:
436
+ 146: <span class="ruby-ivar">@heartbeat</span> = <span class="ruby-constant">Heartbeat</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-ivar">@pulse_rate</span>, <span class="ruby-ivar">@debug</span>
437
+ 147: <span class="ruby-ivar">@r</span>, <span class="ruby-ivar">@w</span> = <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-identifier">pipe</span>
438
+ 148: <span class="ruby-ivar">@r2</span>, <span class="ruby-ivar">@w2</span> = <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-identifier">pipe</span>
400
439
  149:
401
- 150: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@uri</span>
402
- 151: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
403
- 152: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">write</span> <span class="ruby-ivar">@socket</span>
404
- 153: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
405
- 154: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
406
- 155: <span class="ruby-comment cmt"># @heartbeat.stop rescue nil</span>
407
- 156: <span class="ruby-constant">DBb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">kill</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
408
- 157: <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
409
- 158: <span class="ruby-identifier">exit!</span>
410
- 159: <span class="ruby-keyword kw">end</span>
411
- 160: <span class="ruby-identifier">block</span>[<span class="ruby-identifier">obj</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>
412
- 161: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
413
- 162: <span class="ruby-keyword kw">else</span>
414
- 163: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
415
- 164: <span class="ruby-keyword kw">end</span>
416
- 165: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
417
- 166: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join &quot;\n&quot; }]</span> }
418
- 167: <span class="ruby-keyword kw">ensure</span>
419
- 168: <span class="ruby-identifier">status</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'status'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>
420
- 169: <span class="ruby-identifier">exit!</span>(<span class="ruby-identifier">status</span>)
421
- 170: <span class="ruby-keyword kw">end</span>
422
- 171: <span class="ruby-comment cmt">#</span>
423
- 172: <span class="ruby-comment cmt"># parent </span>
424
- 173: <span class="ruby-comment cmt">#</span>
425
- 174: <span class="ruby-keyword kw">else</span>
426
- 175: <span class="ruby-comment cmt">#Process::detach @pid</span>
427
- 176: <span class="ruby-identifier">detach</span>
428
- 177: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
429
- 178: <span class="ruby-ivar">@socket</span> = <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">read</span>
430
- 179: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
431
- 180:
432
- 181: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - socket &lt;#{ @socket }&gt;&quot;</span> }
433
- 182:
434
- 183: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">exist?</span> <span class="ruby-ivar">@socket</span>
435
- 184: <span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> }
436
- 185: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">&quot;drbunix://#{ socket }&quot;</span>
437
- 186: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - uri &lt;#{ @uri }&gt;&quot;</span> }
438
- 187: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
439
- 188: <span class="ruby-comment cmt">#</span>
440
- 189: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
441
- 190: <span class="ruby-comment cmt">#</span>
442
- 191: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span>(<span class="ruby-value str">'druby://localhost:0'</span>, <span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>
443
- 192: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">DRbObject</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-ivar">@uri</span>
444
- 193: <span class="ruby-keyword kw">else</span>
445
- 194: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;failed to find slave socket &lt;#{ @socket }&gt;&quot;</span>
446
- 195: <span class="ruby-keyword kw">end</span>
447
- 196: <span class="ruby-keyword kw">end</span>
448
- 197: <span class="ruby-comment cmt">#--}}}</span>
449
- 198: <span class="ruby-keyword kw">end</span>
440
+ 150: <span class="ruby-comment cmt"># weird syntax because dot/rdoc chokes on this!?!?</span>
441
+ 151: <span class="ruby-identifier">init_failure</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
442
+ 152: <span class="ruby-identifier">o</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
443
+ 153: <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">o</span>
444
+ 154: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value str">'__slave_object_failure__'</span>
445
+ 155: <span class="ruby-keyword kw">end</span>
446
+ 156: <span class="ruby-identifier">o</span>.<span class="ruby-identifier">__slave_object_failure__</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>]
447
+ 157: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">o</span>
448
+ 158: <span class="ruby-keyword kw">end</span>
449
+ 159:
450
+ 160: <span class="ruby-comment cmt">#</span>
451
+ 161: <span class="ruby-comment cmt"># child</span>
452
+ 162: <span class="ruby-comment cmt">#</span>
453
+ 163: <span class="ruby-keyword kw">unless</span>((<span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Slave</span><span class="ruby-operator">::</span><span class="ruby-identifier">fork</span>))
454
+ 164: <span class="ruby-identifier">e</span> = <span class="ruby-keyword kw">nil</span>
455
+ 165: <span class="ruby-keyword kw">begin</span>
456
+ 166: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">exit!</span> }
457
+ 167:
458
+ 168: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@obj</span>
459
+ 169: <span class="ruby-ivar">@object</span> = <span class="ruby-ivar">@obj</span>
460
+ 170: <span class="ruby-keyword kw">else</span>
461
+ 171: <span class="ruby-keyword kw">begin</span>
462
+ 172: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
463
+ 173: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
464
+ 174: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
465
+ 175: <span class="ruby-keyword kw">end</span>
466
+ 176: <span class="ruby-keyword kw">end</span>
467
+ 177:
468
+ 178: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@obj</span>
469
+ 179: <span class="ruby-keyword kw">begin</span>
470
+ 180: <span class="ruby-identifier">block</span>[<span class="ruby-ivar">@obj</span>]
471
+ 181: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
472
+ 182: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
473
+ 183: <span class="ruby-keyword kw">end</span>
474
+ 184: <span class="ruby-keyword kw">end</span>
475
+ 185:
476
+ 186: <span class="ruby-identifier">$0</span> = (<span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>))
477
+ 187: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@dumped</span> <span class="ruby-keyword kw">or</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'__slave_object_failure__'</span>)
478
+ 188: <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">DRbUndumped</span>
479
+ 189: <span class="ruby-keyword kw">end</span>
480
+ 190:
481
+ 191: <span class="ruby-ivar">@ppid</span>, <span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">ppid</span>, <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">pid</span>
482
+ 192:
483
+ 193: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
484
+ 194: <span class="ruby-ivar">@r2</span>.<span class="ruby-identifier">close</span>
485
+ 195: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
486
+ 196: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
487
+ 197:
488
+ 198: <span class="ruby-identifier">tmpdir</span>, <span class="ruby-identifier">basename</span> = <span class="ruby-constant">Dir</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmpdir</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">basename</span>(<span class="ruby-ivar">@psname</span>)
489
+ 199:
490
+ 200: <span class="ruby-ivar">@socket_creation_attempts</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attempt</span><span class="ruby-operator">|</span>
491
+ 201: <span class="ruby-identifier">se</span> = <span class="ruby-keyword kw">nil</span>
492
+ 202: <span class="ruby-keyword kw">begin</span>
493
+ 203: <span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">join</span>(<span class="ruby-identifier">tmpdir</span>, <span class="ruby-node">&quot;#{ basename }_#{ attempt }&quot;</span>)
494
+ 204: <span class="ruby-identifier">u</span> = <span class="ruby-node">&quot;drbunix://#{ s }&quot;</span>
495
+ 205: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span> <span class="ruby-identifier">u</span>, <span class="ruby-ivar">@object</span>
496
+ 206: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
497
+ 207: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
498
+ 208: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - socket &lt;#{ @socket }&gt;&quot;</span> }
499
+ 209: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;child - uri &lt;#{ @uri }&gt;&quot;</span> }
500
+ 210: <span class="ruby-keyword kw">break</span>
501
+ 211: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EADDRINUSE</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">se</span>
502
+ 212: <span class="ruby-keyword kw">nil</span>
503
+ 213: <span class="ruby-keyword kw">end</span>
504
+ 214: <span class="ruby-keyword kw">end</span>
505
+ 215:
506
+ 216: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@uri</span>
507
+ 217: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
508
+ 218:
509
+ 219: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
510
+ 220: <span class="ruby-comment cmt"># @heartbeat.stop rescue nil</span>
511
+ 221: <span class="ruby-constant">DBb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">kill</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
512
+ 222: <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
513
+ 223: <span class="ruby-identifier">exit</span>
514
+ 224: <span class="ruby-keyword kw">end</span>
515
+ 225:
516
+ 226: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">write</span> <span class="ruby-ivar">@socket</span>
517
+ 227: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
518
+ 228: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
519
+ 229: <span class="ruby-keyword kw">else</span>
520
+ 230: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
521
+ 231: <span class="ruby-keyword kw">end</span>
522
+ 232: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
523
+ 233: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join &quot;\n&quot; }]</span> }
524
+ 234: <span class="ruby-keyword kw">ensure</span>
525
+ 235: <span class="ruby-identifier">status</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'status'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>
526
+ 236: <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>)
527
+ 237: <span class="ruby-keyword kw">end</span>
528
+ 238: <span class="ruby-comment cmt">#</span>
529
+ 239: <span class="ruby-comment cmt"># parent </span>
530
+ 240: <span class="ruby-comment cmt">#</span>
531
+ 241: <span class="ruby-keyword kw">else</span>
532
+ 242: <span class="ruby-identifier">detach</span>
533
+ 243: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
534
+ 244: <span class="ruby-ivar">@w2</span>.<span class="ruby-identifier">close</span>
535
+ 245: <span class="ruby-ivar">@socket</span> = <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">read</span>
536
+ 246: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
537
+ 247:
538
+ 248: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - socket &lt;#{ @socket }&gt;&quot;</span> }
539
+ 249:
540
+ 250: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>
541
+ 251: <span class="ruby-ivar">@at_exit_thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{
542
+ 252: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>.<span class="ruby-identifier">abort_on_exception</span> = <span class="ruby-keyword kw">true</span>
543
+ 253:
544
+ 254: <span class="ruby-ivar">@r2</span>.<span class="ruby-identifier">read</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-value">42</span>
545
+ 255:
546
+ 256: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value str">'call'</span>
547
+ 257: <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">self</span>
548
+ 258: <span class="ruby-keyword kw">else</span>
549
+ 259: <span class="ruby-identifier">send</span> <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-keyword kw">self</span>
550
+ 260: <span class="ruby-keyword kw">end</span>
551
+ 261: }
552
+ 262: <span class="ruby-keyword kw">end</span>
553
+ 263:
554
+ 264: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@socket</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">exist?</span> <span class="ruby-ivar">@socket</span>
555
+ 265: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span>{ <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span> }
556
+ 266: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">&quot;drbunix://#{ socket }&quot;</span>
557
+ 267: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">&quot;parent - uri &lt;#{ @uri }&gt;&quot;</span> }
558
+ 268: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
559
+ 269: <span class="ruby-comment cmt">#</span>
560
+ 270: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
561
+ 271: <span class="ruby-comment cmt">#</span>
562
+ 272: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span>(<span class="ruby-value str">'druby://localhost:0'</span>, <span class="ruby-keyword kw">nil</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>
563
+ 273: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">DRbObject</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-ivar">@uri</span>
564
+ 274: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value str">'__slave_object_failure__'</span>
565
+ 275: <span class="ruby-identifier">c</span>, <span class="ruby-identifier">m</span>, <span class="ruby-identifier">bt</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span> <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">__slave_object_failure__</span>
566
+ 276: (<span class="ruby-identifier">e</span> = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>)).<span class="ruby-identifier">set_backtrace</span> <span class="ruby-identifier">bt</span>
567
+ 277: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
568
+ 278: <span class="ruby-keyword kw">end</span>
569
+ 279: <span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>)
570
+ 280: <span class="ruby-keyword kw">else</span>
571
+ 281: <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;failed to find slave socket &lt;#{ @socket }&gt;&quot;</span>
572
+ 282: <span class="ruby-keyword kw">end</span>
573
+ 283: <span class="ruby-keyword kw">end</span>
574
+ 284: <span class="ruby-comment cmt">#--}}}</span>
575
+ 285: <span class="ruby-keyword kw">end</span>
576
+ </pre>
577
+ </div>
578
+ </div>
579
+ </div>
580
+
581
+ <div id="method-M000001" class="method-detail">
582
+ <a name="M000001"></a>
583
+
584
+ <div class="method-heading">
585
+ <a href="#M000001" class="method-signature">
586
+ <span class="method-name">version</span><span class="method-args">()</span>
587
+ </a>
588
+ </div>
589
+
590
+ <div class="method-description">
591
+ <p><a class="source-toggle" href="#"
592
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
593
+ <div class="method-source-code" id="M000001-source">
594
+ <pre>
595
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 40</span>
596
+ 40: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version</span>() <span class="ruby-constant">VERSION</span> <span class="ruby-keyword kw">end</span>
450
597
  </pre>
451
598
  </div>
452
599
  </div>
@@ -454,40 +601,90 @@ keys &#8216;socket_creation_attempts&#8217;, &#8216;pulse_rate&#8217;,
454
601
 
455
602
  <h2 class="section-bar">Public Instance methods</h2>
456
603
 
457
- <div id="method-M000004" class="method-detail">
458
- <a name="M000004"></a>
604
+ <div id="method-M000012" class="method-detail">
605
+ <a name="M000012"></a>
459
606
 
460
607
  <div class="method-heading">
461
- <a href="#M000004" class="method-signature">
608
+ <a href="#M000012" class="method-signature">
609
+ <span class="method-name">default</span><span class="method-args">key</span>
610
+ </a>
611
+ </div>
612
+
613
+ <div class="method-description">
614
+ <p>
615
+ see docs for <a href="Slave.html#M000002">Slave.default</a>
616
+ </p>
617
+ <p><a class="source-toggle" href="#"
618
+ onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
619
+ <div class="method-source-code" id="M000012-source">
620
+ <pre>
621
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 364</span>
622
+ 364: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
623
+ 365: <span class="ruby-comment cmt">#--{{{</span>
624
+ 366: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
625
+ 367: <span class="ruby-comment cmt">#--}}}</span>
626
+ 368: <span class="ruby-keyword kw">end</span>
627
+ </pre>
628
+ </div>
629
+ </div>
630
+ </div>
631
+
632
+ <div id="method-M000006" class="method-detail">
633
+ <a name="M000006"></a>
634
+
635
+ <div class="method-heading">
636
+ <a href="#M000006" class="method-signature">
462
637
  <span class="method-name">detach</span><span class="method-args">()</span>
463
638
  </a>
464
639
  </div>
465
640
 
466
641
  <div class="method-description">
467
642
  <p>
468
- starts a thread to attempt collecting the child status
643
+ starts a thread to collect the child status and sets up at_exit handler to
644
+ prevent zombies. the at_exit handler is canceled if the thread is able to
645
+ collect the status
469
646
  </p>
470
647
  <p><a class="source-toggle" href="#"
471
- onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
472
- <div class="method-source-code" id="M000004-source">
648
+ onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
649
+ <div class="method-source-code" id="M000006-source">
473
650
  <pre>
474
- <span class="ruby-comment cmt"># File lib/slave.rb, line 202</span>
475
- 202: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">detach</span>
476
- 203: <span class="ruby-comment cmt">#--{{{</span>
477
- 204: <span class="ruby-ivar">@waiter</span> =
478
- 205: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-ivar">@pid</span>).<span class="ruby-identifier">last</span> }
479
- 206: <span class="ruby-comment cmt">#--}}}</span>
480
- 207: <span class="ruby-keyword kw">end</span>
651
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 291</span>
652
+ 291: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">detach</span>
653
+ 292: <span class="ruby-comment cmt">#--{{{</span>
654
+ 293: <span class="ruby-identifier">reap</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span>
655
+ 294: <span class="ruby-keyword kw">begin</span>
656
+ 295: <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-identifier">cid</span>).<span class="ruby-identifier">last</span>
657
+ 296: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
658
+ 297: <span class="ruby-identifier">m</span>, <span class="ruby-identifier">c</span>, <span class="ruby-identifier">b</span> = <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>)
659
+ 298: <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;#{ m } (#{ c })\n#{ b }&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECHILD</span>
660
+ 299: <span class="ruby-keyword kw">end</span>
661
+ 300: <span class="ruby-keyword kw">end</span>
662
+ 301:
663
+ 302: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
664
+ 303: <span class="ruby-identifier">shutdown</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
665
+ 304: <span class="ruby-identifier">reap</span>[<span class="ruby-ivar">@pid</span>] <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
666
+ 305: <span class="ruby-keyword kw">end</span>
667
+ 306:
668
+ 307: <span class="ruby-ivar">@waiter</span> =
669
+ 308: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
670
+ 309: <span class="ruby-keyword kw">begin</span>
671
+ 310: <span class="ruby-ivar">@status</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">waitpid2</span>(<span class="ruby-ivar">@pid</span>).<span class="ruby-identifier">last</span>
672
+ 311: <span class="ruby-keyword kw">ensure</span>
673
+ 312: <span class="ruby-identifier">reap</span> = <span class="ruby-identifier">lambda</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">cid</span><span class="ruby-operator">|</span> <span class="ruby-value str">'no-op'</span> }
674
+ 313: <span class="ruby-keyword kw">end</span>
675
+ 314: <span class="ruby-keyword kw">end</span>
676
+ 315: <span class="ruby-comment cmt">#--}}}</span>
677
+ 316: <span class="ruby-keyword kw">end</span>
481
678
  </pre>
482
679
  </div>
483
680
  </div>
484
681
  </div>
485
682
 
486
- <div id="method-M000008" class="method-detail">
487
- <a name="M000008"></a>
683
+ <div id="method-M000011" class="method-detail">
684
+ <a name="M000011"></a>
488
685
 
489
686
  <div class="method-heading">
490
- <a href="#M000008" class="method-signature">
687
+ <a href="#M000011" class="method-signature">
491
688
  <span class="method-name">gen_psname</span><span class="method-args">obj</span>
492
689
  </a>
493
690
  </div>
@@ -497,15 +694,43 @@ starts a thread to attempt collecting the child status
497
694
  generate a default name to appear in ps/top
498
695
  </p>
499
696
  <p><a class="source-toggle" href="#"
500
- onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
501
- <div class="method-source-code" id="M000008-source">
697
+ onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
698
+ <div class="method-source-code" id="M000011-source">
699
+ <pre>
700
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 356</span>
701
+ 356: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
702
+ 357: <span class="ruby-comment cmt">#--{{{</span>
703
+ 358: <span class="ruby-node">&quot;#{ obj.class }_#{ obj.object_id }_#{ Process::ppid }_#{ Process::pid }&quot;</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">%/\s+/</span>,<span class="ruby-value str">'_'</span>)
704
+ 359: <span class="ruby-comment cmt">#--}}}</span>
705
+ 360: <span class="ruby-keyword kw">end</span>
706
+ </pre>
707
+ </div>
708
+ </div>
709
+ </div>
710
+
711
+ <div id="method-M000013" class="method-detail">
712
+ <a name="M000013"></a>
713
+
714
+ <div class="method-heading">
715
+ <a href="#M000013" class="method-signature">
716
+ <span class="method-name">getopts</span><span class="method-args">opts</span>
717
+ </a>
718
+ </div>
719
+
720
+ <div class="method-description">
721
+ <p>
722
+ see docs for <a href="Slave.html#M000003">Slave.getopts</a>
723
+ </p>
724
+ <p><a class="source-toggle" href="#"
725
+ onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
726
+ <div class="method-source-code" id="M000013-source">
502
727
  <pre>
503
- <span class="ruby-comment cmt"># File lib/slave.rb, line 233</span>
504
- 233: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
505
- 234: <span class="ruby-comment cmt">#--{{{</span>
506
- 235: <span class="ruby-node">&quot;#{ obj.class }_slave_of_#{ Process::pid }&quot;</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">%/\s*/</span>,<span class="ruby-value str">'_'</span>)
507
- 236: <span class="ruby-comment cmt">#--}}}</span>
508
- 237: <span class="ruby-keyword kw">end</span>
728
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 372</span>
729
+ 372: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
730
+ 373: <span class="ruby-comment cmt">#--{{{</span>
731
+ 374: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
732
+ 375: <span class="ruby-comment cmt">#--}}}</span>
733
+ 376: <span class="ruby-keyword kw">end</span>
509
734
  </pre>
510
735
  </div>
511
736
  </div>
@@ -516,67 +741,69 @@ generate a default name to appear in ps/top
516
741
 
517
742
  <div class="method-heading">
518
743
  <a href="#M000009" class="method-signature">
519
- <span class="method-name">getval</span><span class="method-args">key, opts = {}</span>
744
+ <span class="method-name">shutdown</span><span class="method-args">opts = {}</span>
520
745
  </a>
521
746
  </div>
522
747
 
523
748
  <div class="method-description">
524
749
  <p>
525
- see docs for <a href="Slave.html#M000001">Slave.getval</a>
750
+ stops the heartbeat thread and kills the child process - give the key
751
+ &#8216;quiet&#8217; to ignore errors shutting down, including having
752
+ already shutdown
526
753
  </p>
527
754
  <p><a class="source-toggle" href="#"
528
755
  onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
529
756
  <div class="method-source-code" id="M000009-source">
530
757
  <pre>
531
- <span class="ruby-comment cmt"># File lib/slave.rb, line 241</span>
532
- 241: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getval</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">opts</span> = {}
533
- 242: <span class="ruby-comment cmt">#--{{{</span>
534
- 243: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">getval</span> <span class="ruby-identifier">key</span>
535
- 244: <span class="ruby-comment cmt">#--}}}</span>
536
- 245: <span class="ruby-keyword kw">end</span>
758
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 335</span>
759
+ 335: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span> <span class="ruby-identifier">opts</span> = {}
760
+ 336: <span class="ruby-comment cmt">#--{{{</span>
761
+ 337: <span class="ruby-identifier">quiet</span> = <span class="ruby-identifier">getopts</span>(<span class="ruby-identifier">opts</span>)[<span class="ruby-value str">'quiet'</span>]
762
+ 338: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;already shutdown&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@shutdown</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span>
763
+ 339: <span class="ruby-identifier">failure</span> = <span class="ruby-identifier">lambda</span>{ <span class="ruby-identifier">raise</span> <span class="ruby-identifier">$!</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span> }
764
+ 340: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">failure</span>.<span class="ruby-identifier">call</span>
765
+ 341: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span>(<span class="ruby-value str">'SIGUSR2'</span>, <span class="ruby-ivar">@pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">failure</span>.<span class="ruby-identifier">call</span>
766
+ 342: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
767
+ 343: <span class="ruby-comment cmt">#--}}}</span>
768
+ 344: <span class="ruby-keyword kw">end</span>
537
769
  </pre>
538
770
  </div>
539
771
  </div>
540
772
  </div>
541
773
 
542
- <div id="method-M000007" class="method-detail">
543
- <a name="M000007"></a>
774
+ <div id="method-M000010" class="method-detail">
775
+ <a name="M000010"></a>
544
776
 
545
777
  <div class="method-heading">
546
- <a href="#M000007" class="method-signature">
547
- <span class="method-name">shutdown</span><span class="method-args">()</span>
778
+ <a href="#M000010" class="method-signature">
779
+ <span class="method-name">shutdown?</span><span class="method-args">()</span>
548
780
  </a>
549
781
  </div>
550
782
 
551
783
  <div class="method-description">
552
784
  <p>
553
- stops the heartbeat thread and kills the child process
785
+ true
554
786
  </p>
555
787
  <p><a class="source-toggle" href="#"
556
- onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
557
- <div class="method-source-code" id="M000007-source">
788
+ onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
789
+ <div class="method-source-code" id="M000010-source">
558
790
  <pre>
559
- <span class="ruby-comment cmt"># File lib/slave.rb, line 220</span>
560
- 220: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span>
561
- 221: <span class="ruby-comment cmt">#--{{{</span>
562
- 222: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;already shutdown&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@shutdown</span>
563
- 223: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
564
- 224: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span>(<span class="ruby-value str">'SIGUSR2'</span>, <span class="ruby-ivar">@pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
565
- 225: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span>(<span class="ruby-value str">'SIGTERM'</span>, <span class="ruby-ivar">@pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
566
- 226: <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span>
567
- 227: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
568
- 228: <span class="ruby-comment cmt">#--}}}</span>
569
- 229: <span class="ruby-keyword kw">end</span>
791
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 348</span>
792
+ 348: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown?</span>
793
+ 349: <span class="ruby-comment cmt">#--{{{</span>
794
+ 350: <span class="ruby-ivar">@shutdown</span>
795
+ 351: <span class="ruby-comment cmt">#--}}}</span>
796
+ 352: <span class="ruby-keyword kw">end</span>
570
797
  </pre>
571
798
  </div>
572
799
  </div>
573
800
  </div>
574
801
 
575
- <div id="method-M000010" class="method-detail">
576
- <a name="M000010"></a>
802
+ <div id="method-M000014" class="method-detail">
803
+ <a name="M000014"></a>
577
804
 
578
805
  <div class="method-heading">
579
- <a href="#M000010" class="method-signature">
806
+ <a href="#M000014" class="method-signature">
580
807
  <span class="method-name">trace</span><span class="method-args">() {|| ...}</span>
581
808
  </a>
582
809
  </div>
@@ -586,58 +813,64 @@ stops the heartbeat thread and kills the child process
586
813
  debugging output - ENV[&#8216;SLAVE_DEBUG&#8217;]=1 to enable
587
814
  </p>
588
815
  <p><a class="source-toggle" href="#"
589
- onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
590
- <div class="method-source-code" id="M000010-source">
816
+ onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
817
+ <div class="method-source-code" id="M000014-source">
591
818
  <pre>
592
- <span class="ruby-comment cmt"># File lib/slave.rb, line 249</span>
593
- 249: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
594
- 250: <span class="ruby-comment cmt">#--{{{</span>
595
- 251: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-keyword kw">yield</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">tty?</span>
596
- 252: <span class="ruby-comment cmt">#--}}}</span>
597
- 253: <span class="ruby-keyword kw">end</span>
819
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 380</span>
820
+ 380: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
821
+ 381: <span class="ruby-comment cmt">#--{{{</span>
822
+ 382: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-keyword kw">yield</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">tty?</span>
823
+ 383: <span class="ruby-comment cmt">#--}}}</span>
824
+ 384: <span class="ruby-keyword kw">end</span>
598
825
  </pre>
599
826
  </div>
600
827
  </div>
601
828
  </div>
602
829
 
603
- <div id="method-M000005" class="method-detail">
604
- <a name="M000005"></a>
830
+ <div id="method-M000007" class="method-detail">
831
+ <a name="M000007"></a>
605
832
 
606
833
  <div class="method-heading">
607
- <a href="#M000005" class="method-signature">
608
- <span class="method-name">wait</span><span class="method-args">()</span>
834
+ <a href="#M000007" class="method-signature">
835
+ <span class="method-name">wait</span><span class="method-args">opts = {}, &amp;b</span>
609
836
  </a>
610
837
  </div>
611
838
 
612
839
  <div class="method-description">
613
840
  <p>
614
- wait for slave to finish
841
+ wait for slave to finish. if the keyword &#8216;non_block&#8217;=&gt;true
842
+ is given a thread is returned to do the waiting in an async fashion. eg
615
843
  </p>
844
+ <pre>
845
+ thread = slave.wait(:non_block=&gt;true){|value| &quot;background &lt;#{ value }&gt;&quot;}
846
+ </pre>
616
847
  <p><a class="source-toggle" href="#"
617
- onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
618
- <div class="method-source-code" id="M000005-source">
848
+ onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
849
+ <div class="method-source-code" id="M000007-source">
619
850
  <pre>
620
- <span class="ruby-comment cmt"># File lib/slave.rb, line 211</span>
621
- 211: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait</span>
622
- 212: <span class="ruby-comment cmt">#--{{{</span>
623
- 213: <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span>
624
- 214: <span class="ruby-comment cmt">#--}}}</span>
625
- 215: <span class="ruby-keyword kw">end</span>
851
+ <span class="ruby-comment cmt"># File lib/slave.rb, line 323</span>
852
+ 323: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>
853
+ 324: <span class="ruby-comment cmt">#--{{{</span>
854
+ 325: <span class="ruby-identifier">b</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">lambda</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">exit_status</span><span class="ruby-operator">|</span>}
855
+ 326: <span class="ruby-identifier">non_block</span> = <span class="ruby-identifier">getopts</span>(<span class="ruby-identifier">opts</span>)[<span class="ruby-value str">'non_block'</span>]
856
+ 327: <span class="ruby-identifier">non_block</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">b</span>[ <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span> ] } <span class="ruby-operator">:</span> <span class="ruby-identifier">b</span>[ <span class="ruby-ivar">@waiter</span>.<span class="ruby-identifier">value</span> ]
857
+ 328: <span class="ruby-comment cmt">#--}}}</span>
858
+ 329: <span class="ruby-keyword kw">end</span>
626
859
  </pre>
627
860
  </div>
628
861
  </div>
629
862
  </div>
630
863
 
631
- <div id="method-M000006" class="method-detail">
632
- <a name="M000006"></a>
864
+ <div id="method-M000008" class="method-detail">
865
+ <a name="M000008"></a>
633
866
 
634
867
  <div class="method-heading">
635
- <span class="method-name">wait2</span><span class="method-args">()</span>
868
+ <span class="method-name">wait2</span><span class="method-args">opts = {}, &amp;b</span>
636
869
  </div>
637
870
 
638
871
  <div class="method-description">
639
872
  <p>
640
- Alias for <a href="Slave.html#M000005">wait</a>
873
+ Alias for <a href="Slave.html#M000007">wait</a>
641
874
  </p>
642
875
  </div>
643
876
  </div>