slave 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +16 -11
- data/Rakefile +14 -8
- data/lib/slave.rb +66 -81
- data/{README.tmpl → readme.erb} +4 -1
- data/samples/a.rb +2 -2
- data/slave.gemspec +42 -0
- metadata +8 -31
- data/doc/classes/Slave.html +0 -997
- data/doc/classes/Slave/LifeLine.html +0 -419
- data/doc/classes/Slave/ThreadSafe.html +0 -292
- data/doc/classes/Slave/ThreadSafeHash.html +0 -158
- data/doc/classes/o.html +0 -117
- data/doc/created.rid +0 -1
- data/doc/dot/f_0.dot +0 -14
- data/doc/dot/f_0.jpg +0 -0
- data/doc/dot/f_1.dot +0 -29
- data/doc/dot/f_1.jpg +0 -0
- data/doc/files/README.html +0 -411
- data/doc/files/lib/slave_rb.html +0 -120
- data/doc/fr_class_index.html +0 -30
- data/doc/fr_file_index.html +0 -28
- data/doc/fr_method_index.html +0 -56
- data/doc/index.html +0 -24
- data/doc/rdoc-style.css +0 -208
- data/gemspec.rb +0 -23
- data/gen_readme.rb +0 -32
- data/install.rb +0 -206
- data/rdoc.cmd +0 -1
- data/test.old/slave.rb +0 -21
data/{README.tmpl → readme.erb}
RENAMED
@@ -38,6 +38,9 @@ URIS
|
|
38
38
|
http://codeforpeople.com/lib/ruby/slave
|
39
39
|
|
40
40
|
HISTORY
|
41
|
+
1.3.0:
|
42
|
+
- fixes for 1.9.2 (undef object_id)
|
43
|
+
- fixes for osx (too long socket names)
|
41
44
|
|
42
45
|
1.2.1:
|
43
46
|
- jruby/ThreadSafe patches from skaar and ez. using slave.rb with jruby,
|
@@ -105,4 +108,4 @@ HISTORY
|
|
105
108
|
|
106
109
|
SAMPLES
|
107
110
|
|
108
|
-
@samples
|
111
|
+
<%= @samples %>
|
data/samples/a.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'slave'
|
2
|
-
|
2
|
+
|
3
3
|
# simple usage is simply to stand up a server object as a slave. you do not
|
4
4
|
# need to wait for the server, join it, etc. it will die when the parent
|
5
5
|
# process dies - even under 'kill -9' conditions
|
6
6
|
#
|
7
7
|
class Server
|
8
|
-
def add_two
|
8
|
+
def add_two(n)
|
9
9
|
n + 2
|
10
10
|
end
|
11
11
|
end
|
data/slave.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## slave.gemspec
|
2
|
+
#
|
3
|
+
|
4
|
+
Gem::Specification::new do |spec|
|
5
|
+
spec.name = "slave"
|
6
|
+
spec.version = "1.3.0"
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.summary = "slave"
|
9
|
+
spec.description = "description: slave kicks the ass"
|
10
|
+
|
11
|
+
spec.files =
|
12
|
+
["README",
|
13
|
+
"Rakefile",
|
14
|
+
"lib",
|
15
|
+
"lib/slave-1.2.1.rb",
|
16
|
+
"lib/slave.rb",
|
17
|
+
"readme.erb",
|
18
|
+
"samples",
|
19
|
+
"samples/a.rb",
|
20
|
+
"samples/b.rb",
|
21
|
+
"samples/c.rb",
|
22
|
+
"samples/d.rb",
|
23
|
+
"samples/e.rb",
|
24
|
+
"samples/f.rb",
|
25
|
+
"samples/g.rb",
|
26
|
+
"slave.gemspec"]
|
27
|
+
|
28
|
+
spec.executables = []
|
29
|
+
|
30
|
+
spec.require_path = "lib"
|
31
|
+
|
32
|
+
spec.test_files = nil
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
spec.extensions.push(*[])
|
37
|
+
|
38
|
+
spec.rubyforge_project = "codeforpeople"
|
39
|
+
spec.author = "Ara T. Howard"
|
40
|
+
spec.email = "ara.t.howard@gmail.com"
|
41
|
+
spec.homepage = "https://github.com/ahoward/slave"
|
42
|
+
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 1.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ara T. Howard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-10 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: "description: slave kicks the ass"
|
@@ -28,31 +28,10 @@ extra_rdoc_files: []
|
|
28
28
|
|
29
29
|
files:
|
30
30
|
- README
|
31
|
-
- README.tmpl
|
32
31
|
- Rakefile
|
33
|
-
- doc/classes/Slave.html
|
34
|
-
- doc/classes/Slave/LifeLine.html
|
35
|
-
- doc/classes/Slave/ThreadSafe.html
|
36
|
-
- doc/classes/Slave/ThreadSafeHash.html
|
37
|
-
- doc/classes/o.html
|
38
|
-
- doc/created.rid
|
39
|
-
- doc/dot/f_0.dot
|
40
|
-
- doc/dot/f_0.jpg
|
41
|
-
- doc/dot/f_1.dot
|
42
|
-
- doc/dot/f_1.jpg
|
43
|
-
- doc/files/README.html
|
44
|
-
- doc/files/lib/slave_rb.html
|
45
|
-
- doc/fr_class_index.html
|
46
|
-
- doc/fr_file_index.html
|
47
|
-
- doc/fr_method_index.html
|
48
|
-
- doc/index.html
|
49
|
-
- doc/rdoc-style.css
|
50
|
-
- gemspec.rb
|
51
|
-
- gen_readme.rb
|
52
|
-
- install.rb
|
53
32
|
- lib/slave-1.2.1.rb
|
54
33
|
- lib/slave.rb
|
55
|
-
-
|
34
|
+
- readme.erb
|
56
35
|
- samples/a.rb
|
57
36
|
- samples/b.rb
|
58
37
|
- samples/c.rb
|
@@ -60,12 +39,10 @@ files:
|
|
60
39
|
- samples/e.rb
|
61
40
|
- samples/f.rb
|
62
41
|
- samples/g.rb
|
63
|
-
-
|
42
|
+
- slave.gemspec
|
64
43
|
homepage: https://github.com/ahoward/slave
|
65
44
|
licenses: []
|
66
45
|
|
67
|
-
metadata: {}
|
68
|
-
|
69
46
|
post_install_message:
|
70
47
|
rdoc_options: []
|
71
48
|
|
@@ -92,9 +69,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
69
|
requirements: []
|
93
70
|
|
94
71
|
rubyforge_project: codeforpeople
|
95
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.11
|
96
73
|
signing_key:
|
97
|
-
specification_version:
|
74
|
+
specification_version: 3
|
98
75
|
summary: slave
|
99
76
|
test_files: []
|
100
77
|
|
data/doc/classes/Slave.html
DELETED
@@ -1,997 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>Class: Slave</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="classHeader">
|
50
|
-
<table class="header-table">
|
51
|
-
<tr class="top-aligned-row">
|
52
|
-
<td><strong>Class</strong></td>
|
53
|
-
<td class="class-name-in-header">Slave</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../files/lib/slave_rb.html">
|
59
|
-
lib/slave.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
|
-
</td>
|
63
|
-
</tr>
|
64
|
-
|
65
|
-
<tr class="top-aligned-row">
|
66
|
-
<td><strong>Parent:</strong></td>
|
67
|
-
<td>
|
68
|
-
Object
|
69
|
-
</td>
|
70
|
-
</tr>
|
71
|
-
</table>
|
72
|
-
</div>
|
73
|
-
<!-- banner header -->
|
74
|
-
|
75
|
-
<div id="bodyContent">
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
<div id="contextContent">
|
80
|
-
<div id="diagram">
|
81
|
-
<map id="map" name="map">
|
82
|
-
<area shape="rect" coords="27,50,99,98" href="Slave.html" alt="Slave" />
|
83
|
-
</map>
|
84
|
-
<img src="../dot/f_1.jpg" usemap="#map" border="0" alt="dot/f_1.jpg">
|
85
|
-
</div>
|
86
|
-
|
87
|
-
<div id="description">
|
88
|
-
<p>
|
89
|
-
the <a href="Slave.html">Slave</a> class encapsulates the work of setting
|
90
|
-
up a drb server in another process running on localhost via unix domain
|
91
|
-
sockets. the slave process is attached to it‘s parent via a <a
|
92
|
-
href="Slave/LifeLine.html">LifeLine</a> which is designed such that the
|
93
|
-
slave cannot out-live it‘s parent and become a zombie, even if the
|
94
|
-
parent dies and early death, such as by ‘kill -9’. the concept
|
95
|
-
and purpose of the <a href="Slave.html">Slave</a> class is to be able to
|
96
|
-
setup any server <a href="Slave.html#M000015">object</a> in another process
|
97
|
-
so easily that using a multi-process, drb/ipc, based design is as easy, or
|
98
|
-
easier, than a multi-threaded one. eg
|
99
|
-
</p>
|
100
|
-
<pre>
|
101
|
-
class Server
|
102
|
-
def add_two n
|
103
|
-
n + 2
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
slave = Slave.new 'object' => Server.new
|
108
|
-
server = slave.object
|
109
|
-
|
110
|
-
p server.add_two(40) #=> 42
|
111
|
-
</pre>
|
112
|
-
<p>
|
113
|
-
two other methods of providing server objects exist:
|
114
|
-
</p>
|
115
|
-
<p>
|
116
|
-
a) server = Server.new "this is called the parent" }
|
117
|
-
</p>
|
118
|
-
<pre>
|
119
|
-
Slave.new(:object=>server){|s| puts "#{ s.inspect } passed to block in child process"}
|
120
|
-
</pre>
|
121
|
-
<p>
|
122
|
-
b) <a href="Slave.html#M000005">Slave.new</a>{ Server.new "this is
|
123
|
-
called only in the child" }
|
124
|
-
</p>
|
125
|
-
<p>
|
126
|
-
of the two ‘b’ is preferred.
|
127
|
-
</p>
|
128
|
-
|
129
|
-
</div>
|
130
|
-
|
131
|
-
|
132
|
-
</div>
|
133
|
-
|
134
|
-
<div id="method-list">
|
135
|
-
<h3 class="section-bar">Methods</h3>
|
136
|
-
|
137
|
-
<div class="name-list">
|
138
|
-
<a href="#M000012">default</a>
|
139
|
-
<a href="#M000002">default</a>
|
140
|
-
<a href="#M000006">detach</a>
|
141
|
-
<a href="#M000004">fork</a>
|
142
|
-
<a href="#M000011">gen_psname</a>
|
143
|
-
<a href="#M000003">getopts</a>
|
144
|
-
<a href="#M000013">getopts</a>
|
145
|
-
<a href="#M000005">new</a>
|
146
|
-
<a href="#M000015">object</a>
|
147
|
-
<a href="#M000009">shutdown</a>
|
148
|
-
<a href="#M000010">shutdown?</a>
|
149
|
-
<a href="#M000014">trace</a>
|
150
|
-
<a href="#M000001">version</a>
|
151
|
-
<a href="#M000007">wait</a>
|
152
|
-
<a href="#M000008">wait2</a>
|
153
|
-
</div>
|
154
|
-
</div>
|
155
|
-
|
156
|
-
</div>
|
157
|
-
|
158
|
-
|
159
|
-
<!-- if includes -->
|
160
|
-
|
161
|
-
<div id="section">
|
162
|
-
|
163
|
-
<div id="class-list">
|
164
|
-
<h3 class="section-bar">Classes and Modules</h3>
|
165
|
-
|
166
|
-
Class <a href="Slave/LifeLine.html" class="link">Slave::LifeLine</a><br />
|
167
|
-
Class <a href="Slave/ThreadSafe.html" class="link">Slave::ThreadSafe</a><br />
|
168
|
-
Class <a href="Slave/ThreadSafeHash.html" class="link">Slave::ThreadSafeHash</a><br />
|
169
|
-
|
170
|
-
</div>
|
171
|
-
|
172
|
-
<div id="constants-list">
|
173
|
-
<h3 class="section-bar">Constants</h3>
|
174
|
-
|
175
|
-
<div class="name-list">
|
176
|
-
<table summary="Constants">
|
177
|
-
<tr class="top-aligned-row context-row">
|
178
|
-
<td class="context-item-name">VERSION</td>
|
179
|
-
<td>=</td>
|
180
|
-
<td class="context-item-value">'1.2.1'</td>
|
181
|
-
</tr>
|
182
|
-
<tr class="top-aligned-row context-row">
|
183
|
-
<td class="context-item-name">DEFAULT_SOCKET_CREATION_ATTEMPTS</td>
|
184
|
-
<td>=</td>
|
185
|
-
<td class="context-item-value">Integer(ENV['SLAVE_SOCKET_CREATION_ATTEMPTS'] || 42)</td>
|
186
|
-
<td width="3em"> </td>
|
187
|
-
<td class="context-item-desc">
|
188
|
-
env config
|
189
|
-
|
190
|
-
</td>
|
191
|
-
</tr>
|
192
|
-
<tr class="top-aligned-row context-row">
|
193
|
-
<td class="context-item-name">DEFAULT_DEBUG</td>
|
194
|
-
<td>=</td>
|
195
|
-
<td class="context-item-value">(ENV['SLAVE_DEBUG'] ? true : false)</td>
|
196
|
-
</tr>
|
197
|
-
<tr class="top-aligned-row context-row">
|
198
|
-
<td class="context-item-name">DEFAULT_THREADSAFE</td>
|
199
|
-
<td>=</td>
|
200
|
-
<td class="context-item-value">(ENV['SLAVE_THREADSAFE'] ? true : false)</td>
|
201
|
-
</tr>
|
202
|
-
</table>
|
203
|
-
</div>
|
204
|
-
</div>
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
<div id="attribute-list">
|
209
|
-
<h3 class="section-bar">Attributes</h3>
|
210
|
-
|
211
|
-
<div class="name-list">
|
212
|
-
<table>
|
213
|
-
<tr class="top-aligned-row context-row">
|
214
|
-
<td class="context-item-name">at_exit</td>
|
215
|
-
<td class="context-item-value"> [R] </td>
|
216
|
-
<td class="context-item-desc"></td>
|
217
|
-
</tr>
|
218
|
-
<tr class="top-aligned-row context-row">
|
219
|
-
<td class="context-item-name">debug</td>
|
220
|
-
<td class="context-item-value"> [RW] </td>
|
221
|
-
<td class="context-item-desc">
|
222
|
-
if this is true and you are running from a terminal information is printed
|
223
|
-
on STDERR
|
224
|
-
|
225
|
-
</td>
|
226
|
-
</tr>
|
227
|
-
<tr class="top-aligned-row context-row">
|
228
|
-
<td class="context-item-name">debug</td>
|
229
|
-
<td class="context-item-value"> [R] </td>
|
230
|
-
<td class="context-item-desc"></td>
|
231
|
-
</tr>
|
232
|
-
<tr class="top-aligned-row context-row">
|
233
|
-
<td class="context-item-name">dumped</td>
|
234
|
-
<td class="context-item-value"> [R] </td>
|
235
|
-
<td class="context-item-desc"></td>
|
236
|
-
</tr>
|
237
|
-
<tr class="top-aligned-row context-row">
|
238
|
-
<td class="context-item-name">obj</td>
|
239
|
-
<td class="context-item-value"> [R] </td>
|
240
|
-
<td class="context-item-desc">
|
241
|
-
attrs
|
242
|
-
|
243
|
-
</td>
|
244
|
-
</tr>
|
245
|
-
<tr class="top-aligned-row context-row">
|
246
|
-
<td class="context-item-name">object</td>
|
247
|
-
<td class="context-item-value"> [R] </td>
|
248
|
-
<td class="context-item-desc"></td>
|
249
|
-
</tr>
|
250
|
-
<tr class="top-aligned-row context-row">
|
251
|
-
<td class="context-item-name">pid</td>
|
252
|
-
<td class="context-item-value"> [R] </td>
|
253
|
-
<td class="context-item-desc"></td>
|
254
|
-
</tr>
|
255
|
-
<tr class="top-aligned-row context-row">
|
256
|
-
<td class="context-item-name">ppid</td>
|
257
|
-
<td class="context-item-value"> [R] </td>
|
258
|
-
<td class="context-item-desc"></td>
|
259
|
-
</tr>
|
260
|
-
<tr class="top-aligned-row context-row">
|
261
|
-
<td class="context-item-name">psname</td>
|
262
|
-
<td class="context-item-value"> [R] </td>
|
263
|
-
<td class="context-item-desc"></td>
|
264
|
-
</tr>
|
265
|
-
<tr class="top-aligned-row context-row">
|
266
|
-
<td class="context-item-name">socket</td>
|
267
|
-
<td class="context-item-value"> [R] </td>
|
268
|
-
<td class="context-item-desc"></td>
|
269
|
-
</tr>
|
270
|
-
<tr class="top-aligned-row context-row">
|
271
|
-
<td class="context-item-name">socket_creation_attempts</td>
|
272
|
-
<td class="context-item-value"> [RW] </td>
|
273
|
-
<td class="context-item-desc"></td>
|
274
|
-
</tr>
|
275
|
-
<tr class="top-aligned-row context-row">
|
276
|
-
<td class="context-item-name">socket_creation_attempts</td>
|
277
|
-
<td class="context-item-value"> [R] </td>
|
278
|
-
<td class="context-item-desc"></td>
|
279
|
-
</tr>
|
280
|
-
<tr class="top-aligned-row context-row">
|
281
|
-
<td class="context-item-name">status</td>
|
282
|
-
<td class="context-item-value"> [R] </td>
|
283
|
-
<td class="context-item-desc"></td>
|
284
|
-
</tr>
|
285
|
-
<tr class="top-aligned-row context-row">
|
286
|
-
<td class="context-item-name">threadsafe</td>
|
287
|
-
<td class="context-item-value"> [RW] </td>
|
288
|
-
<td class="context-item-desc">
|
289
|
-
if this is true all slave objects will be wrapped such that any call to the
|
290
|
-
<a href="Slave.html#M000015">object</a> is threadsafe. if you do not use
|
291
|
-
this you must ensure that your objects are threadsafe <em>yourself</em> as
|
292
|
-
this is required of any <a href="Slave.html#M000015">object</a> acting as a
|
293
|
-
drb server
|
294
|
-
|
295
|
-
</td>
|
296
|
-
</tr>
|
297
|
-
<tr class="top-aligned-row context-row">
|
298
|
-
<td class="context-item-name">uri</td>
|
299
|
-
<td class="context-item-value"> [R] </td>
|
300
|
-
<td class="context-item-desc"></td>
|
301
|
-
</tr>
|
302
|
-
</table>
|
303
|
-
</div>
|
304
|
-
</div>
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
<!-- if method_list -->
|
309
|
-
<div id="methods">
|
310
|
-
<h3 class="section-bar">Public Class methods</h3>
|
311
|
-
|
312
|
-
<div id="method-M000002" class="method-detail">
|
313
|
-
<a name="M000002"></a>
|
314
|
-
|
315
|
-
<div class="method-heading">
|
316
|
-
<a href="#M000002" class="method-signature">
|
317
|
-
<span class="method-name">default</span><span class="method-args">(key)</span>
|
318
|
-
</a>
|
319
|
-
</div>
|
320
|
-
|
321
|
-
<div class="method-description">
|
322
|
-
<p>
|
323
|
-
get a <a href="Slave.html#M000002">default</a> value
|
324
|
-
</p>
|
325
|
-
<p><a class="source-toggle" href="#"
|
326
|
-
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
327
|
-
<div class="method-source-code" id="M000002-source">
|
328
|
-
<pre>
|
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>
|
335
|
-
</pre>
|
336
|
-
</div>
|
337
|
-
</div>
|
338
|
-
</div>
|
339
|
-
|
340
|
-
<div id="method-M000004" class="method-detail">
|
341
|
-
<a name="M000004"></a>
|
342
|
-
|
343
|
-
<div class="method-heading">
|
344
|
-
<a href="#M000004" class="method-signature">
|
345
|
-
<span class="method-name">fork</span><span class="method-args">(&b)</span>
|
346
|
-
</a>
|
347
|
-
</div>
|
348
|
-
|
349
|
-
<div class="method-description">
|
350
|
-
<p>
|
351
|
-
just <a href="Slave.html#M000004">fork</a> with out silly warnings
|
352
|
-
</p>
|
353
|
-
<p><a class="source-toggle" href="#"
|
354
|
-
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
355
|
-
<div class="method-source-code" id="M000004-source">
|
356
|
-
<pre>
|
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">b</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">b</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>
|
369
|
-
</pre>
|
370
|
-
</div>
|
371
|
-
</div>
|
372
|
-
</div>
|
373
|
-
|
374
|
-
<div id="method-M000003" class="method-detail">
|
375
|
-
<a name="M000003"></a>
|
376
|
-
|
377
|
-
<div class="method-heading">
|
378
|
-
<a href="#M000003" class="method-signature">
|
379
|
-
<span class="method-name">getopts</span><span class="method-args">(opts)</span>
|
380
|
-
</a>
|
381
|
-
</div>
|
382
|
-
|
383
|
-
<div class="method-description">
|
384
|
-
<p><a class="source-toggle" href="#"
|
385
|
-
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
386
|
-
<div class="method-source-code" id="M000003-source">
|
387
|
-
<pre>
|
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>
|
402
|
-
</pre>
|
403
|
-
</div>
|
404
|
-
</div>
|
405
|
-
</div>
|
406
|
-
|
407
|
-
<div id="method-M000005" class="method-detail">
|
408
|
-
<a name="M000005"></a>
|
409
|
-
|
410
|
-
<div class="method-heading">
|
411
|
-
<a href="#M000005" class="method-signature">
|
412
|
-
<span class="method-name">new</span><span class="method-args">(opts = {})</span>
|
413
|
-
</a>
|
414
|
-
</div>
|
415
|
-
|
416
|
-
<div class="method-description">
|
417
|
-
<p>
|
418
|
-
sets up a child process serving any <a href="Slave.html#M000015">object</a>
|
419
|
-
as a DRb server running locally on unix domain sockets. the child process
|
420
|
-
has a <a href="Slave/LifeLine.html">LifeLine</a> established between it and
|
421
|
-
the parent, making it impossible for the child to outlive the parent
|
422
|
-
(become a zombie). the <a href="Slave.html#M000015">object</a> to serve is
|
423
|
-
specfied either directly using the ‘<a
|
424
|
-
href="Slave.html#M000015">object</a>’/:<a
|
425
|
-
href="Slave.html#M000015">object</a> keyword
|
426
|
-
</p>
|
427
|
-
<pre>
|
428
|
-
Slave.new :object => MyServer.new
|
429
|
-
</pre>
|
430
|
-
<p>
|
431
|
-
or, preferably, using the block form
|
432
|
-
</p>
|
433
|
-
<pre>
|
434
|
-
Slave.new{ MyServer.new }
|
435
|
-
</pre>
|
436
|
-
<p>
|
437
|
-
when the block form is used the <a href="Slave.html#M000015">object</a> is
|
438
|
-
contructed in the child process itself. this is quite advantageous if the
|
439
|
-
child <a href="Slave.html#M000015">object</a> consumes resources or opens
|
440
|
-
file handles (db connections, etc). by contructing the <a
|
441
|
-
href="Slave.html#M000015">object</a> in the child any resources are
|
442
|
-
consumed from the child‘s address space and things like open file
|
443
|
-
handles will not be carried into subsequent child processes (via standard
|
444
|
-
unix <a href="Slave.html#M000004">fork</a> semantics). in the event that a
|
445
|
-
block is specified but the <a href="Slave.html#M000015">object</a> cannot
|
446
|
-
be constructed and, instead, throws and Exception, that exception will be
|
447
|
-
propogated to the parent process.
|
448
|
-
</p>
|
449
|
-
<p>
|
450
|
-
opts may contain the following keys, as either strings or symbols
|
451
|
-
</p>
|
452
|
-
<pre>
|
453
|
-
object : specify the slave object. otherwise block value is used.
|
454
|
-
socket_creation_attempts : specify how many attempts to create a unix domain socket will be made
|
455
|
-
debug : turn on some logging to STDERR
|
456
|
-
psname : specify the name that will appear in 'top' ($0)
|
457
|
-
at_exit : specify a lambda to be called in the *parent* when the child dies
|
458
|
-
dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
|
459
|
-
threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
|
460
|
-
</pre>
|
461
|
-
<p><a class="source-toggle" href="#"
|
462
|
-
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
463
|
-
<div class="method-source-code" id="M000005-source">
|
464
|
-
<pre>
|
465
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 319</span>
|
466
|
-
319: <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>
|
467
|
-
320: <span class="ruby-comment cmt">#--{{{</span>
|
468
|
-
321: <span class="ruby-identifier">getopt</span> = <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
|
469
|
-
322:
|
470
|
-
323: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'object'</span>]
|
471
|
-
324: <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>)
|
472
|
-
325: <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>)
|
473
|
-
326: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'psname'</span>]
|
474
|
-
327: <span class="ruby-ivar">@at_exit</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'at_exit'</span>]
|
475
|
-
328: <span class="ruby-ivar">@dumped</span> = <span class="ruby-identifier">getopt</span>[<span class="ruby-value str">'dumped'</span>]
|
476
|
-
329: <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>)
|
477
|
-
330:
|
478
|
-
331: <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>
|
479
|
-
332: <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>
|
480
|
-
333:
|
481
|
-
334: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
|
482
|
-
335: <span class="ruby-ivar">@waiter</span> = <span class="ruby-ivar">@status</span> = <span class="ruby-keyword kw">nil</span>
|
483
|
-
336: <span class="ruby-ivar">@lifeline</span> = <span class="ruby-constant">LifeLine</span>.<span class="ruby-identifier">new</span>
|
484
|
-
337:
|
485
|
-
338: <span class="ruby-comment cmt"># weird syntax because dot/rdoc chokes on this!?!?</span>
|
486
|
-
339: <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>
|
487
|
-
340: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%Q[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
488
|
-
341: <span class="ruby-identifier">o</span> = <span class="ruby-constant">Object</span>.<span class="ruby-identifier">new</span>
|
489
|
-
342: <span class="ruby-keyword kw">class</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">o</span>
|
490
|
-
343: <span class="ruby-identifier">attr_accessor</span> <span class="ruby-value str">'__slave_object_failure__'</span>
|
491
|
-
344: <span class="ruby-keyword kw">end</span>
|
492
|
-
345: <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>]
|
493
|
-
346: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">o</span>
|
494
|
-
347: <span class="ruby-keyword kw">end</span>
|
495
|
-
348:
|
496
|
-
349: <span class="ruby-comment cmt">#</span>
|
497
|
-
350: <span class="ruby-comment cmt"># child</span>
|
498
|
-
351: <span class="ruby-comment cmt">#</span>
|
499
|
-
352: <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>))
|
500
|
-
353: <span class="ruby-identifier">e</span> = <span class="ruby-keyword kw">nil</span>
|
501
|
-
354: <span class="ruby-keyword kw">begin</span>
|
502
|
-
355: <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> }
|
503
|
-
356: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">catch</span>
|
504
|
-
357:
|
505
|
-
358: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@obj</span>
|
506
|
-
359: <span class="ruby-ivar">@object</span> = <span class="ruby-ivar">@obj</span>
|
507
|
-
360: <span class="ruby-keyword kw">else</span>
|
508
|
-
361: <span class="ruby-keyword kw">begin</span>
|
509
|
-
362: <span class="ruby-ivar">@object</span> = <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
|
510
|
-
363: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
511
|
-
364: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
|
512
|
-
365: <span class="ruby-keyword kw">end</span>
|
513
|
-
366: <span class="ruby-keyword kw">end</span>
|
514
|
-
367:
|
515
|
-
368: <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>
|
516
|
-
369: <span class="ruby-keyword kw">begin</span>
|
517
|
-
370: <span class="ruby-identifier">block</span>[<span class="ruby-ivar">@obj</span>]
|
518
|
-
371: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
519
|
-
372: <span class="ruby-identifier">init_failure</span>[<span class="ruby-identifier">e</span>]
|
520
|
-
373: <span class="ruby-keyword kw">end</span>
|
521
|
-
374: <span class="ruby-keyword kw">end</span>
|
522
|
-
375:
|
523
|
-
376: <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>))
|
524
|
-
377:
|
525
|
-
378: <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>)
|
526
|
-
379: <span class="ruby-ivar">@object</span>.<span class="ruby-identifier">extend</span> <span class="ruby-constant">DRbUndumped</span>
|
527
|
-
380: <span class="ruby-keyword kw">end</span>
|
528
|
-
381:
|
529
|
-
382: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@threadsafe</span>
|
530
|
-
383: <span class="ruby-ivar">@object</span> = <span class="ruby-constant">ThreadSafe</span>.<span class="ruby-identifier">new</span> <span class="ruby-ivar">@object</span>
|
531
|
-
384: <span class="ruby-keyword kw">end</span>
|
532
|
-
385:
|
533
|
-
386: <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>
|
534
|
-
387: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
|
535
|
-
388: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
|
536
|
-
389:
|
537
|
-
390: <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>)
|
538
|
-
391:
|
539
|
-
392: <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>
|
540
|
-
393: <span class="ruby-identifier">se</span> = <span class="ruby-keyword kw">nil</span>
|
541
|
-
394: <span class="ruby-keyword kw">begin</span>
|
542
|
-
395: <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>)
|
543
|
-
396: <span class="ruby-identifier">u</span> = <span class="ruby-node">"drbunix://#{ s }"</span>
|
544
|
-
397: <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>
|
545
|
-
398: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
|
546
|
-
399: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
|
547
|
-
400: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - socket <#{ @socket }>"</span> }
|
548
|
-
401: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - uri <#{ @uri }>"</span> }
|
549
|
-
402: <span class="ruby-keyword kw">break</span>
|
550
|
-
403: <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>
|
551
|
-
404: <span class="ruby-keyword kw">nil</span>
|
552
|
-
405: <span class="ruby-keyword kw">end</span>
|
553
|
-
406: <span class="ruby-keyword kw">end</span>
|
554
|
-
407:
|
555
|
-
408: <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>
|
556
|
-
409: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
|
557
|
-
410: <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>
|
558
|
-
411: <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>
|
559
|
-
412: <span class="ruby-identifier">exit</span>
|
560
|
-
413: <span class="ruby-keyword kw">end</span>
|
561
|
-
414:
|
562
|
-
415: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">puts</span> <span class="ruby-ivar">@socket</span>
|
563
|
-
416: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">cling</span>
|
564
|
-
417: <span class="ruby-keyword kw">else</span>
|
565
|
-
418: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">release</span>
|
566
|
-
419: <span class="ruby-identifier">warn</span> <span class="ruby-node">"slave(#{ $$ }) could not create socket!"</span>
|
567
|
-
420: <span class="ruby-identifier">exit</span>
|
568
|
-
421: <span class="ruby-keyword kw">end</span>
|
569
|
-
422: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
570
|
-
423: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%Q[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
571
|
-
424: <span class="ruby-keyword kw">ensure</span>
|
572
|
-
425: <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>
|
573
|
-
426: <span class="ruby-identifier">exit</span>(<span class="ruby-identifier">status</span>)
|
574
|
-
427: <span class="ruby-keyword kw">end</span>
|
575
|
-
428: <span class="ruby-comment cmt">#</span>
|
576
|
-
429: <span class="ruby-comment cmt"># parent </span>
|
577
|
-
430: <span class="ruby-comment cmt">#</span>
|
578
|
-
431: <span class="ruby-keyword kw">else</span>
|
579
|
-
432: <span class="ruby-identifier">detach</span>
|
580
|
-
433: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">throw</span>
|
581
|
-
434:
|
582
|
-
435: <span class="ruby-identifier">buf</span> = <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">gets</span>
|
583
|
-
436: <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>
|
584
|
-
437: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">buf</span>.<span class="ruby-identifier">strip</span>
|
585
|
-
438: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - socket <#{ @socket }>"</span> }
|
586
|
-
439:
|
587
|
-
440: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@at_exit</span>
|
588
|
-
441: <span class="ruby-ivar">@at_exit_thread</span> = <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">on_cut</span>{
|
589
|
-
442: <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>)
|
590
|
-
443: }
|
591
|
-
444: <span class="ruby-keyword kw">end</span>
|
592
|
-
445:
|
593
|
-
446: <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>
|
594
|
-
447: <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> }
|
595
|
-
448: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">"drbunix://#{ socket }"</span>
|
596
|
-
449: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - uri <#{ @uri }>"</span> }
|
597
|
-
450: <span class="ruby-comment cmt">#</span>
|
598
|
-
451: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
|
599
|
-
452: <span class="ruby-comment cmt">#</span>
|
600
|
-
453: <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>
|
601
|
-
454: <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>
|
602
|
-
455: <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>
|
603
|
-
456: <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>
|
604
|
-
457: (<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>
|
605
|
-
458: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%Q[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
606
|
-
459: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
|
607
|
-
460: <span class="ruby-keyword kw">end</span>
|
608
|
-
461: <span class="ruby-ivar">@psname</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@object</span>)
|
609
|
-
462: <span class="ruby-keyword kw">else</span>
|
610
|
-
463: <span class="ruby-identifier">raise</span> <span class="ruby-node">"failed to find slave socket <#{ @socket }>"</span>
|
611
|
-
464: <span class="ruby-keyword kw">end</span>
|
612
|
-
465: <span class="ruby-keyword kw">end</span>
|
613
|
-
466: <span class="ruby-comment cmt">#--}}}</span>
|
614
|
-
467: <span class="ruby-keyword kw">end</span>
|
615
|
-
</pre>
|
616
|
-
</div>
|
617
|
-
</div>
|
618
|
-
</div>
|
619
|
-
|
620
|
-
<div id="method-M000015" class="method-detail">
|
621
|
-
<a name="M000015"></a>
|
622
|
-
|
623
|
-
<div class="method-heading">
|
624
|
-
<a href="#M000015" class="method-signature">
|
625
|
-
<span class="method-name">object</span><span class="method-args">(opts = {})</span>
|
626
|
-
</a>
|
627
|
-
</div>
|
628
|
-
|
629
|
-
<div class="method-description">
|
630
|
-
<p>
|
631
|
-
a simple convenience method which returns an <b><a
|
632
|
-
href="Slave.html#M000015">object</a></b> from another process. the <a
|
633
|
-
href="Slave.html#M000015">object</a> returned is the result of the supplied
|
634
|
-
block. eg
|
635
|
-
</p>
|
636
|
-
<pre>
|
637
|
-
object = Slave.object{ processor_intensive_object_built_in_child_process() }
|
638
|
-
</pre>
|
639
|
-
<p>
|
640
|
-
eg.
|
641
|
-
</p>
|
642
|
-
<p>
|
643
|
-
the call can be made asynchronous via the ‘async’/:async
|
644
|
-
keyword
|
645
|
-
</p>
|
646
|
-
<pre>
|
647
|
-
thread = Slave.object(:async=>true){ long_processor_intensive_object_built_in_child_process() }
|
648
|
-
|
649
|
-
# go on about your coding business then, later
|
650
|
-
|
651
|
-
object = thread.value
|
652
|
-
</pre>
|
653
|
-
<p><a class="source-toggle" href="#"
|
654
|
-
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
655
|
-
<div class="method-source-code" id="M000015-source">
|
656
|
-
<pre>
|
657
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 587</span>
|
658
|
-
587: <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>
|
659
|
-
588: <span class="ruby-comment cmt">#--{{{</span>
|
660
|
-
589: <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>)
|
661
|
-
590:
|
662
|
-
591: <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>)
|
663
|
-
592: <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>
|
664
|
-
593:
|
665
|
-
594: <span class="ruby-identifier">slave</span> = <span class="ruby-constant">Slave</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">opts</span>
|
666
|
-
595:
|
667
|
-
596: <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>
|
668
|
-
597: <span class="ruby-keyword kw">begin</span>
|
669
|
-
598: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span>
|
670
|
-
599: <span class="ruby-keyword kw">ensure</span>
|
671
|
-
600: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">shutdown</span>
|
672
|
-
601: <span class="ruby-keyword kw">end</span>
|
673
|
-
602: <span class="ruby-keyword kw">end</span>
|
674
|
-
603:
|
675
|
-
604: <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>]
|
676
|
-
605: <span class="ruby-comment cmt">#--}}}</span>
|
677
|
-
606: <span class="ruby-keyword kw">end</span>
|
678
|
-
</pre>
|
679
|
-
</div>
|
680
|
-
</div>
|
681
|
-
</div>
|
682
|
-
|
683
|
-
<div id="method-M000001" class="method-detail">
|
684
|
-
<a name="M000001"></a>
|
685
|
-
|
686
|
-
<div class="method-heading">
|
687
|
-
<a href="#M000001" class="method-signature">
|
688
|
-
<span class="method-name">version</span><span class="method-args">()</span>
|
689
|
-
</a>
|
690
|
-
</div>
|
691
|
-
|
692
|
-
<div class="method-description">
|
693
|
-
<p><a class="source-toggle" href="#"
|
694
|
-
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
695
|
-
<div class="method-source-code" id="M000001-source">
|
696
|
-
<pre>
|
697
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 44</span>
|
698
|
-
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>
|
699
|
-
</pre>
|
700
|
-
</div>
|
701
|
-
</div>
|
702
|
-
</div>
|
703
|
-
|
704
|
-
<h3 class="section-bar">Public Instance methods</h3>
|
705
|
-
|
706
|
-
<div id="method-M000012" class="method-detail">
|
707
|
-
<a name="M000012"></a>
|
708
|
-
|
709
|
-
<div class="method-heading">
|
710
|
-
<a href="#M000012" class="method-signature">
|
711
|
-
<span class="method-name">default</span><span class="method-args">(key)</span>
|
712
|
-
</a>
|
713
|
-
</div>
|
714
|
-
|
715
|
-
<div class="method-description">
|
716
|
-
<p>
|
717
|
-
see docs for <a href="Slave.html#M000002">Slave.default</a>
|
718
|
-
</p>
|
719
|
-
<p><a class="source-toggle" href="#"
|
720
|
-
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
721
|
-
<div class="method-source-code" id="M000012-source">
|
722
|
-
<pre>
|
723
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 546</span>
|
724
|
-
546: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
|
725
|
-
547: <span class="ruby-comment cmt">#--{{{</span>
|
726
|
-
548: <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>
|
727
|
-
549: <span class="ruby-comment cmt">#--}}}</span>
|
728
|
-
550: <span class="ruby-keyword kw">end</span>
|
729
|
-
</pre>
|
730
|
-
</div>
|
731
|
-
</div>
|
732
|
-
</div>
|
733
|
-
|
734
|
-
<div id="method-M000006" class="method-detail">
|
735
|
-
<a name="M000006"></a>
|
736
|
-
|
737
|
-
<div class="method-heading">
|
738
|
-
<a href="#M000006" class="method-signature">
|
739
|
-
<span class="method-name">detach</span><span class="method-args">()</span>
|
740
|
-
</a>
|
741
|
-
</div>
|
742
|
-
|
743
|
-
<div class="method-description">
|
744
|
-
<p>
|
745
|
-
starts a thread to collect the child status and sets up at_exit handler to
|
746
|
-
prevent zombies. the at_exit handler is canceled if the thread is able to
|
747
|
-
collect the status
|
748
|
-
</p>
|
749
|
-
<p><a class="source-toggle" href="#"
|
750
|
-
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
751
|
-
<div class="method-source-code" id="M000006-source">
|
752
|
-
<pre>
|
753
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 473</span>
|
754
|
-
473: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">detach</span>
|
755
|
-
474: <span class="ruby-comment cmt">#--{{{</span>
|
756
|
-
475: <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>
|
757
|
-
476: <span class="ruby-keyword kw">begin</span>
|
758
|
-
477: <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>
|
759
|
-
478: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
760
|
-
479: <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>)
|
761
|
-
480: <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>
|
762
|
-
481: <span class="ruby-keyword kw">end</span>
|
763
|
-
482: <span class="ruby-keyword kw">end</span>
|
764
|
-
483:
|
765
|
-
484: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">at_exit</span> <span class="ruby-keyword kw">do</span>
|
766
|
-
485: <span class="ruby-identifier">shutdown</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
767
|
-
486: <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>
|
768
|
-
487: <span class="ruby-keyword kw">end</span>
|
769
|
-
488:
|
770
|
-
489: <span class="ruby-ivar">@waiter</span> =
|
771
|
-
490: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
|
772
|
-
491: <span class="ruby-keyword kw">begin</span>
|
773
|
-
492: <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>
|
774
|
-
493: <span class="ruby-keyword kw">ensure</span>
|
775
|
-
494: <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> }
|
776
|
-
495: <span class="ruby-keyword kw">end</span>
|
777
|
-
496: <span class="ruby-keyword kw">end</span>
|
778
|
-
497: <span class="ruby-comment cmt">#--}}}</span>
|
779
|
-
498: <span class="ruby-keyword kw">end</span>
|
780
|
-
</pre>
|
781
|
-
</div>
|
782
|
-
</div>
|
783
|
-
</div>
|
784
|
-
|
785
|
-
<div id="method-M000011" class="method-detail">
|
786
|
-
<a name="M000011"></a>
|
787
|
-
|
788
|
-
<div class="method-heading">
|
789
|
-
<a href="#M000011" class="method-signature">
|
790
|
-
<span class="method-name">gen_psname</span><span class="method-args">(obj)</span>
|
791
|
-
</a>
|
792
|
-
</div>
|
793
|
-
|
794
|
-
<div class="method-description">
|
795
|
-
<p>
|
796
|
-
generate a <a href="Slave.html#M000002">default</a> name to appear in
|
797
|
-
ps/top
|
798
|
-
</p>
|
799
|
-
<p><a class="source-toggle" href="#"
|
800
|
-
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
801
|
-
<div class="method-source-code" id="M000011-source">
|
802
|
-
<pre>
|
803
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 538</span>
|
804
|
-
538: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
|
805
|
-
539: <span class="ruby-comment cmt">#--{{{</span>
|
806
|
-
540: <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">%r/\s+/</span>,<span class="ruby-value str">'_'</span>)
|
807
|
-
541: <span class="ruby-comment cmt">#--}}}</span>
|
808
|
-
542: <span class="ruby-keyword kw">end</span>
|
809
|
-
</pre>
|
810
|
-
</div>
|
811
|
-
</div>
|
812
|
-
</div>
|
813
|
-
|
814
|
-
<div id="method-M000013" class="method-detail">
|
815
|
-
<a name="M000013"></a>
|
816
|
-
|
817
|
-
<div class="method-heading">
|
818
|
-
<a href="#M000013" class="method-signature">
|
819
|
-
<span class="method-name">getopts</span><span class="method-args">(opts)</span>
|
820
|
-
</a>
|
821
|
-
</div>
|
822
|
-
|
823
|
-
<div class="method-description">
|
824
|
-
<p>
|
825
|
-
see docs for <a href="Slave.html#M000003">Slave.getopts</a>
|
826
|
-
</p>
|
827
|
-
<p><a class="source-toggle" href="#"
|
828
|
-
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
829
|
-
<div class="method-source-code" id="M000013-source">
|
830
|
-
<pre>
|
831
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 554</span>
|
832
|
-
554: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
|
833
|
-
555: <span class="ruby-comment cmt">#--{{{</span>
|
834
|
-
556: <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>
|
835
|
-
557: <span class="ruby-comment cmt">#--}}}</span>
|
836
|
-
558: <span class="ruby-keyword kw">end</span>
|
837
|
-
</pre>
|
838
|
-
</div>
|
839
|
-
</div>
|
840
|
-
</div>
|
841
|
-
|
842
|
-
<div id="method-M000009" class="method-detail">
|
843
|
-
<a name="M000009"></a>
|
844
|
-
|
845
|
-
<div class="method-heading">
|
846
|
-
<a href="#M000009" class="method-signature">
|
847
|
-
<span class="method-name">shutdown</span><span class="method-args">(opts = {})</span>
|
848
|
-
</a>
|
849
|
-
</div>
|
850
|
-
|
851
|
-
<div class="method-description">
|
852
|
-
<p>
|
853
|
-
cuts the lifeline and kills the child process - give the key
|
854
|
-
‘quiet’ to ignore errors shutting down, including having
|
855
|
-
already <a href="Slave.html#M000009">shutdown</a>
|
856
|
-
</p>
|
857
|
-
<p><a class="source-toggle" href="#"
|
858
|
-
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
859
|
-
<div class="method-source-code" id="M000009-source">
|
860
|
-
<pre>
|
861
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 517</span>
|
862
|
-
517: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span> <span class="ruby-identifier">opts</span> = {}
|
863
|
-
518: <span class="ruby-comment cmt">#--{{{</span>
|
864
|
-
519: <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>]
|
865
|
-
520: <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>
|
866
|
-
521: <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>
|
867
|
-
522: <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>
|
868
|
-
523: <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>
|
869
|
-
524: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
|
870
|
-
525: <span class="ruby-comment cmt">#--}}}</span>
|
871
|
-
526: <span class="ruby-keyword kw">end</span>
|
872
|
-
</pre>
|
873
|
-
</div>
|
874
|
-
</div>
|
875
|
-
</div>
|
876
|
-
|
877
|
-
<div id="method-M000010" class="method-detail">
|
878
|
-
<a name="M000010"></a>
|
879
|
-
|
880
|
-
<div class="method-heading">
|
881
|
-
<a href="#M000010" class="method-signature">
|
882
|
-
<span class="method-name">shutdown?</span><span class="method-args">()</span>
|
883
|
-
</a>
|
884
|
-
</div>
|
885
|
-
|
886
|
-
<div class="method-description">
|
887
|
-
<p>
|
888
|
-
true
|
889
|
-
</p>
|
890
|
-
<p><a class="source-toggle" href="#"
|
891
|
-
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
892
|
-
<div class="method-source-code" id="M000010-source">
|
893
|
-
<pre>
|
894
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 530</span>
|
895
|
-
530: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown?</span>
|
896
|
-
531: <span class="ruby-comment cmt">#--{{{</span>
|
897
|
-
532: <span class="ruby-ivar">@shutdown</span>
|
898
|
-
533: <span class="ruby-comment cmt">#--}}}</span>
|
899
|
-
534: <span class="ruby-keyword kw">end</span>
|
900
|
-
</pre>
|
901
|
-
</div>
|
902
|
-
</div>
|
903
|
-
</div>
|
904
|
-
|
905
|
-
<div id="method-M000014" class="method-detail">
|
906
|
-
<a name="M000014"></a>
|
907
|
-
|
908
|
-
<div class="method-heading">
|
909
|
-
<a href="#M000014" class="method-signature">
|
910
|
-
<span class="method-name">trace</span><span class="method-args">() {|| ...}</span>
|
911
|
-
</a>
|
912
|
-
</div>
|
913
|
-
|
914
|
-
<div class="method-description">
|
915
|
-
<p>
|
916
|
-
debugging output - ENV[‘SLAVE_DEBUG’]=1 to enable
|
917
|
-
</p>
|
918
|
-
<p><a class="source-toggle" href="#"
|
919
|
-
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
920
|
-
<div class="method-source-code" id="M000014-source">
|
921
|
-
<pre>
|
922
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 562</span>
|
923
|
-
562: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
|
924
|
-
563: <span class="ruby-comment cmt">#--{{{</span>
|
925
|
-
564: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span>
|
926
|
-
565: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span> <span class="ruby-keyword kw">yield</span>
|
927
|
-
566: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">flush</span>
|
928
|
-
567: <span class="ruby-keyword kw">end</span>
|
929
|
-
568: <span class="ruby-comment cmt">#--}}}</span>
|
930
|
-
569: <span class="ruby-keyword kw">end</span>
|
931
|
-
</pre>
|
932
|
-
</div>
|
933
|
-
</div>
|
934
|
-
</div>
|
935
|
-
|
936
|
-
<div id="method-M000007" class="method-detail">
|
937
|
-
<a name="M000007"></a>
|
938
|
-
|
939
|
-
<div class="method-heading">
|
940
|
-
<a href="#M000007" class="method-signature">
|
941
|
-
<span class="method-name">wait</span><span class="method-args">(opts = {})</span>
|
942
|
-
</a>
|
943
|
-
</div>
|
944
|
-
|
945
|
-
<div class="method-description">
|
946
|
-
<p>
|
947
|
-
<a href="Slave.html#M000007">wait</a> for slave to finish. if the keyword
|
948
|
-
‘non_block’=>true is given a thread is returned to do the
|
949
|
-
waiting in an async fashion. eg
|
950
|
-
</p>
|
951
|
-
<pre>
|
952
|
-
thread = slave.wait(:non_block=>true){|value| "background <#{ value }>"}
|
953
|
-
</pre>
|
954
|
-
<p><a class="source-toggle" href="#"
|
955
|
-
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
956
|
-
<div class="method-source-code" id="M000007-source">
|
957
|
-
<pre>
|
958
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 505</span>
|
959
|
-
505: <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>
|
960
|
-
506: <span class="ruby-comment cmt">#--{{{</span>
|
961
|
-
507: <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>}
|
962
|
-
508: <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>]
|
963
|
-
509: <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> ]
|
964
|
-
510: <span class="ruby-comment cmt">#--}}}</span>
|
965
|
-
511: <span class="ruby-keyword kw">end</span>
|
966
|
-
</pre>
|
967
|
-
</div>
|
968
|
-
</div>
|
969
|
-
</div>
|
970
|
-
|
971
|
-
<div id="method-M000008" class="method-detail">
|
972
|
-
<a name="M000008"></a>
|
973
|
-
|
974
|
-
<div class="method-heading">
|
975
|
-
<span class="method-name">wait2</span><span class="method-args">(opts = {})</span>
|
976
|
-
</div>
|
977
|
-
|
978
|
-
<div class="method-description">
|
979
|
-
<p>
|
980
|
-
Alias for <a href="Slave.html#M000007">wait</a>
|
981
|
-
</p>
|
982
|
-
</div>
|
983
|
-
</div>
|
984
|
-
|
985
|
-
|
986
|
-
</div>
|
987
|
-
|
988
|
-
|
989
|
-
</div>
|
990
|
-
|
991
|
-
|
992
|
-
<div id="validator-badges">
|
993
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
994
|
-
</div>
|
995
|
-
|
996
|
-
</body>
|
997
|
-
</html>
|