slave 1.0.0 → 1.1.0
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/README +90 -17
- data/README.tmpl +29 -12
- data/doc/classes/Slave.html +430 -298
- data/doc/classes/Slave/LifeLine.html +406 -0
- data/doc/classes/Slave/ThreadSafe.html +284 -0
- data/doc/classes/Slave/ThreadSafeHash.html +151 -0
- data/doc/created.rid +1 -1
- data/doc/files/README.html +88 -18
- data/doc/files/lib/slave_rb.html +6 -2
- data/doc/fr_class_index.html +3 -1
- data/doc/fr_method_index.html +19 -11
- data/lib/slave-1.1.0.rb +623 -0
- data/lib/slave.rb +293 -203
- data/samples/a.rb +3 -1
- data/samples/f.rb +13 -0
- data/samples/g.rb +19 -0
- metadata +26 -30
- data/doc/classes/(@object = Object.new).html +0 -117
- data/doc/classes/(o = Object.new).html +0 -117
- data/doc/classes/@object.html +0 -117
- data/doc/classes/Slave/Heartbeat.html +0 -458
- data/doc/classes/object.html +0 -117
- data/doc/dot/f_2.dot +0 -29
- data/doc/dot/f_2.jpg +0 -0
- data/doc/files/VERSION.html +0 -107
- data/lib/slave-1.0.0.rb +0 -533
- data/slave-1.0.0.gem +0 -0
data/README
CHANGED
@@ -10,23 +10,27 @@ SYNOPSIS
|
|
10
10
|
|
11
11
|
typical usage:
|
12
12
|
|
13
|
-
|
13
|
+
slave = Slave::new{ AnyObject.new }
|
14
14
|
|
15
|
-
slave
|
15
|
+
slave.object #=> handle on drb object
|
16
|
+
slave.uri #=> uri of the drb object
|
17
|
+
slave.socket #=> unix domain socket path for drb object
|
18
|
+
slave.psname #=> title shown in ps/top
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
p slave.psname # title shown in ps/top
|
20
|
+
object = slave.object
|
21
|
+
|
22
|
+
value = object.any_method #=> use the object normally
|
21
23
|
|
22
24
|
slaves may be configured via the environment, the Slave class, or via the
|
23
25
|
ctor for object itself. attributes which may be configured include
|
24
26
|
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
27
|
+
* object : specify the slave object. otherwise block value is used.
|
28
|
+
* socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
|
29
|
+
* debug : turn on some logging to STDERR
|
30
|
+
* psname : specify the name that will appear in 'top' ($0)
|
31
|
+
* at_exit : specify a lambda to be called in the *parent* when the child dies
|
32
|
+
* dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
|
33
|
+
* threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
|
30
34
|
|
31
35
|
URIS
|
32
36
|
|
@@ -35,9 +39,22 @@ URIS
|
|
35
39
|
|
36
40
|
HISTORY
|
37
41
|
|
38
|
-
|
42
|
+
1.1.0:
|
43
|
+
- replaced HeartBeat class with LifeLine.
|
44
|
+
|
45
|
+
- __HUGE__ cleanup of file descriptor/fork management with tons of help
|
46
|
+
from skaar and ezra. thanks guys!
|
47
|
+
|
48
|
+
- introduced Slave.object method used to return any object directory from
|
49
|
+
a child process. see samples/g.rb.
|
50
|
+
|
51
|
+
- indroduced keyword to automatically make slave objects threadsafe.
|
52
|
+
remember that your slave object must be threadsafe because they are
|
53
|
+
being server via DRb!!!
|
54
|
+
|
39
55
|
|
40
56
|
1.0.0:
|
57
|
+
- THIS RELEASE IS !! NOT !! BACKWARD COMPATIBLE. NOTE NEW CTOR SYNTAX.
|
41
58
|
|
42
59
|
- detach method also sets up at_exit handler. extra protection from
|
43
60
|
zombies.
|
@@ -97,9 +114,11 @@ SAMPLES
|
|
97
114
|
end
|
98
115
|
|
99
116
|
slave = Slave.new :object => Server.new
|
100
|
-
server = slave.object
|
101
117
|
|
118
|
+
server = slave.object
|
102
119
|
p server.add_two(40) #=> 42
|
120
|
+
|
121
|
+
slave.shutdown
|
103
122
|
|
104
123
|
~ > ruby samples/a.rb
|
105
124
|
|
@@ -136,7 +155,7 @@ SAMPLES
|
|
136
155
|
~ > ruby samples/b.rb
|
137
156
|
|
138
157
|
:postgresql
|
139
|
-
./lib/slave.rb:
|
158
|
+
./lib/slave.rb:460:in `initialize': undefined method `typo' for #<Server:0xb7565694> (NoMethodError)
|
140
159
|
from samples/b.rb:22:in `new'
|
141
160
|
from samples/b.rb:22
|
142
161
|
|
@@ -169,9 +188,9 @@ SAMPLES
|
|
169
188
|
|
170
189
|
~ > ruby samples/c.rb
|
171
190
|
|
172
|
-
|
173
|
-
|
174
|
-
./lib/slave.rb:
|
191
|
+
14387
|
192
|
+
14388
|
193
|
+
./lib/slave.rb:460:in `initialize': undefined local variable or method `fubar' for main:Object (NameError)
|
175
194
|
from samples/c.rb:21:in `new'
|
176
195
|
from samples/c.rb:21
|
177
196
|
|
@@ -192,6 +211,7 @@ SAMPLES
|
|
192
211
|
|
193
212
|
~ > ruby samples/d.rb
|
194
213
|
|
214
|
+
"child"
|
195
215
|
"parent"
|
196
216
|
|
197
217
|
|
@@ -215,3 +235,56 @@ SAMPLES
|
|
215
235
|
|
216
236
|
"child"
|
217
237
|
|
238
|
+
|
239
|
+
<========< samples/f.rb >========>
|
240
|
+
|
241
|
+
~ > cat samples/f.rb
|
242
|
+
|
243
|
+
require 'slave'
|
244
|
+
#
|
245
|
+
# slaves created previously are visible to newly created slaves - in this
|
246
|
+
# example the child process of slave_a communicates directly with the child
|
247
|
+
# process of slave_a
|
248
|
+
#
|
249
|
+
slave_a = Slave.new{ Array.new }
|
250
|
+
slave_b = Slave.new{ slave_a.object }
|
251
|
+
|
252
|
+
a, b = slave_b.object, slave_a.object
|
253
|
+
|
254
|
+
b << 42
|
255
|
+
puts a #=> 42
|
256
|
+
|
257
|
+
~ > ruby samples/f.rb
|
258
|
+
|
259
|
+
42
|
260
|
+
|
261
|
+
|
262
|
+
<========< samples/g.rb >========>
|
263
|
+
|
264
|
+
~ > cat samples/g.rb
|
265
|
+
|
266
|
+
require 'slave'
|
267
|
+
#
|
268
|
+
# Slave.object can used when you want to construct an object in another
|
269
|
+
# process. in otherwords you want to fork a process and retrieve a single
|
270
|
+
# returned object from that process as opposed to setting up a server.
|
271
|
+
#
|
272
|
+
this = Process.pid
|
273
|
+
that = Slave.object{ Process.pid }
|
274
|
+
|
275
|
+
p 'this' => this, 'that' => that
|
276
|
+
|
277
|
+
#
|
278
|
+
# any object can be returned and it can be returned asychronously via a thread
|
279
|
+
#
|
280
|
+
thread = Slave.object(:async => true){ sleep 2 and [ Process.pid, Time.now ] }
|
281
|
+
this = [ Process.pid, Time.now ]
|
282
|
+
that = thread.value
|
283
|
+
|
284
|
+
p 'this' => this, 'that' => that
|
285
|
+
|
286
|
+
~ > ruby samples/g.rb
|
287
|
+
|
288
|
+
{"that"=>14406, "this"=>14405}
|
289
|
+
{"that"=>[14407, Tue Nov 28 09:47:31 MST 2006], "this"=>[14405, Tue Nov 28 09:47:29 MST 2006]}
|
290
|
+
|
data/README.tmpl
CHANGED
@@ -10,23 +10,27 @@ SYNOPSIS
|
|
10
10
|
|
11
11
|
typical usage:
|
12
12
|
|
13
|
-
|
13
|
+
slave = Slave::new{ AnyObject.new }
|
14
14
|
|
15
|
-
slave
|
15
|
+
slave.object #=> handle on drb object
|
16
|
+
slave.uri #=> uri of the drb object
|
17
|
+
slave.socket #=> unix domain socket path for drb object
|
18
|
+
slave.psname #=> title shown in ps/top
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
p slave.psname # title shown in ps/top
|
20
|
+
object = slave.object
|
21
|
+
|
22
|
+
value = object.any_method #=> use the object normally
|
21
23
|
|
22
24
|
slaves may be configured via the environment, the Slave class, or via the
|
23
25
|
ctor for object itself. attributes which may be configured include
|
24
26
|
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
27
|
+
* object : specify the slave object. otherwise block value is used.
|
28
|
+
* socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
|
29
|
+
* debug : turn on some logging to STDERR
|
30
|
+
* psname : specify the name that will appear in 'top' ($0)
|
31
|
+
* at_exit : specify a lambda to be called in the *parent* when the child dies
|
32
|
+
* dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
|
33
|
+
* threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
|
30
34
|
|
31
35
|
URIS
|
32
36
|
|
@@ -35,9 +39,22 @@ URIS
|
|
35
39
|
|
36
40
|
HISTORY
|
37
41
|
|
38
|
-
|
42
|
+
1.1.0:
|
43
|
+
- replaced HeartBeat class with LifeLine.
|
44
|
+
|
45
|
+
- __HUGE__ cleanup of file descriptor/fork management with tons of help
|
46
|
+
from skaar and ezra. thanks guys!
|
47
|
+
|
48
|
+
- introduced Slave.object method used to return any object directory from
|
49
|
+
a child process. see samples/g.rb.
|
50
|
+
|
51
|
+
- indroduced keyword to automatically make slave objects threadsafe.
|
52
|
+
remember that your slave object must be threadsafe because they are
|
53
|
+
being server via DRb!!!
|
54
|
+
|
39
55
|
|
40
56
|
1.0.0:
|
57
|
+
- THIS RELEASE IS !! NOT !! BACKWARD COMPATIBLE. NOTE NEW CTOR SYNTAX.
|
41
58
|
|
42
59
|
- detach method also sets up at_exit handler. extra protection from
|
43
60
|
zombies.
|
data/doc/classes/Slave.html
CHANGED
@@ -84,9 +84,9 @@
|
|
84
84
|
<div id="description">
|
85
85
|
<p>
|
86
86
|
the <a href="Slave.html">Slave</a> class encapsulates the work of setting
|
87
|
-
up a drb server in another process running on localhost
|
88
|
-
is attached to it’s parent via a <a
|
89
|
-
href="Slave/
|
87
|
+
up a drb server in another process running on localhost via unix domain
|
88
|
+
sockets. the slave process is attached to it’s parent via a <a
|
89
|
+
href="Slave/LifeLine.html">LifeLine</a> which is designed such that the
|
90
90
|
slave cannot out-live it’s parent and become a zombie, even if the
|
91
91
|
parent dies and early death, such as by ‘kill -9’. the concept
|
92
92
|
and purpose of the <a href="Slave.html">Slave</a> class is to be able to
|
@@ -138,6 +138,8 @@ of the two ‘b’ is preferred.
|
|
138
138
|
<a href="#M000003">getopts</a>
|
139
139
|
<a href="#M000013">getopts</a>
|
140
140
|
<a href="#M000005">new</a>
|
141
|
+
<a href="#M000015">object</a>
|
142
|
+
<a href="#M000016">object</a>
|
141
143
|
<a href="#M000009">shutdown</a>
|
142
144
|
<a href="#M000010">shutdown?</a>
|
143
145
|
<a href="#M000014">trace</a>
|
@@ -155,7 +157,7 @@ of the two ‘b’ is preferred.
|
|
155
157
|
<tr class="top-aligned-row context-row">
|
156
158
|
<td class="context-item-name">VERSION</td>
|
157
159
|
<td>=</td>
|
158
|
-
<td class="context-item-value">'1.
|
160
|
+
<td class="context-item-value">'1.1.0'</td>
|
159
161
|
</tr>
|
160
162
|
<tr class="top-aligned-row context-row">
|
161
163
|
<td class="context-item-name">DEFAULT_SOCKET_CREATION_ATTEMPTS</td>
|
@@ -165,19 +167,19 @@ of the two ‘b’ is preferred.
|
|
165
167
|
<tr class="top-aligned-row context-row">
|
166
168
|
<td> </td>
|
167
169
|
<td colspan="2" class="context-item-desc">
|
168
|
-
config
|
170
|
+
env config
|
169
171
|
|
170
172
|
</td>
|
171
173
|
</tr>
|
172
174
|
<tr class="top-aligned-row context-row">
|
173
|
-
<td class="context-item-name">
|
175
|
+
<td class="context-item-name">DEFAULT_DEBUG</td>
|
174
176
|
<td>=</td>
|
175
|
-
<td class="context-item-value">
|
177
|
+
<td class="context-item-value">(ENV['SLAVE_DEBUG'] ? true : false)</td>
|
176
178
|
</tr>
|
177
179
|
<tr class="top-aligned-row context-row">
|
178
|
-
<td class="context-item-name">
|
180
|
+
<td class="context-item-name">DEFAULT_THREADSAFE</td>
|
179
181
|
<td>=</td>
|
180
|
-
<td class="context-item-value">(ENV['
|
182
|
+
<td class="context-item-value">(ENV['SLAVE_THREADSAFE'] ? true : false)</td>
|
181
183
|
</tr>
|
182
184
|
</table>
|
183
185
|
</div>
|
@@ -210,10 +212,18 @@ on STDERR
|
|
210
212
|
<td class="context-item-desc"></td>
|
211
213
|
</tr>
|
212
214
|
<tr class="top-aligned-row context-row">
|
213
|
-
<td class="context-item-name">
|
215
|
+
<td class="context-item-name">dumped</td>
|
214
216
|
<td class="context-item-value"> [R] </td>
|
215
217
|
<td class="context-item-desc"></td>
|
216
218
|
</tr>
|
219
|
+
<tr class="top-aligned-row context-row">
|
220
|
+
<td class="context-item-name">obj</td>
|
221
|
+
<td class="context-item-value"> [R] </td>
|
222
|
+
<td class="context-item-desc">
|
223
|
+
attrs
|
224
|
+
|
225
|
+
</td>
|
226
|
+
</tr>
|
217
227
|
<tr class="top-aligned-row context-row">
|
218
228
|
<td class="context-item-name">object</td>
|
219
229
|
<td class="context-item-value"> [R] </td>
|
@@ -234,20 +244,6 @@ on STDERR
|
|
234
244
|
<td class="context-item-value"> [R] </td>
|
235
245
|
<td class="context-item-desc"></td>
|
236
246
|
</tr>
|
237
|
-
<tr class="top-aligned-row context-row">
|
238
|
-
<td class="context-item-name">pulse_rate</td>
|
239
|
-
<td class="context-item-value"> [RW] </td>
|
240
|
-
<td class="context-item-desc">
|
241
|
-
defined the rate of pinging in the <a
|
242
|
-
href="Slave/Heartbeat.html">Heartbeat</a> object
|
243
|
-
|
244
|
-
</td>
|
245
|
-
</tr>
|
246
|
-
<tr class="top-aligned-row context-row">
|
247
|
-
<td class="context-item-name">pulse_rate</td>
|
248
|
-
<td class="context-item-value"> [R] </td>
|
249
|
-
<td class="context-item-desc"></td>
|
250
|
-
</tr>
|
251
247
|
<tr class="top-aligned-row context-row">
|
252
248
|
<td class="context-item-name">shutdown</td>
|
253
249
|
<td class="context-item-value"> [R] </td>
|
@@ -273,6 +269,17 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
|
|
273
269
|
<td class="context-item-value"> [R] </td>
|
274
270
|
<td class="context-item-desc"></td>
|
275
271
|
</tr>
|
272
|
+
<tr class="top-aligned-row context-row">
|
273
|
+
<td class="context-item-name">threadsafe</td>
|
274
|
+
<td class="context-item-value"> [RW] </td>
|
275
|
+
<td class="context-item-desc">
|
276
|
+
if this is true all slave objects will be wrapped such that any call to the
|
277
|
+
object is threadsafe. if you do not use this you must ensure that your
|
278
|
+
objects are threadsafe <em>yourself</em> as this is required of any object
|
279
|
+
acting as a drb server
|
280
|
+
|
281
|
+
</td>
|
282
|
+
</tr>
|
276
283
|
<tr class="top-aligned-row context-row">
|
277
284
|
<td class="context-item-name">uri</td>
|
278
285
|
<td class="context-item-value"> [R] </td>
|
@@ -285,7 +292,9 @@ href="Slave/Heartbeat.html">Heartbeat</a> object
|
|
285
292
|
<div id="class-list">
|
286
293
|
<h2 class="section-bar">Classes and Modules</h2>
|
287
294
|
|
288
|
-
Class <a href="Slave/
|
295
|
+
Class <a href="Slave/LifeLine.html" class="link">Slave::LifeLine</a><br />
|
296
|
+
Class <a href="Slave/ThreadSafe.html" class="link">Slave::ThreadSafe</a><br />
|
297
|
+
Class <a href="Slave/ThreadSafeHash.html" class="link">Slave::ThreadSafeHash</a><br />
|
289
298
|
|
290
299
|
</div>
|
291
300
|
|
@@ -317,12 +326,12 @@ get a default value
|
|
317
326
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
318
327
|
<div class="method-source-code" id="M000002-source">
|
319
328
|
<pre>
|
320
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
329
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 77</span>
|
330
|
+
77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
|
331
|
+
78: <span class="ruby-comment cmt">#--{{{</span>
|
332
|
+
79: <span class="ruby-identifier">send</span> <span class="ruby-identifier">key</span>
|
333
|
+
80: <span class="ruby-comment cmt">#--}}}</span>
|
334
|
+
81: <span class="ruby-keyword kw">end</span>
|
326
335
|
</pre>
|
327
336
|
</div>
|
328
337
|
</div>
|
@@ -345,18 +354,18 @@ just fork with out silly warnings
|
|
345
354
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
346
355
|
<div class="method-source-code" id="M000004-source">
|
347
356
|
<pre>
|
348
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
357
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 98</span>
|
358
|
+
98: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fork</span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
359
|
+
99: <span class="ruby-comment cmt">#--{{{</span>
|
360
|
+
100: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
|
361
|
+
101: <span class="ruby-keyword kw">begin</span>
|
362
|
+
102: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-keyword kw">nil</span>
|
363
|
+
103: <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>
|
364
|
+
104: <span class="ruby-keyword kw">ensure</span>
|
365
|
+
105: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
|
366
|
+
106: <span class="ruby-keyword kw">end</span>
|
367
|
+
107: <span class="ruby-comment cmt">#--}}}</span>
|
368
|
+
108: <span class="ruby-keyword kw">end</span>
|
360
369
|
</pre>
|
361
370
|
</div>
|
362
371
|
</div>
|
@@ -376,20 +385,20 @@ just fork with out silly warnings
|
|
376
385
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
377
386
|
<div class="method-source-code" id="M000003-source">
|
378
387
|
<pre>
|
379
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
388
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 83</span>
|
389
|
+
83: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
|
390
|
+
84: <span class="ruby-comment cmt">#--{{{</span>
|
391
|
+
85: <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>
|
392
|
+
86: <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>)
|
393
|
+
87:
|
394
|
+
88: <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>
|
395
|
+
89: <span class="ruby-identifier">defval</span> = <span class="ruby-identifier">defval</span>.<span class="ruby-identifier">shift</span>
|
396
|
+
90: <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>]
|
397
|
+
91: <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>]
|
398
|
+
92: <span class="ruby-identifier">defval</span>
|
399
|
+
93: <span class="ruby-keyword kw">end</span>
|
400
|
+
94: <span class="ruby-comment cmt">#--}}}</span>
|
401
|
+
95: <span class="ruby-keyword kw">end</span>
|
393
402
|
</pre>
|
394
403
|
</div>
|
395
404
|
</div>
|
@@ -406,173 +415,293 @@ just fork with out silly warnings
|
|
406
415
|
|
407
416
|
<div class="method-description">
|
408
417
|
<p>
|
409
|
-
|
410
|
-
|
411
|
-
|
418
|
+
sets up a child process serving any object as a DRb server running locally
|
419
|
+
on unix domain sockets. the child process has a <a
|
420
|
+
href="Slave/LifeLine.html">LifeLine</a> established between it and the
|
421
|
+
parent, making it impossible for the child to outlive the parent (become a
|
422
|
+
zombie). the object to serve is specfied either directly using the
|
423
|
+
‘object’/:object keyword
|
412
424
|
</p>
|
425
|
+
<pre>
|
426
|
+
Slave.new :object => MyServer.new
|
427
|
+
</pre>
|
428
|
+
<p>
|
429
|
+
or, preferably, using the block form
|
430
|
+
</p>
|
431
|
+
<pre>
|
432
|
+
Slave.new{ MyServer.new }
|
433
|
+
</pre>
|
434
|
+
<p>
|
435
|
+
when the block form is used the object is contructed in the child process
|
436
|
+
itself. this is quite advantageous if the child object consumes resources
|
437
|
+
or opens file handles (db connections, etc). by contructing the object in
|
438
|
+
the child any resources are consumed from the child’s address space
|
439
|
+
and things like open file handles will not be carried into subsequent child
|
440
|
+
processes (via standard unix fork semantics). in the event that a block is
|
441
|
+
specified but the object cannot be constructed and, instead, throws and
|
442
|
+
Exception, that exception will be propogated to the parent process.
|
443
|
+
</p>
|
444
|
+
<p>
|
445
|
+
opts may contain the following keys, as either strings or symbols
|
446
|
+
</p>
|
447
|
+
<pre>
|
448
|
+
object : specify the slave object. otherwise block value is used.
|
449
|
+
socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
|
450
|
+
debug : turn on some logging to STDERR
|
451
|
+
psname : specify the name that will appear in 'top' ($0)
|
452
|
+
at_exit : specify a lambda to be called in the *parent* when the child dies
|
453
|
+
dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
|
454
|
+
threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
|
455
|
+
</pre>
|
413
456
|
<p><a class="source-toggle" href="#"
|
414
457
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
415
458
|
<div class="method-source-code" id="M000005-source">
|
416
459
|
<pre>
|
417
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
460
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 321</span>
|
461
|
+
321: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
462
|
+
322: <span class="ruby-comment cmt">#--{{{</span>
|
463
|
+
323: <span class="ruby-identifier">getopt</span> = <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
|
464
|
+
324:
|
465
|
+
325: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'object'</span>]
|
466
|
+
326: <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>)
|
467
|
+
327: <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>)
|
468
|
+
328: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'psname'</span>]
|
469
|
+
329: <span class="ruby-ivar">@at_exit</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'at_exit'</span>]
|
470
|
+
330: <span class="ruby-ivar">@dumped</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'dumped'</span>]
|
471
|
+
331: <span class="ruby-ivar">@threadsafe</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'threadsafe'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>(<span class="ruby-value str">'threadsafe'</span>)
|
472
|
+
332:
|
473
|
+
333: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'no slave object or slave object block provided!'</span> <span class="ruby-keyword kw">if</span>
|
474
|
+
334: <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>
|
475
|
+
335:
|
476
|
+
336: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
|
477
|
+
337: <span class="ruby-ivar">@waiter</span> = <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
|
478
|
+
338: <span class="ruby-ivar">@lifeline</span> = <span class="ruby-constant">LifeLine</span>.<span class="ruby-identifier">new</span>
|
479
|
+
339:
|
480
|
+
340: <span class="ruby-comment cmt"># weird syntax because dot/rdoc chokes on this!?!?</span>
|
481
|
+
341: <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>
|
482
|
+
342: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
483
|
+
343: <span class="ruby-identifier">o</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
|
484
|
+
344: <span class="ruby-keyword kw">class</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">o</span>
|
485
|
+
345: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value str">'__slave_object_failure__'</span>
|
486
|
+
346: <span class="ruby-keyword kw">end</span>
|
487
|
+
347: <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>]
|
488
|
+
348: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">o</span>
|
489
|
+
349: <span class="ruby-keyword kw">end</span>
|
490
|
+
350:
|
491
|
+
351: <span class="ruby-comment cmt">#</span>
|
492
|
+
352: <span class="ruby-comment cmt"># child</span>
|
493
|
+
353: <span class="ruby-comment cmt">#</span>
|
494
|
+
354: <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>))
|
495
|
+
355: <span class="ruby-identifier">e</span> = <span class="ruby-keyword kw">nil</span>
|
496
|
+
356: <span class="ruby-keyword kw">begin</span>
|
497
|
+
357: <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> }
|
498
|
+
358: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">catch</span>
|
499
|
+
359:
|
500
|
+
360: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@obj</span>
|
501
|
+
361: <span class="ruby-ivar">@object</span> = <span class="ruby-ivar">@obj</span>
|
502
|
+
362: <span class="ruby-keyword kw">else</span>
|
503
|
+
363: <span class="ruby-keyword kw">begin</span>
|
504
|
+
364: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
|
505
|
+
365: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
506
|
+
366: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
|
507
|
+
367: <span class="ruby-keyword kw">end</span>
|
508
|
+
368: <span class="ruby-keyword kw">end</span>
|
509
|
+
369:
|
510
|
+
370: <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>
|
511
|
+
371: <span class="ruby-keyword kw">begin</span>
|
512
|
+
372: <span class="ruby-identifier">block</span>[<span class="ruby-ivar">@obj</span>]
|
513
|
+
373: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
514
|
+
374: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
|
515
|
+
375: <span class="ruby-keyword kw">end</span>
|
516
|
+
376: <span class="ruby-keyword kw">end</span>
|
517
|
+
377:
|
518
|
+
378: <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>))
|
519
|
+
379:
|
520
|
+
380: <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>)
|
521
|
+
381: <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">DRbUndumped</span>
|
522
|
+
382: <span class="ruby-keyword kw">end</span>
|
523
|
+
383:
|
524
|
+
384: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@threadsafe</span>
|
525
|
+
385: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">ThreadSafe</span>.<span class="ruby-identifier">new</span> <span class="ruby-ivar">@object</span>
|
526
|
+
386: <span class="ruby-keyword kw">end</span>
|
527
|
+
387:
|
528
|
+
388: <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>
|
529
|
+
389: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
|
530
|
+
390: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
|
531
|
+
391:
|
532
|
+
392: <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>)
|
533
|
+
393:
|
534
|
+
394: <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>
|
535
|
+
395: <span class="ruby-identifier">se</span> = <span class="ruby-keyword kw">nil</span>
|
536
|
+
396: <span class="ruby-keyword kw">begin</span>
|
537
|
+
397: <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 }_#{ rand }"</span>)
|
538
|
+
398: <span class="ruby-identifier">u</span> = <span class="ruby-node">"drbunix://#{ s }"</span>
|
539
|
+
399: <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>
|
540
|
+
400: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
|
541
|
+
401: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
|
542
|
+
402: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - socket <#{ @socket }>"</span> }
|
543
|
+
403: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - uri <#{ @uri }>"</span> }
|
544
|
+
404: <span class="ruby-keyword kw">break</span>
|
545
|
+
405: <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">></span> <span class="ruby-identifier">se</span>
|
546
|
+
406: <span class="ruby-keyword kw">nil</span>
|
547
|
+
407: <span class="ruby-keyword kw">end</span>
|
548
|
+
408: <span class="ruby-keyword kw">end</span>
|
549
|
+
409:
|
550
|
+
410: <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>
|
551
|
+
411: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
|
552
|
+
412: <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>
|
553
|
+
413: <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>
|
554
|
+
414: <span class="ruby-identifier">exit</span>
|
555
|
+
415: <span class="ruby-keyword kw">end</span>
|
556
|
+
416:
|
557
|
+
417: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">puts</span> <span class="ruby-ivar">@socket</span>
|
558
|
+
418: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">cling</span>
|
559
|
+
419: <span class="ruby-keyword kw">else</span>
|
560
|
+
420: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">release</span>
|
561
|
+
421: <span class="ruby-identifier">warn</span> <span class="ruby-node">"slave(#{ $$ }) could not create socket!"</span>
|
562
|
+
422: <span class="ruby-identifier">exit</span>
|
563
|
+
423: <span class="ruby-keyword kw">end</span>
|
564
|
+
424: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
565
|
+
425: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
566
|
+
426: <span class="ruby-keyword kw">ensure</span>
|
567
|
+
427: <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>
|
568
|
+
428: <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>)
|
569
|
+
429: <span class="ruby-keyword kw">end</span>
|
570
|
+
430: <span class="ruby-comment cmt">#</span>
|
571
|
+
431: <span class="ruby-comment cmt"># parent </span>
|
572
|
+
432: <span class="ruby-comment cmt">#</span>
|
573
|
+
433: <span class="ruby-keyword kw">else</span>
|
574
|
+
434: <span class="ruby-identifier">detach</span>
|
575
|
+
435: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">throw</span>
|
576
|
+
436:
|
577
|
+
437: <span class="ruby-identifier">buf</span> = <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">gets</span>
|
578
|
+
438: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"failed to find slave socket"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">empty?</span>
|
579
|
+
439: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">strip</span>
|
580
|
+
440: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - socket <#{ @socket }>"</span> }
|
581
|
+
441:
|
582
|
+
442: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>
|
583
|
+
443: <span class="ruby-ivar">@at_exit_thread</span> = <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">on_cut</span>{
|
584
|
+
444: <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">'call'</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@at_exit</span>.<span class="ruby-identifier">call</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">:</span> <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>)
|
585
|
+
445: }
|
586
|
+
446: <span class="ruby-keyword kw">end</span>
|
587
|
+
447:
|
588
|
+
448: <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>
|
589
|
+
449: <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> }
|
590
|
+
450: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">"drbunix://#{ socket }"</span>
|
591
|
+
451: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - uri <#{ @uri }>"</span> }
|
592
|
+
452: <span class="ruby-comment cmt">#</span>
|
593
|
+
453: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
|
594
|
+
454: <span class="ruby-comment cmt">#</span>
|
595
|
+
455: <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>
|
596
|
+
456: <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>
|
597
|
+
457: <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>
|
598
|
+
458: <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>
|
599
|
+
459: (<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>
|
600
|
+
460: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
601
|
+
461: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
|
602
|
+
462: <span class="ruby-keyword kw">end</span>
|
603
|
+
463: <span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>)
|
604
|
+
464: <span class="ruby-keyword kw">else</span>
|
605
|
+
465: <span class="ruby-identifier">raise</span> <span class="ruby-node">"failed to find slave socket <#{ @socket }>"</span>
|
606
|
+
466: <span class="ruby-keyword kw">end</span>
|
607
|
+
467: <span class="ruby-keyword kw">end</span>
|
608
|
+
468: <span class="ruby-comment cmt">#--}}}</span>
|
609
|
+
469: <span class="ruby-keyword kw">end</span>
|
610
|
+
</pre>
|
611
|
+
</div>
|
612
|
+
</div>
|
613
|
+
</div>
|
614
|
+
|
615
|
+
<div id="method-M000015" class="method-detail">
|
616
|
+
<a name="M000015"></a>
|
617
|
+
|
618
|
+
<div class="method-heading">
|
619
|
+
<a href="#M000015" class="method-signature">
|
620
|
+
<span class="method-name">object</span><span class="method-args">opts = {}, &b</span>
|
621
|
+
</a>
|
622
|
+
</div>
|
623
|
+
|
624
|
+
<div class="method-description">
|
625
|
+
<p>
|
626
|
+
a simple convenience method which returns an <b>object</b> from another
|
627
|
+
process. the object returned is the result of the supplied block. eg
|
628
|
+
</p>
|
629
|
+
<pre>
|
630
|
+
object = Slave.object{ processor_intensive_object_built_in_child_process() }
|
631
|
+
</pre>
|
632
|
+
<p>
|
633
|
+
eg.
|
634
|
+
</p>
|
635
|
+
<p>
|
636
|
+
the call can be made asynchronous via the ‘async’/:async
|
637
|
+
keyword
|
638
|
+
</p>
|
639
|
+
<pre>
|
640
|
+
thread = Slave.object(:async=>true){ long_processor_intensive_object_built_in_child_process() }
|
641
|
+
|
642
|
+
# go on about your coding business then, later
|
643
|
+
|
644
|
+
object = thread.value
|
645
|
+
</pre>
|
646
|
+
<p><a class="source-toggle" href="#"
|
647
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
648
|
+
<div class="method-source-code" id="M000015-source">
|
649
|
+
<pre>
|
650
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 589</span>
|
651
|
+
589: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">object</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>
|
652
|
+
590: <span class="ruby-comment cmt">#--{{{</span>
|
653
|
+
591: <span class="ruby-identifier">l</span> = <span class="ruby-identifier">lambda</span>{ <span class="ruby-keyword kw">begin</span>; <span class="ruby-identifier">b</span>.<span class="ruby-identifier">call</span>; <span class="ruby-keyword kw">ensure</span>; <span class="ruby-identifier">exit</span>; <span class="ruby-keyword kw">end</span> }
|
654
|
+
592:
|
655
|
+
593: <span class="ruby-identifier">async</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'async'</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:async</span>)
|
656
|
+
594:
|
657
|
+
595: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'object'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:object</span>] = <span class="ruby-identifier">l</span>
|
658
|
+
596: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'dumped'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:dumped</span>] = <span class="ruby-keyword kw">true</span>
|
659
|
+
597:
|
660
|
+
598: <span class="ruby-identifier">slave</span> = <span class="ruby-constant">Slave</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">opts</span>
|
661
|
+
599:
|
662
|
+
600: <span class="ruby-identifier">async</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span> } <span class="ruby-operator">:</span> <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span>
|
663
|
+
601: <span class="ruby-comment cmt">#--}}}</span>
|
664
|
+
602: <span class="ruby-keyword kw">end</span>
|
665
|
+
</pre>
|
666
|
+
</div>
|
667
|
+
</div>
|
668
|
+
</div>
|
669
|
+
|
670
|
+
<div id="method-M000016" class="method-detail">
|
671
|
+
<a name="M000016"></a>
|
672
|
+
|
673
|
+
<div class="method-heading">
|
674
|
+
<a href="#M000016" class="method-signature">
|
675
|
+
<span class="method-name">object</span><span class="method-args">opts = {}, &b</span>
|
676
|
+
</a>
|
677
|
+
</div>
|
678
|
+
|
679
|
+
<div class="method-description">
|
680
|
+
<p><a class="source-toggle" href="#"
|
681
|
+
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
682
|
+
<div class="method-source-code" id="M000016-source">
|
683
|
+
<pre>
|
684
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 603</span>
|
685
|
+
603: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">object</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>
|
686
|
+
604: <span class="ruby-comment cmt">#--{{{</span>
|
687
|
+
605: <span class="ruby-identifier">async</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'async'</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:async</span>)
|
688
|
+
606:
|
689
|
+
607: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'object'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:object</span>] = <span class="ruby-identifier">lambda</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
|
690
|
+
608: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'dumped'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:dumped</span>] = <span class="ruby-keyword kw">true</span>
|
691
|
+
609:
|
692
|
+
610: <span class="ruby-identifier">slave</span> = <span class="ruby-constant">Slave</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">opts</span>
|
693
|
+
611:
|
694
|
+
612: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">slave</span><span class="ruby-operator">|</span>
|
695
|
+
613: <span class="ruby-keyword kw">begin</span>
|
696
|
+
614: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span>
|
697
|
+
615: <span class="ruby-keyword kw">ensure</span>
|
698
|
+
616: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">shutdown</span>
|
699
|
+
617: <span class="ruby-keyword kw">end</span>
|
700
|
+
618: <span class="ruby-keyword kw">end</span>
|
701
|
+
619:
|
702
|
+
620: <span class="ruby-identifier">async</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">value</span>[<span class="ruby-identifier">slave</span>] } <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">slave</span>]
|
703
|
+
621: <span class="ruby-comment cmt">#--}}}</span>
|
704
|
+
622: <span class="ruby-keyword kw">end</span>
|
576
705
|
</pre>
|
577
706
|
</div>
|
578
707
|
</div>
|
@@ -592,8 +721,8 @@ opts may contain the keys ‘object’,
|
|
592
721
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
593
722
|
<div class="method-source-code" id="M000001-source">
|
594
723
|
<pre>
|
595
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
596
|
-
|
724
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 44</span>
|
725
|
+
44: <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>
|
597
726
|
</pre>
|
598
727
|
</div>
|
599
728
|
</div>
|
@@ -618,12 +747,12 @@ see docs for <a href="Slave.html#M000002">Slave.default</a>
|
|
618
747
|
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
619
748
|
<div class="method-source-code" id="M000012-source">
|
620
749
|
<pre>
|
621
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
750
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 548</span>
|
751
|
+
548: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
|
752
|
+
549: <span class="ruby-comment cmt">#--{{{</span>
|
753
|
+
550: <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>
|
754
|
+
551: <span class="ruby-comment cmt">#--}}}</span>
|
755
|
+
552: <span class="ruby-keyword kw">end</span>
|
627
756
|
</pre>
|
628
757
|
</div>
|
629
758
|
</div>
|
@@ -648,33 +777,33 @@ collect the status
|
|
648
777
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
649
778
|
<div class="method-source-code" id="M000006-source">
|
650
779
|
<pre>
|
651
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
780
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 475</span>
|
781
|
+
475: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">detach</span>
|
782
|
+
476: <span class="ruby-comment cmt">#--{{{</span>
|
783
|
+
477: <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>
|
784
|
+
478: <span class="ruby-keyword kw">begin</span>
|
785
|
+
479: <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>
|
786
|
+
480: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
787
|
+
481: <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">"\n"</span>)
|
788
|
+
482: <span class="ruby-identifier">warn</span> <span class="ruby-node">"#{ m } (#{ c })\n#{ b }"</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>
|
789
|
+
483: <span class="ruby-keyword kw">end</span>
|
790
|
+
484: <span class="ruby-keyword kw">end</span>
|
791
|
+
485:
|
792
|
+
486: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
|
793
|
+
487: <span class="ruby-identifier">shutdown</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
794
|
+
488: <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>
|
795
|
+
489: <span class="ruby-keyword kw">end</span>
|
796
|
+
490:
|
797
|
+
491: <span class="ruby-ivar">@waiter</span> =
|
798
|
+
492: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
|
799
|
+
493: <span class="ruby-keyword kw">begin</span>
|
800
|
+
494: <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>
|
801
|
+
495: <span class="ruby-keyword kw">ensure</span>
|
802
|
+
496: <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> }
|
803
|
+
497: <span class="ruby-keyword kw">end</span>
|
804
|
+
498: <span class="ruby-keyword kw">end</span>
|
805
|
+
499: <span class="ruby-comment cmt">#--}}}</span>
|
806
|
+
500: <span class="ruby-keyword kw">end</span>
|
678
807
|
</pre>
|
679
808
|
</div>
|
680
809
|
</div>
|
@@ -697,12 +826,12 @@ generate a default name to appear in ps/top
|
|
697
826
|
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
698
827
|
<div class="method-source-code" id="M000011-source">
|
699
828
|
<pre>
|
700
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
829
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 540</span>
|
830
|
+
540: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
|
831
|
+
541: <span class="ruby-comment cmt">#--{{{</span>
|
832
|
+
542: <span class="ruby-node">"slave_#{ obj.class }_#{ obj.object_id }_#{ Process::ppid }_#{ 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>)
|
833
|
+
543: <span class="ruby-comment cmt">#--}}}</span>
|
834
|
+
544: <span class="ruby-keyword kw">end</span>
|
706
835
|
</pre>
|
707
836
|
</div>
|
708
837
|
</div>
|
@@ -725,12 +854,12 @@ see docs for <a href="Slave.html#M000003">Slave.getopts</a>
|
|
725
854
|
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
726
855
|
<div class="method-source-code" id="M000013-source">
|
727
856
|
<pre>
|
728
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
857
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 556</span>
|
858
|
+
556: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
|
859
|
+
557: <span class="ruby-comment cmt">#--{{{</span>
|
860
|
+
558: <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>
|
861
|
+
559: <span class="ruby-comment cmt">#--}}}</span>
|
862
|
+
560: <span class="ruby-keyword kw">end</span>
|
734
863
|
</pre>
|
735
864
|
</div>
|
736
865
|
</div>
|
@@ -747,7 +876,7 @@ see docs for <a href="Slave.html#M000003">Slave.getopts</a>
|
|
747
876
|
|
748
877
|
<div class="method-description">
|
749
878
|
<p>
|
750
|
-
|
879
|
+
cuts the lifeline and kills the child process - give the key
|
751
880
|
‘quiet’ to ignore errors shutting down, including having
|
752
881
|
already shutdown
|
753
882
|
</p>
|
@@ -755,17 +884,17 @@ already shutdown
|
|
755
884
|
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
756
885
|
<div class="method-source-code" id="M000009-source">
|
757
886
|
<pre>
|
758
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
887
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 519</span>
|
888
|
+
519: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span> <span class="ruby-identifier">opts</span> = {}
|
889
|
+
520: <span class="ruby-comment cmt">#--{{{</span>
|
890
|
+
521: <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>]
|
891
|
+
522: <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> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span>
|
892
|
+
523: <span class="ruby-keyword kw">begin</span>; <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-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>; <span class="ruby-keyword kw">end</span>
|
893
|
+
524: <span class="ruby-keyword kw">begin</span>; <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">cut</span>; <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>; <span class="ruby-keyword kw">end</span>
|
894
|
+
525: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">quiet</span>
|
895
|
+
526: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
|
896
|
+
527: <span class="ruby-comment cmt">#--}}}</span>
|
897
|
+
528: <span class="ruby-keyword kw">end</span>
|
769
898
|
</pre>
|
770
899
|
</div>
|
771
900
|
</div>
|
@@ -788,12 +917,12 @@ true
|
|
788
917
|
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
789
918
|
<div class="method-source-code" id="M000010-source">
|
790
919
|
<pre>
|
791
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
920
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 532</span>
|
921
|
+
532: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown?</span>
|
922
|
+
533: <span class="ruby-comment cmt">#--{{{</span>
|
923
|
+
534: <span class="ruby-ivar">@shutdown</span>
|
924
|
+
535: <span class="ruby-comment cmt">#--}}}</span>
|
925
|
+
536: <span class="ruby-keyword kw">end</span>
|
797
926
|
</pre>
|
798
927
|
</div>
|
799
928
|
</div>
|
@@ -816,12 +945,15 @@ debugging output - ENV[‘SLAVE_DEBUG’]=1 to enable
|
|
816
945
|
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
817
946
|
<div class="method-source-code" id="M000014-source">
|
818
947
|
<pre>
|
819
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
948
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 564</span>
|
949
|
+
564: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
|
950
|
+
565: <span class="ruby-comment cmt">#--{{{</span>
|
951
|
+
566: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span>
|
952
|
+
567: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-keyword kw">yield</span>
|
953
|
+
568: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">flush</span>
|
954
|
+
569: <span class="ruby-keyword kw">end</span>
|
955
|
+
570: <span class="ruby-comment cmt">#--}}}</span>
|
956
|
+
571: <span class="ruby-keyword kw">end</span>
|
825
957
|
</pre>
|
826
958
|
</div>
|
827
959
|
</div>
|
@@ -848,14 +980,14 @@ is given a thread is returned to do the waiting in an async fashion. eg
|
|
848
980
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
849
981
|
<div class="method-source-code" id="M000007-source">
|
850
982
|
<pre>
|
851
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
983
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 507</span>
|
984
|
+
507: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>
|
985
|
+
508: <span class="ruby-comment cmt">#--{{{</span>
|
986
|
+
509: <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>}
|
987
|
+
510: <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>]
|
988
|
+
511: <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> ]
|
989
|
+
512: <span class="ruby-comment cmt">#--}}}</span>
|
990
|
+
513: <span class="ruby-keyword kw">end</span>
|
859
991
|
</pre>
|
860
992
|
</div>
|
861
993
|
</div>
|