slave 0.0.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 +42 -0
- data/VERSION +1 -0
- data/doc/classes/Slave.html +541 -0
- data/doc/classes/Slave/Heartbeat.html +342 -0
- data/doc/created.rid +1 -0
- data/doc/dot/f_0.dot +14 -0
- data/doc/dot/f_0.jpg +0 -0
- data/doc/dot/f_1.dot +14 -0
- data/doc/dot/f_1.jpg +0 -0
- data/doc/dot/f_2.dot +29 -0
- data/doc/dot/f_2.jpg +0 -0
- data/doc/files/README.html +169 -0
- data/doc/files/VERSION.html +107 -0
- data/doc/files/lib/slave_rb.html +119 -0
- data/doc/fr_class_index.html +28 -0
- data/doc/fr_file_index.html +29 -0
- data/doc/fr_method_index.html +39 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +172 -0
- data/gemspec.rb +23 -0
- data/install.rb +201 -0
- data/lib/slave-0.0.0.rb +292 -0
- data/lib/slave.rb +292 -0
- data/rdoc.cmd +1 -0
- data/sample/a.rb +102 -0
- data/slave-0.0.0.gem +0 -0
- metadata +72 -0
data/README
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
the Slave class forks a process and starts a drb server in the child using any
|
2
|
+
object as the server. the process is detached so it is not required (nor
|
3
|
+
possible) to wait on the child pid. a Heartbeat is set up between the parent
|
4
|
+
and child processes so that the child will exit of the parent exits for any
|
5
|
+
reason - preventing orphaned slaves from running indefinitely. the purpose of
|
6
|
+
Slaves is to be able to easily set up a collection of objects communicating
|
7
|
+
via drb protocols instead of having to use IPC.
|
8
|
+
|
9
|
+
typical usage:
|
10
|
+
|
11
|
+
obj = AnyClass::new
|
12
|
+
|
13
|
+
slave = Slave::new obj
|
14
|
+
|
15
|
+
p slave.object # handle on drb object
|
16
|
+
p slave.uri # uri of the drb object
|
17
|
+
p slave.socket # unix domain socket path for drb object
|
18
|
+
p slave.psname # title shown in ps/top
|
19
|
+
|
20
|
+
other usage:
|
21
|
+
|
22
|
+
set the pulse_rate used for the Heartbeat
|
23
|
+
|
24
|
+
slave = Slave::new MyClass::new, 'pulse_rate' => 10
|
25
|
+
|
26
|
+
same
|
27
|
+
|
28
|
+
Slave::pulse_rate = 10
|
29
|
+
slave = Slave::new MyClass::new
|
30
|
+
|
31
|
+
same
|
32
|
+
|
33
|
+
ENV['SLAVE_PULSE_RATE'] = 10
|
34
|
+
slave = Slave::new MyClass::new
|
35
|
+
|
36
|
+
slaves may be configured via the environment, the Slave class, or via the ctor
|
37
|
+
for object itself. attributes which may be configured include
|
38
|
+
|
39
|
+
* socket_creation_attempts
|
40
|
+
* pulse_rate
|
41
|
+
* psname
|
42
|
+
* debug
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,541 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: 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
|
+
<h1>Slave <sup class="type-note">(Class)</sup></h1>
|
51
|
+
<table class="header-table">
|
52
|
+
<tr class="top-aligned-row">
|
53
|
+
<td><strong>In:</strong></td>
|
54
|
+
<td>
|
55
|
+
<a href="../files/lib/slave_rb.html">
|
56
|
+
lib/slave.rb
|
57
|
+
</a>
|
58
|
+
<br />
|
59
|
+
</td>
|
60
|
+
</tr>
|
61
|
+
|
62
|
+
<tr class="top-aligned-row">
|
63
|
+
<td><strong>Parent:</strong></td>
|
64
|
+
<td>
|
65
|
+
Object
|
66
|
+
</td>
|
67
|
+
</tr>
|
68
|
+
</table>
|
69
|
+
</div>
|
70
|
+
<!-- banner header -->
|
71
|
+
|
72
|
+
<div id="bodyContent">
|
73
|
+
|
74
|
+
|
75
|
+
<div id="contextContent">
|
76
|
+
<div id="diagram">
|
77
|
+
<map name="map">
|
78
|
+
<area shape="RECT" coords="28,88,99,40" href="Slave.html" alt="Slave">
|
79
|
+
</map>
|
80
|
+
<img src="../dot/f_2.jpg" usemap="#map" border=0 alt="TopLevel">
|
81
|
+
</div>
|
82
|
+
|
83
|
+
<div id="description">
|
84
|
+
<p>
|
85
|
+
the <a href="Slave.html">Slave</a> class encapsulates the work of setting
|
86
|
+
up a drb server in another process.
|
87
|
+
</p>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
<div id="method-list">
|
93
|
+
<h2 class="section-bar">Methods</h2>
|
94
|
+
|
95
|
+
<div class="name-list">
|
96
|
+
<a href="#M000002">fork</a>
|
97
|
+
<a href="#M000005">gen_psname</a>
|
98
|
+
<a href="#M000006">getval</a>
|
99
|
+
<a href="#M000001">getval</a>
|
100
|
+
<a href="#M000003">new</a>
|
101
|
+
<a href="#M000004">shutdown</a>
|
102
|
+
<a href="#M000007">trace</a>
|
103
|
+
</div>
|
104
|
+
</div>
|
105
|
+
|
106
|
+
<div id="constants-list">
|
107
|
+
<h2 class="section-bar">Constants</h2>
|
108
|
+
|
109
|
+
<div class="name-list">
|
110
|
+
<table summary="Constants">
|
111
|
+
<tr class="top-aligned-row context-row">
|
112
|
+
<td class="context-item-name">DEFAULT_SOCKET_CREATION_ATTEMPTS</td>
|
113
|
+
<td>=</td>
|
114
|
+
<td class="context-item-value">Integer(ENV['SLAVE_SOCKET_CREATION_ATTEMPTS'] || 42)</td>
|
115
|
+
</tr>
|
116
|
+
<tr class="top-aligned-row context-row">
|
117
|
+
<td class="context-item-name">DEFAULT_PULSE_RATE</td>
|
118
|
+
<td>=</td>
|
119
|
+
<td class="context-item-value">Float(ENV['SLAVE_PULSE_RATE'] || 8)</td>
|
120
|
+
</tr>
|
121
|
+
<tr class="top-aligned-row context-row">
|
122
|
+
<td class="context-item-name">DEFAULT_DEBUG</td>
|
123
|
+
<td>=</td>
|
124
|
+
<td class="context-item-value">(ENV['SLAVE_DEBUG'] ? true : false)</td>
|
125
|
+
</tr>
|
126
|
+
</table>
|
127
|
+
</div>
|
128
|
+
</div>
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
<div id="attribute-list">
|
133
|
+
<h2 class="section-bar">Attributes</h2>
|
134
|
+
|
135
|
+
<div class="name-list">
|
136
|
+
<table>
|
137
|
+
<tr class="top-aligned-row context-row">
|
138
|
+
<td class="context-item-name">debug</td>
|
139
|
+
<td class="context-item-value"> [R] </td>
|
140
|
+
<td class="context-item-desc"></td>
|
141
|
+
</tr>
|
142
|
+
<tr class="top-aligned-row context-row">
|
143
|
+
<td class="context-item-name">debug</td>
|
144
|
+
<td class="context-item-value"> [RW] </td>
|
145
|
+
<td class="context-item-desc">
|
146
|
+
if this is true and you are running from a terminal information is printed
|
147
|
+
on STDERR
|
148
|
+
|
149
|
+
</td>
|
150
|
+
</tr>
|
151
|
+
<tr class="top-aligned-row context-row">
|
152
|
+
<td class="context-item-name">obj</td>
|
153
|
+
<td class="context-item-value"> [R] </td>
|
154
|
+
<td class="context-item-desc"></td>
|
155
|
+
</tr>
|
156
|
+
<tr class="top-aligned-row context-row">
|
157
|
+
<td class="context-item-name">object</td>
|
158
|
+
<td class="context-item-value"> [R] </td>
|
159
|
+
<td class="context-item-desc"></td>
|
160
|
+
</tr>
|
161
|
+
<tr class="top-aligned-row context-row">
|
162
|
+
<td class="context-item-name">pid</td>
|
163
|
+
<td class="context-item-value"> [R] </td>
|
164
|
+
<td class="context-item-desc"></td>
|
165
|
+
</tr>
|
166
|
+
<tr class="top-aligned-row context-row">
|
167
|
+
<td class="context-item-name">ppid</td>
|
168
|
+
<td class="context-item-value"> [R] </td>
|
169
|
+
<td class="context-item-desc"></td>
|
170
|
+
</tr>
|
171
|
+
<tr class="top-aligned-row context-row">
|
172
|
+
<td class="context-item-name">psname</td>
|
173
|
+
<td class="context-item-value"> [R] </td>
|
174
|
+
<td class="context-item-desc"></td>
|
175
|
+
</tr>
|
176
|
+
<tr class="top-aligned-row context-row">
|
177
|
+
<td class="context-item-name">pulse_rate</td>
|
178
|
+
<td class="context-item-value"> [RW] </td>
|
179
|
+
<td class="context-item-desc">
|
180
|
+
defined the rate of pinging in the <a
|
181
|
+
href="Slave/Heartbeat.html">Heartbeat</a> object
|
182
|
+
|
183
|
+
</td>
|
184
|
+
</tr>
|
185
|
+
<tr class="top-aligned-row context-row">
|
186
|
+
<td class="context-item-name">pulse_rate</td>
|
187
|
+
<td class="context-item-value"> [R] </td>
|
188
|
+
<td class="context-item-desc"></td>
|
189
|
+
</tr>
|
190
|
+
<tr class="top-aligned-row context-row">
|
191
|
+
<td class="context-item-name">socket</td>
|
192
|
+
<td class="context-item-value"> [R] </td>
|
193
|
+
<td class="context-item-desc"></td>
|
194
|
+
</tr>
|
195
|
+
<tr class="top-aligned-row context-row">
|
196
|
+
<td class="context-item-name">socket_creation_attempts</td>
|
197
|
+
<td class="context-item-value"> [RW] </td>
|
198
|
+
<td class="context-item-desc"></td>
|
199
|
+
</tr>
|
200
|
+
<tr class="top-aligned-row context-row">
|
201
|
+
<td class="context-item-name">uri</td>
|
202
|
+
<td class="context-item-value"> [R] </td>
|
203
|
+
<td class="context-item-desc"></td>
|
204
|
+
</tr>
|
205
|
+
</table>
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
|
209
|
+
<div id="class-list">
|
210
|
+
<h2 class="section-bar">Classes and Modules</h2>
|
211
|
+
|
212
|
+
Class <a href="Slave/Heartbeat.html" class="link">Slave::Heartbeat</a><br />
|
213
|
+
|
214
|
+
</div>
|
215
|
+
|
216
|
+
</div>
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
<!-- if includes -->
|
221
|
+
|
222
|
+
|
223
|
+
<!-- if method_list -->
|
224
|
+
<div id="methods">
|
225
|
+
<h2 class="section-bar">Public Class methods</h2>
|
226
|
+
|
227
|
+
<div id="method-M000002" class="method-detail">
|
228
|
+
<a name="M000002"></a>
|
229
|
+
|
230
|
+
<div class="method-heading">
|
231
|
+
<a href="#M000002" class="method-signature">
|
232
|
+
<span class="method-name">fork</span><span class="method-args">(&block)</span>
|
233
|
+
</a>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
<div class="method-description">
|
237
|
+
<p>
|
238
|
+
just fork with out silly warnings
|
239
|
+
</p>
|
240
|
+
<p><a class="source-toggle" href="#"
|
241
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
242
|
+
<div class="method-source-code" id="M000002-source">
|
243
|
+
<pre>
|
244
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 47</span>
|
245
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fork</span> <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>
|
246
|
+
48: <span class="ruby-comment cmt">#--{{{</span>
|
247
|
+
49: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
|
248
|
+
50: <span class="ruby-keyword kw">begin</span>
|
249
|
+
51: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-keyword kw">nil</span>
|
250
|
+
52: <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>
|
251
|
+
53: <span class="ruby-keyword kw">ensure</span>
|
252
|
+
54: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
|
253
|
+
55: <span class="ruby-keyword kw">end</span>
|
254
|
+
56: <span class="ruby-comment cmt">#--}}}</span>
|
255
|
+
57: <span class="ruby-keyword kw">end</span>
|
256
|
+
</pre>
|
257
|
+
</div>
|
258
|
+
</div>
|
259
|
+
</div>
|
260
|
+
|
261
|
+
<div id="method-M000001" class="method-detail">
|
262
|
+
<a name="M000001"></a>
|
263
|
+
|
264
|
+
<div class="method-heading">
|
265
|
+
<a href="#M000001" class="method-signature">
|
266
|
+
<span class="method-name">getval</span><span class="method-args">key, opts = {}</span>
|
267
|
+
</a>
|
268
|
+
</div>
|
269
|
+
|
270
|
+
<div class="method-description">
|
271
|
+
<p>
|
272
|
+
look up a value in an option hash failing back to class defaults
|
273
|
+
</p>
|
274
|
+
<p><a class="source-toggle" href="#"
|
275
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
276
|
+
<div class="method-source-code" id="M000001-source">
|
277
|
+
<pre>
|
278
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 39</span>
|
279
|
+
39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getval</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">opts</span> = {}
|
280
|
+
40: <span class="ruby-comment cmt">#--{{{</span>
|
281
|
+
41: <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>]
|
282
|
+
42: <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">k</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">k</span>)}
|
283
|
+
43: <span class="ruby-identifier">send</span> <span class="ruby-identifier">key</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
284
|
+
44: <span class="ruby-comment cmt">#--}}}</span>
|
285
|
+
45: <span class="ruby-keyword kw">end</span>
|
286
|
+
</pre>
|
287
|
+
</div>
|
288
|
+
</div>
|
289
|
+
</div>
|
290
|
+
|
291
|
+
<div id="method-M000003" class="method-detail">
|
292
|
+
<a name="M000003"></a>
|
293
|
+
|
294
|
+
<div class="method-heading">
|
295
|
+
<a href="#M000003" class="method-signature">
|
296
|
+
<span class="method-name">new</span><span class="method-args">obj, opts = {}</span>
|
297
|
+
</a>
|
298
|
+
</div>
|
299
|
+
|
300
|
+
<div class="method-description">
|
301
|
+
<p>
|
302
|
+
‘obj’ can be any object and ‘opts’ may contain the
|
303
|
+
keys ‘socket_creation_attempts’, ‘pulse_rate’,
|
304
|
+
‘psname’, or ‘debug’
|
305
|
+
</p>
|
306
|
+
<p><a class="source-toggle" href="#"
|
307
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
308
|
+
<div class="method-source-code" id="M000003-source">
|
309
|
+
<pre>
|
310
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 73</span>
|
311
|
+
73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">obj</span>, <span class="ruby-identifier">opts</span> = {}
|
312
|
+
74: <span class="ruby-comment cmt">#--{{{</span>
|
313
|
+
75: <span class="ruby-ivar">@obj</span> = <span class="ruby-identifier">obj</span>
|
314
|
+
76:
|
315
|
+
77: <span class="ruby-ivar">@socket_creation_attempts</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'socket_creation_attempts'</span>, <span class="ruby-identifier">opts</span>)
|
316
|
+
78: <span class="ruby-ivar">@pulse_rate</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'pulse_rate'</span>, <span class="ruby-identifier">opts</span>)
|
317
|
+
79: <span class="ruby-ivar">@debug</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'debug'</span>, <span class="ruby-identifier">opts</span>)
|
318
|
+
80: <span class="ruby-ivar">@psname</span> = <span class="ruby-identifier">getval</span>(<span class="ruby-value str">'psname'</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">gen_psname</span>(<span class="ruby-ivar">@obj</span>)
|
319
|
+
81:
|
320
|
+
82: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"socket_creation_attempts <#{ @socket_creation_attempts }>"</span> }
|
321
|
+
83: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"pulse_rate <#{ @pulse_rate }>"</span> }
|
322
|
+
84: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"psname <#{ @psname }>"</span> }
|
323
|
+
85:
|
324
|
+
86: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">false</span>
|
325
|
+
87:
|
326
|
+
88: <span class="ruby-ivar">@heartbeat</span> = <span class="ruby-constant">Heartbeat</span><span class="ruby-operator">::</span><span class="ruby-identifier">new</span> <span class="ruby-ivar">@pulse_rate</span>, <span class="ruby-ivar">@debug</span>
|
327
|
+
89: <span class="ruby-ivar">@r</span>, <span class="ruby-ivar">@w</span> = <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-identifier">pipe</span>
|
328
|
+
90: <span class="ruby-comment cmt">#</span>
|
329
|
+
91: <span class="ruby-comment cmt"># child</span>
|
330
|
+
92: <span class="ruby-comment cmt">#</span>
|
331
|
+
93: <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>))
|
332
|
+
94: <span class="ruby-keyword kw">begin</span>
|
333
|
+
95: <span class="ruby-identifier">$0</span> = <span class="ruby-ivar">@psname</span>
|
334
|
+
96: <span class="ruby-ivar">@pid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">pid</span>
|
335
|
+
97: <span class="ruby-ivar">@ppid</span> = <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">ppid</span>
|
336
|
+
98:
|
337
|
+
99: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
|
338
|
+
100: <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword kw">nil</span>
|
339
|
+
101: <span class="ruby-ivar">@uri</span> = <span class="ruby-keyword kw">nil</span>
|
340
|
+
102:
|
341
|
+
103: <span class="ruby-identifier">tmpdir</span> = <span class="ruby-constant">Dir</span><span class="ruby-operator">::</span><span class="ruby-identifier">tmpdir</span>
|
342
|
+
104: <span class="ruby-identifier">basename</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">basename</span> <span class="ruby-ivar">@psname</span>
|
343
|
+
105:
|
344
|
+
106: <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>
|
345
|
+
107: <span class="ruby-keyword kw">begin</span>
|
346
|
+
108: <span class="ruby-identifier">s</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">join</span>(<span class="ruby-identifier">tmpdir</span>, <span class="ruby-node">"#{ basename }_#{ attempt }"</span>)
|
347
|
+
109: <span class="ruby-identifier">u</span> = <span class="ruby-node">"drbunix://#{ s }"</span>
|
348
|
+
110: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">start_service</span> <span class="ruby-identifier">u</span>, <span class="ruby-identifier">obj</span>
|
349
|
+
111: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">s</span>
|
350
|
+
112: <span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">u</span>
|
351
|
+
113: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - socket <#{ @socket }>"</span> }
|
352
|
+
114: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"child - uri <#{ @uri }>"</span> }
|
353
|
+
115: <span class="ruby-keyword kw">break</span>
|
354
|
+
116: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EADDRINUSE</span>
|
355
|
+
117: <span class="ruby-keyword kw">nil</span>
|
356
|
+
118: <span class="ruby-keyword kw">end</span>
|
357
|
+
119: <span class="ruby-keyword kw">end</span>
|
358
|
+
120:
|
359
|
+
121: <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>
|
360
|
+
122: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
|
361
|
+
123: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">write</span> <span class="ruby-ivar">@socket</span>
|
362
|
+
124: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
|
363
|
+
125: <span class="ruby-identifier">trap</span>(<span class="ruby-value str">'SIGUSR2'</span>) <span class="ruby-keyword kw">do</span>
|
364
|
+
126: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
365
|
+
127: <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>
|
366
|
+
128: <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>
|
367
|
+
129: <span class="ruby-identifier">exit!</span>
|
368
|
+
130: <span class="ruby-keyword kw">end</span>
|
369
|
+
131: <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
|
370
|
+
132: <span class="ruby-keyword kw">else</span>
|
371
|
+
133: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
|
372
|
+
134: <span class="ruby-keyword kw">end</span>
|
373
|
+
135: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
374
|
+
136: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">%[#{ e.message } (#{ e.class })\n#{ e.backtrace.join "\n" }]</span> }
|
375
|
+
137: <span class="ruby-keyword kw">ensure</span>
|
376
|
+
138: <span class="ruby-identifier">exit!</span>
|
377
|
+
139: <span class="ruby-keyword kw">end</span>
|
378
|
+
140: <span class="ruby-comment cmt">#</span>
|
379
|
+
141: <span class="ruby-comment cmt"># parent </span>
|
380
|
+
142: <span class="ruby-comment cmt">#</span>
|
381
|
+
143: <span class="ruby-keyword kw">else</span>
|
382
|
+
144: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">detach</span> <span class="ruby-ivar">@pid</span>
|
383
|
+
145: <span class="ruby-ivar">@w</span>.<span class="ruby-identifier">close</span>
|
384
|
+
146: <span class="ruby-ivar">@socket</span> = <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">read</span>
|
385
|
+
147: <span class="ruby-ivar">@r</span>.<span class="ruby-identifier">close</span>
|
386
|
+
148:
|
387
|
+
149: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - socket <#{ @socket }>"</span> }
|
388
|
+
150:
|
389
|
+
151: <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>
|
390
|
+
152: <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> }
|
391
|
+
153: <span class="ruby-ivar">@uri</span> = <span class="ruby-node">"drbunix://#{ socket }"</span>
|
392
|
+
154: <span class="ruby-identifier">trace</span>{ <span class="ruby-node">"parent - uri <#{ @uri }>"</span> }
|
393
|
+
155: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">start</span>
|
394
|
+
156: <span class="ruby-comment cmt">#</span>
|
395
|
+
157: <span class="ruby-comment cmt"># starting drb on localhost avoids dns lookups!</span>
|
396
|
+
158: <span class="ruby-comment cmt">#</span>
|
397
|
+
159: <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>
|
398
|
+
160: <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>
|
399
|
+
161: <span class="ruby-keyword kw">else</span>
|
400
|
+
162: <span class="ruby-identifier">raise</span> <span class="ruby-node">"failed to find slave socket <#{ @socket }>"</span>
|
401
|
+
163: <span class="ruby-keyword kw">end</span>
|
402
|
+
164: <span class="ruby-keyword kw">end</span>
|
403
|
+
165: <span class="ruby-comment cmt">#--}}}</span>
|
404
|
+
166: <span class="ruby-keyword kw">end</span>
|
405
|
+
</pre>
|
406
|
+
</div>
|
407
|
+
</div>
|
408
|
+
</div>
|
409
|
+
|
410
|
+
<h2 class="section-bar">Public Instance methods</h2>
|
411
|
+
|
412
|
+
<div id="method-M000005" class="method-detail">
|
413
|
+
<a name="M000005"></a>
|
414
|
+
|
415
|
+
<div class="method-heading">
|
416
|
+
<a href="#M000005" class="method-signature">
|
417
|
+
<span class="method-name">gen_psname</span><span class="method-args">obj</span>
|
418
|
+
</a>
|
419
|
+
</div>
|
420
|
+
|
421
|
+
<div class="method-description">
|
422
|
+
<p>
|
423
|
+
generate a default name to appear in ps/top
|
424
|
+
</p>
|
425
|
+
<p><a class="source-toggle" href="#"
|
426
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
427
|
+
<div class="method-source-code" id="M000005-source">
|
428
|
+
<pre>
|
429
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 179</span>
|
430
|
+
179: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_psname</span> <span class="ruby-identifier">obj</span>
|
431
|
+
180: <span class="ruby-comment cmt">#--{{{</span>
|
432
|
+
181: <span class="ruby-node">"#{ obj.class }_slave_of_#{ Process::pid }"</span>.<span class="ruby-identifier">downcase</span>
|
433
|
+
182: <span class="ruby-comment cmt">#--}}}</span>
|
434
|
+
183: <span class="ruby-keyword kw">end</span>
|
435
|
+
</pre>
|
436
|
+
</div>
|
437
|
+
</div>
|
438
|
+
</div>
|
439
|
+
|
440
|
+
<div id="method-M000006" class="method-detail">
|
441
|
+
<a name="M000006"></a>
|
442
|
+
|
443
|
+
<div class="method-heading">
|
444
|
+
<a href="#M000006" class="method-signature">
|
445
|
+
<span class="method-name">getval</span><span class="method-args">key, opts = {}</span>
|
446
|
+
</a>
|
447
|
+
</div>
|
448
|
+
|
449
|
+
<div class="method-description">
|
450
|
+
<p>
|
451
|
+
see docs for class.getval
|
452
|
+
</p>
|
453
|
+
<p><a class="source-toggle" href="#"
|
454
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
455
|
+
<div class="method-source-code" id="M000006-source">
|
456
|
+
<pre>
|
457
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 185</span>
|
458
|
+
185: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getval</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">opts</span> = {}
|
459
|
+
186: <span class="ruby-comment cmt">#--{{{</span>
|
460
|
+
187: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">getval</span> <span class="ruby-identifier">key</span>
|
461
|
+
188: <span class="ruby-comment cmt">#--}}}</span>
|
462
|
+
189: <span class="ruby-keyword kw">end</span>
|
463
|
+
</pre>
|
464
|
+
</div>
|
465
|
+
</div>
|
466
|
+
</div>
|
467
|
+
|
468
|
+
<div id="method-M000004" class="method-detail">
|
469
|
+
<a name="M000004"></a>
|
470
|
+
|
471
|
+
<div class="method-heading">
|
472
|
+
<a href="#M000004" class="method-signature">
|
473
|
+
<span class="method-name">shutdown</span><span class="method-args">()</span>
|
474
|
+
</a>
|
475
|
+
</div>
|
476
|
+
|
477
|
+
<div class="method-description">
|
478
|
+
<p>
|
479
|
+
stops the heartbeat thread and kills the child process
|
480
|
+
</p>
|
481
|
+
<p><a class="source-toggle" href="#"
|
482
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
483
|
+
<div class="method-source-code" id="M000004-source">
|
484
|
+
<pre>
|
485
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 168</span>
|
486
|
+
168: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shutdown</span>
|
487
|
+
169: <span class="ruby-comment cmt">#--{{{</span>
|
488
|
+
170: <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>
|
489
|
+
171: <span class="ruby-ivar">@heartbeat</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
490
|
+
172: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span>(<span class="ruby-value str">'SIGUSR2'</span>, <span class="ruby-ivar">@pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
491
|
+
173: <span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-identifier">kill</span>(<span class="ruby-value str">'SIGTERM'</span>, <span class="ruby-ivar">@pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
|
492
|
+
174: <span class="ruby-constant">FileUtils</span><span class="ruby-operator">::</span><span class="ruby-identifier">rm_f</span> <span class="ruby-ivar">@socket</span>
|
493
|
+
175: <span class="ruby-ivar">@shutdown</span> = <span class="ruby-keyword kw">true</span>
|
494
|
+
176: <span class="ruby-comment cmt">#--}}}</span>
|
495
|
+
177: <span class="ruby-keyword kw">end</span>
|
496
|
+
</pre>
|
497
|
+
</div>
|
498
|
+
</div>
|
499
|
+
</div>
|
500
|
+
|
501
|
+
<div id="method-M000007" class="method-detail">
|
502
|
+
<a name="M000007"></a>
|
503
|
+
|
504
|
+
<div class="method-heading">
|
505
|
+
<a href="#M000007" class="method-signature">
|
506
|
+
<span class="method-name">trace</span><span class="method-args">() {|| ...}</span>
|
507
|
+
</a>
|
508
|
+
</div>
|
509
|
+
|
510
|
+
<div class="method-description">
|
511
|
+
<p>
|
512
|
+
debugging output
|
513
|
+
</p>
|
514
|
+
<p><a class="source-toggle" href="#"
|
515
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
516
|
+
<div class="method-source-code" id="M000007-source">
|
517
|
+
<pre>
|
518
|
+
<span class="ruby-comment cmt"># File lib/slave.rb, line 191</span>
|
519
|
+
191: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">trace</span>
|
520
|
+
192: <span class="ruby-comment cmt">#--{{{</span>
|
521
|
+
193: <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-keyword kw">yield</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@debug</span> <span class="ruby-keyword kw">and</span> <span class="ruby-constant">STDERR</span>.<span class="ruby-identifier">tty?</span>
|
522
|
+
194: <span class="ruby-comment cmt">#--}}}</span>
|
523
|
+
195: <span class="ruby-keyword kw">end</span>
|
524
|
+
</pre>
|
525
|
+
</div>
|
526
|
+
</div>
|
527
|
+
</div>
|
528
|
+
|
529
|
+
|
530
|
+
</div>
|
531
|
+
|
532
|
+
|
533
|
+
</div>
|
534
|
+
|
535
|
+
|
536
|
+
<div id="validator-badges">
|
537
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
538
|
+
</div>
|
539
|
+
|
540
|
+
</body>
|
541
|
+
</html>
|