slave 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +16 -0
- data/doc/classes/Slave/Heartbeat.html +241 -126
- data/doc/classes/Slave.html +289 -173
- data/doc/created.rid +1 -1
- data/doc/dot/f_1.dot +16 -1
- data/doc/dot/f_1.jpg +0 -0
- data/doc/files/README.html +1 -1
- data/doc/files/lib/slave_rb.html +3 -2
- data/doc/fr_file_index.html +0 -1
- data/doc/fr_method_index.html +16 -10
- data/lib/{slave-0.0.0.rb → slave-0.0.1.rb} +102 -8
- data/lib/slave.rb +130 -19
- data/rdoc.cmd +1 -1
- data/sample/a.rb +11 -94
- data/sample/b.rb +8 -0
- data/sample/c.rb +109 -0
- data/{slave-0.0.0.gem → slave-0.0.1.gem} +0 -0
- metadata +24 -22
- data/VERSION +0 -1
data/doc/classes/Slave.html
CHANGED
@@ -77,14 +77,34 @@
|
|
77
77
|
<map name="map">
|
78
78
|
<area shape="RECT" coords="28,88,99,40" href="Slave.html" alt="Slave">
|
79
79
|
</map>
|
80
|
-
<img src="../dot/
|
80
|
+
<img src="../dot/f_1.jpg" usemap="#map" border=0 alt="TopLevel">
|
81
81
|
</div>
|
82
82
|
|
83
83
|
<div id="description">
|
84
84
|
<p>
|
85
85
|
the <a href="Slave.html">Slave</a> class encapsulates the work of setting
|
86
|
-
up a drb server in another process.
|
86
|
+
up a drb server in another process running on localhost. the slave process
|
87
|
+
is attached to it’s parent via a <a
|
88
|
+
href="Slave/Heartbeat.html">Heartbeat</a> which is designed such that the
|
89
|
+
slave cannot out-live it’s parent and become a zombie, even if the
|
90
|
+
parent dies and early death, such as by ‘kill -9’. the concept
|
91
|
+
and purpose of the <a href="Slave.html">Slave</a> class is to be able to
|
92
|
+
setup any server object in another process so easily that using a
|
93
|
+
multi-process, drb/ipc, based design is as easy, or easier, than a
|
94
|
+
multi-threaded one. eg
|
87
95
|
</p>
|
96
|
+
<pre>
|
97
|
+
class Server
|
98
|
+
def add_two n
|
99
|
+
n + 2
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
slave = Slave.new Server.new
|
104
|
+
server = slave.object
|
105
|
+
|
106
|
+
p server.add_two(40) #=> 42
|
107
|
+
</pre>
|
88
108
|
|
89
109
|
</div>
|
90
110
|
|
@@ -93,13 +113,16 @@ up a drb server in another process.
|
|
93
113
|
<h2 class="section-bar">Methods</h2>
|
94
114
|
|
95
115
|
<div class="name-list">
|
116
|
+
<a href="#M000004">detach</a>
|
96
117
|
<a href="#M000002">fork</a>
|
97
|
-
<a href="#
|
98
|
-
<a href="#M000006">getval</a>
|
118
|
+
<a href="#M000008">gen_psname</a>
|
99
119
|
<a href="#M000001">getval</a>
|
120
|
+
<a href="#M000009">getval</a>
|
100
121
|
<a href="#M000003">new</a>
|
101
|
-
<a href="#
|
102
|
-
<a href="#
|
122
|
+
<a href="#M000007">shutdown</a>
|
123
|
+
<a href="#M000010">trace</a>
|
124
|
+
<a href="#M000005">wait</a>
|
125
|
+
<a href="#M000006">wait2</a>
|
103
126
|
</div>
|
104
127
|
</div>
|
105
128
|
|
@@ -108,11 +131,23 @@ up a drb server in another process.
|
|
108
131
|
|
109
132
|
<div class="name-list">
|
110
133
|
<table summary="Constants">
|
134
|
+
<tr class="top-aligned-row context-row">
|
135
|
+
<td class="context-item-name">VERSION</td>
|
136
|
+
<td>=</td>
|
137
|
+
<td class="context-item-value">'0.0.1'</td>
|
138
|
+
</tr>
|
111
139
|
<tr class="top-aligned-row context-row">
|
112
140
|
<td class="context-item-name">DEFAULT_SOCKET_CREATION_ATTEMPTS</td>
|
113
141
|
<td>=</td>
|
114
142
|
<td class="context-item-value">Integer(ENV['SLAVE_SOCKET_CREATION_ATTEMPTS'] || 42)</td>
|
115
143
|
</tr>
|
144
|
+
<tr class="top-aligned-row context-row">
|
145
|
+
<td> </td>
|
146
|
+
<td colspan="2" class="context-item-desc">
|
147
|
+
config
|
148
|
+
|
149
|
+
</td>
|
150
|
+
</tr>
|
116
151
|
<tr class="top-aligned-row context-row">
|
117
152
|
<td class="context-item-name">DEFAULT_PULSE_RATE</td>
|
118
153
|
<td>=</td>
|
@@ -197,6 +232,11 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
|
|
197
232
|
<td class="context-item-value"> [RW] </td>
|
198
233
|
<td class="context-item-desc"></td>
|
199
234
|
</tr>
|
235
|
+
<tr class="top-aligned-row context-row">
|
236
|
+
<td class="context-item-name">status</td>
|
237
|
+
<td class="context-item-value"> [R] </td>
|
238
|
+
<td class="context-item-desc"></td>
|
239
|
+
</tr>
|
200
240
|
<tr class="top-aligned-row context-row">
|
201
241
|
<td class="context-item-name">uri</td>
|
202
242
|
<td class="context-item-value"> [R] </td>
|
@@ -241,18 +281,18 @@ just fork with out silly warnings
|
|
241
281
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
242
282
|
<div class="method-source-code" id="M000002-source">
|
243
283
|
<pre>
|
244
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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">&</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">&</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>
|
256
296
|
</pre>
|
257
297
|
</div>
|
258
298
|
</div>
|
@@ -275,14 +315,14 @@ look up a value in an option hash failing back to class defaults
|
|
275
315
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
276
316
|
<div class="method-source-code" id="M000001-source">
|
277
317
|
<pre>
|
278
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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>
|
286
326
|
</pre>
|
287
327
|
</div>
|
288
328
|
</div>
|
@@ -293,7 +333,7 @@ look up a value in an option hash failing back to class defaults
|
|
293
333
|
|
294
334
|
<div class="method-heading">
|
295
335
|
<a href="#M000003" class="method-signature">
|
296
|
-
<span class="method-name">new</span><span class="method-args">obj, opts = {}</span>
|
336
|
+
<span class="method-name">new</span><span class="method-args">obj = nil, opts = {}, &block</span>
|
297
337
|
</a>
|
298
338
|
</div>
|
299
339
|
|
@@ -307,101 +347,106 @@ keys ‘socket_creation_attempts’, ‘pulse_rate’,
|
|
307
347
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
308
348
|
<div class="method-source-code" id="M000003-source">
|
309
349
|
<pre>
|
310
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
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">&</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">"socket_creation_attempts <#{ @socket_creation_attempts }>"</span> }
|
361
|
+
110: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"pulse_rate <#{ @pulse_rate }>"</span> }
|
362
|
+
111: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"psname <#{ @psname }>"</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>
|
382
|
+
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">"#{ basename }_#{ attempt }"</span>)
|
389
|
+
138: <span class="ruby-identifier">u</span> = <span class="ruby-node">"drbunix://#{ s }"</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">"child - socket <#{ @socket }>"</span> }
|
394
|
+
143: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - uri <#{ @uri }>"</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>
|
400
|
+
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">></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 "\n" }]</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">"parent - socket <#{ @socket }>"</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">"drbunix://#{ socket }"</span>
|
437
|
+
186: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - uri <#{ @uri }>"</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">"failed to find slave socket <#{ @socket }>"</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>
|
405
450
|
</pre>
|
406
451
|
</div>
|
407
452
|
</div>
|
@@ -409,11 +454,40 @@ keys ‘socket_creation_attempts’, ‘pulse_rate’,
|
|
409
454
|
|
410
455
|
<h2 class="section-bar">Public Instance methods</h2>
|
411
456
|
|
412
|
-
<div id="method-
|
413
|
-
<a name="
|
457
|
+
<div id="method-M000004" class="method-detail">
|
458
|
+
<a name="M000004"></a>
|
414
459
|
|
415
460
|
<div class="method-heading">
|
416
|
-
<a href="#
|
461
|
+
<a href="#M000004" class="method-signature">
|
462
|
+
<span class="method-name">detach</span><span class="method-args">()</span>
|
463
|
+
</a>
|
464
|
+
</div>
|
465
|
+
|
466
|
+
<div class="method-description">
|
467
|
+
<p>
|
468
|
+
starts a thread to attempt collecting the child status
|
469
|
+
</p>
|
470
|
+
<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">
|
473
|
+
<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>
|
481
|
+
</pre>
|
482
|
+
</div>
|
483
|
+
</div>
|
484
|
+
</div>
|
485
|
+
|
486
|
+
<div id="method-M000008" class="method-detail">
|
487
|
+
<a name="M000008"></a>
|
488
|
+
|
489
|
+
<div class="method-heading">
|
490
|
+
<a href="#M000008" class="method-signature">
|
417
491
|
<span class="method-name">gen_psname</span><span class="method-args">obj</span>
|
418
492
|
</a>
|
419
493
|
</div>
|
@@ -423,53 +497,53 @@ keys ‘socket_creation_attempts’, ‘pulse_rate’,
|
|
423
497
|
generate a default name to appear in ps/top
|
424
498
|
</p>
|
425
499
|
<p><a class="source-toggle" href="#"
|
426
|
-
onclick="toggleCode('
|
427
|
-
<div class="method-source-code" id="
|
500
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
501
|
+
<div class="method-source-code" id="M000008-source">
|
428
502
|
<pre>
|
429
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
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">"#{ obj.class }_slave_of_#{ Process::pid }"</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>
|
435
509
|
</pre>
|
436
510
|
</div>
|
437
511
|
</div>
|
438
512
|
</div>
|
439
513
|
|
440
|
-
<div id="method-
|
441
|
-
<a name="
|
514
|
+
<div id="method-M000009" class="method-detail">
|
515
|
+
<a name="M000009"></a>
|
442
516
|
|
443
517
|
<div class="method-heading">
|
444
|
-
<a href="#
|
518
|
+
<a href="#M000009" class="method-signature">
|
445
519
|
<span class="method-name">getval</span><span class="method-args">key, opts = {}</span>
|
446
520
|
</a>
|
447
521
|
</div>
|
448
522
|
|
449
523
|
<div class="method-description">
|
450
524
|
<p>
|
451
|
-
see docs for
|
525
|
+
see docs for <a href="Slave.html#M000001">Slave.getval</a>
|
452
526
|
</p>
|
453
527
|
<p><a class="source-toggle" href="#"
|
454
|
-
onclick="toggleCode('
|
455
|
-
<div class="method-source-code" id="
|
528
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
529
|
+
<div class="method-source-code" id="M000009-source">
|
456
530
|
<pre>
|
457
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
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>
|
463
537
|
</pre>
|
464
538
|
</div>
|
465
539
|
</div>
|
466
540
|
</div>
|
467
541
|
|
468
|
-
<div id="method-
|
469
|
-
<a name="
|
542
|
+
<div id="method-M000007" class="method-detail">
|
543
|
+
<a name="M000007"></a>
|
470
544
|
|
471
545
|
<div class="method-heading">
|
472
|
-
<a href="#
|
546
|
+
<a href="#M000007" class="method-signature">
|
473
547
|
<span class="method-name">shutdown</span><span class="method-args">()</span>
|
474
548
|
</a>
|
475
549
|
</div>
|
@@ -479,53 +553,95 @@ see docs for class.getval
|
|
479
553
|
stops the heartbeat thread and kills the child process
|
480
554
|
</p>
|
481
555
|
<p><a class="source-toggle" href="#"
|
482
|
-
onclick="toggleCode('
|
483
|
-
<div class="method-source-code" id="
|
556
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
557
|
+
<div class="method-source-code" id="M000007-source">
|
484
558
|
<pre>
|
485
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
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">"already shutdown"</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>
|
496
570
|
</pre>
|
497
571
|
</div>
|
498
572
|
</div>
|
499
573
|
</div>
|
500
574
|
|
501
|
-
<div id="method-
|
502
|
-
<a name="
|
575
|
+
<div id="method-M000010" class="method-detail">
|
576
|
+
<a name="M000010"></a>
|
503
577
|
|
504
578
|
<div class="method-heading">
|
505
|
-
<a href="#
|
579
|
+
<a href="#M000010" class="method-signature">
|
506
580
|
<span class="method-name">trace</span><span class="method-args">() {|| ...}</span>
|
507
581
|
</a>
|
508
582
|
</div>
|
509
583
|
|
510
584
|
<div class="method-description">
|
511
585
|
<p>
|
512
|
-
debugging output
|
586
|
+
debugging output - ENV[‘SLAVE_DEBUG’]=1 to enable
|
513
587
|
</p>
|
514
588
|
<p><a class="source-toggle" href="#"
|
515
|
-
onclick="toggleCode('
|
516
|
-
<div class="method-source-code" id="
|
589
|
+
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
590
|
+
<div class="method-source-code" id="M000010-source">
|
591
|
+
<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>
|
598
|
+
</pre>
|
599
|
+
</div>
|
600
|
+
</div>
|
601
|
+
</div>
|
602
|
+
|
603
|
+
<div id="method-M000005" class="method-detail">
|
604
|
+
<a name="M000005"></a>
|
605
|
+
|
606
|
+
<div class="method-heading">
|
607
|
+
<a href="#M000005" class="method-signature">
|
608
|
+
<span class="method-name">wait</span><span class="method-args">()</span>
|
609
|
+
</a>
|
610
|
+
</div>
|
611
|
+
|
612
|
+
<div class="method-description">
|
613
|
+
<p>
|
614
|
+
wait for slave to finish
|
615
|
+
</p>
|
616
|
+
<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">
|
517
619
|
<pre>
|
518
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
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>
|
524
626
|
</pre>
|
525
627
|
</div>
|
526
628
|
</div>
|
527
629
|
</div>
|
528
630
|
|
631
|
+
<div id="method-M000006" class="method-detail">
|
632
|
+
<a name="M000006"></a>
|
633
|
+
|
634
|
+
<div class="method-heading">
|
635
|
+
<span class="method-name">wait2</span><span class="method-args">()</span>
|
636
|
+
</div>
|
637
|
+
|
638
|
+
<div class="method-description">
|
639
|
+
<p>
|
640
|
+
Alias for <a href="Slave.html#M000005">wait</a>
|
641
|
+
</p>
|
642
|
+
</div>
|
643
|
+
</div>
|
644
|
+
|
529
645
|
|
530
646
|
</div>
|
531
647
|
|