slave 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +390 -0
- data/doc/classes/Slave.html +765 -790
- data/doc/classes/Slave/LifeLine.html +262 -249
- data/doc/classes/Slave/ThreadSafe.html +184 -176
- data/doc/classes/Slave/ThreadSafeHash.html +85 -78
- data/doc/created.rid +1 -1
- data/doc/dot/f_0.dot +1 -1
- data/doc/dot/f_0.jpg +0 -0
- data/doc/dot/f_1.dot +1 -10
- data/doc/dot/f_1.jpg +0 -0
- data/doc/files/README.html +87 -70
- data/doc/files/lib/slave_rb.html +77 -83
- data/doc/fr_class_index.html +12 -13
- data/doc/fr_file_index.html +10 -10
- data/doc/fr_method_index.html +38 -39
- data/doc/index.html +3 -3
- data/doc/rdoc-style.css +79 -43
- data/install.rb +0 -0
- data/lib/slave.rb +1 -1
- data/rdoc.cmd +0 -0
- metadata +76 -64
- data/slave-1.2.1.gem +0 -0
data/Rakefile
ADDED
@@ -0,0 +1,390 @@
|
|
1
|
+
This.rubyforge_project = 'codeforpeople'
|
2
|
+
This.author = "Ara T. Howard"
|
3
|
+
This.email = "ara.t.howard@gmail.com"
|
4
|
+
This.homepage = "https://github.com/ahoward/#{ This.lib }"
|
5
|
+
|
6
|
+
|
7
|
+
task :default do
|
8
|
+
puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
run_tests!
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :test do
|
16
|
+
task(:unit){ run_tests!(:unit) }
|
17
|
+
task(:functional){ run_tests!(:functional) }
|
18
|
+
task(:integration){ run_tests!(:integration) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_tests!(which = nil)
|
22
|
+
which ||= '**'
|
23
|
+
test_dir = File.join(This.dir, "test")
|
24
|
+
test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
|
25
|
+
test_rbs = Dir.glob(test_glob).sort
|
26
|
+
|
27
|
+
div = ('=' * 119)
|
28
|
+
line = ('-' * 119)
|
29
|
+
|
30
|
+
test_rbs.each_with_index do |test_rb, index|
|
31
|
+
testno = index + 1
|
32
|
+
command = "#{ This.ruby } -I ./lib -I ./test/lib #{ test_rb }"
|
33
|
+
|
34
|
+
puts
|
35
|
+
say(div, :color => :cyan, :bold => true)
|
36
|
+
say("@#{ testno } => ", :bold => true, :method => :print)
|
37
|
+
say(command, :color => :cyan, :bold => true)
|
38
|
+
say(line, :color => :cyan, :bold => true)
|
39
|
+
|
40
|
+
system(command)
|
41
|
+
|
42
|
+
say(line, :color => :cyan, :bold => true)
|
43
|
+
|
44
|
+
status = $?.exitstatus
|
45
|
+
|
46
|
+
if status.zero?
|
47
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
48
|
+
say("SUCCESS", :color => :green, :bold => true)
|
49
|
+
else
|
50
|
+
say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
|
51
|
+
say("FAILURE", :color => :red, :bold => true)
|
52
|
+
end
|
53
|
+
say(line, :color => :cyan, :bold => true)
|
54
|
+
|
55
|
+
exit(status) unless status.zero?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
task :gemspec do
|
61
|
+
ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
|
62
|
+
ignore_directories = ['pkg']
|
63
|
+
ignore_files = ['test/log', 'a.rb'] + Dir['db/*'] + %w'db'
|
64
|
+
|
65
|
+
shiteless =
|
66
|
+
lambda do |list|
|
67
|
+
list.delete_if do |entry|
|
68
|
+
next unless test(?e, entry)
|
69
|
+
extension = File.basename(entry).split(%r/[.]/).last
|
70
|
+
ignore_extensions.any?{|ext| ext === extension}
|
71
|
+
end
|
72
|
+
list.delete_if do |entry|
|
73
|
+
next unless test(?d, entry)
|
74
|
+
dirname = File.expand_path(entry)
|
75
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
76
|
+
end
|
77
|
+
list.delete_if do |entry|
|
78
|
+
next unless test(?f, entry)
|
79
|
+
filename = File.expand_path(entry)
|
80
|
+
ignore_files.any?{|file| File.expand_path(file) == filename}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
lib = This.lib
|
85
|
+
object = This.object
|
86
|
+
version = This.version
|
87
|
+
files = shiteless[Dir::glob("**/**")]
|
88
|
+
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
89
|
+
#has_rdoc = true #File.exist?('doc')
|
90
|
+
test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
|
91
|
+
summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
|
92
|
+
description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
|
93
|
+
|
94
|
+
if This.extensions.nil?
|
95
|
+
This.extensions = []
|
96
|
+
extensions = This.extensions
|
97
|
+
%w( Makefile configure extconf.rb ).each do |ext|
|
98
|
+
extensions << ext if File.exists?(ext)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
extensions = [extensions].flatten.compact
|
102
|
+
|
103
|
+
# TODO
|
104
|
+
if This.dependencies.nil?
|
105
|
+
dependencies = []
|
106
|
+
else
|
107
|
+
case This.dependencies
|
108
|
+
when Hash
|
109
|
+
dependencies = This.dependencies.values
|
110
|
+
when Array
|
111
|
+
dependencies = This.dependencies
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
template =
|
116
|
+
if test(?e, 'gemspec.erb')
|
117
|
+
Template{ IO.read('gemspec.erb') }
|
118
|
+
else
|
119
|
+
Template {
|
120
|
+
<<-__
|
121
|
+
## <%= lib %>.gemspec
|
122
|
+
#
|
123
|
+
|
124
|
+
Gem::Specification::new do |spec|
|
125
|
+
spec.name = <%= lib.inspect %>
|
126
|
+
spec.version = <%= version.inspect %>
|
127
|
+
spec.platform = Gem::Platform::RUBY
|
128
|
+
spec.summary = <%= lib.inspect %>
|
129
|
+
spec.description = <%= description.inspect %>
|
130
|
+
|
131
|
+
spec.files =\n<%= files.sort.pretty_inspect %>
|
132
|
+
spec.executables = <%= executables.inspect %>
|
133
|
+
|
134
|
+
spec.require_path = "lib"
|
135
|
+
|
136
|
+
spec.test_files = <%= test_files.inspect %>
|
137
|
+
|
138
|
+
<% dependencies.each do |lib_version| %>
|
139
|
+
spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
|
140
|
+
<% end %>
|
141
|
+
|
142
|
+
spec.extensions.push(*<%= extensions.inspect %>)
|
143
|
+
|
144
|
+
spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
|
145
|
+
spec.author = <%= This.author.inspect %>
|
146
|
+
spec.email = <%= This.email.inspect %>
|
147
|
+
spec.homepage = <%= This.homepage.inspect %>
|
148
|
+
end
|
149
|
+
__
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
Fu.mkdir_p(This.pkgdir)
|
154
|
+
gemspec = "#{ lib }.gemspec"
|
155
|
+
open(gemspec, "w"){|fd| fd.puts(template)}
|
156
|
+
This.gemspec = gemspec
|
157
|
+
end
|
158
|
+
|
159
|
+
task :gem => [:clean, :gemspec] do
|
160
|
+
Fu.mkdir_p(This.pkgdir)
|
161
|
+
before = Dir['*.gem']
|
162
|
+
cmd = "gem build #{ This.gemspec }"
|
163
|
+
`#{ cmd }`
|
164
|
+
after = Dir['*.gem']
|
165
|
+
gem = ((after - before).first || after.first) or abort('no gem!')
|
166
|
+
Fu.mv(gem, This.pkgdir)
|
167
|
+
This.gem = File.join(This.pkgdir, File.basename(gem))
|
168
|
+
end
|
169
|
+
|
170
|
+
task :readme do
|
171
|
+
samples = ''
|
172
|
+
prompt = '~ > '
|
173
|
+
lib = This.lib
|
174
|
+
version = This.version
|
175
|
+
|
176
|
+
Dir['sample*/*'].sort.each do |sample|
|
177
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
178
|
+
|
179
|
+
cmd = "cat #{ sample }"
|
180
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
181
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
182
|
+
|
183
|
+
cmd = "ruby #{ sample }"
|
184
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
185
|
+
|
186
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
|
187
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
188
|
+
end
|
189
|
+
|
190
|
+
template =
|
191
|
+
if test(?e, 'readme.erb')
|
192
|
+
Template{ IO.read('readme.erb') }
|
193
|
+
else
|
194
|
+
Template {
|
195
|
+
<<-__
|
196
|
+
NAME
|
197
|
+
#{ lib }
|
198
|
+
|
199
|
+
DESCRIPTION
|
200
|
+
|
201
|
+
INSTALL
|
202
|
+
gem install #{ lib }
|
203
|
+
|
204
|
+
SAMPLES
|
205
|
+
#{ samples }
|
206
|
+
__
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
210
|
+
open("README", "w"){|fd| fd.puts template}
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
task :clean do
|
215
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
task :release => [:clean, :gemspec, :gem] do
|
220
|
+
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
221
|
+
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
222
|
+
raise "no gems?" if gems.size < 1
|
223
|
+
|
224
|
+
cmd = "gem push #{ This.gem }"
|
225
|
+
puts cmd
|
226
|
+
puts
|
227
|
+
system(cmd)
|
228
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
229
|
+
|
230
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
|
231
|
+
puts cmd
|
232
|
+
puts
|
233
|
+
system(cmd)
|
234
|
+
abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
BEGIN {
|
242
|
+
# support for this rakefile
|
243
|
+
#
|
244
|
+
$VERBOSE = nil
|
245
|
+
|
246
|
+
require 'ostruct'
|
247
|
+
require 'erb'
|
248
|
+
require 'fileutils'
|
249
|
+
require 'rbconfig'
|
250
|
+
require 'pp'
|
251
|
+
|
252
|
+
# fu shortcut
|
253
|
+
#
|
254
|
+
Fu = FileUtils
|
255
|
+
|
256
|
+
# cache a bunch of stuff about this rakefile/environment
|
257
|
+
#
|
258
|
+
This = OpenStruct.new
|
259
|
+
|
260
|
+
This.file = File.expand_path(__FILE__)
|
261
|
+
This.dir = File.dirname(This.file)
|
262
|
+
This.pkgdir = File.join(This.dir, 'pkg')
|
263
|
+
|
264
|
+
# grok lib
|
265
|
+
#
|
266
|
+
lib = ENV['LIB']
|
267
|
+
unless lib
|
268
|
+
lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
|
269
|
+
end
|
270
|
+
This.lib = lib
|
271
|
+
|
272
|
+
# grok version
|
273
|
+
#
|
274
|
+
version = ENV['VERSION']
|
275
|
+
unless version
|
276
|
+
require "./lib/#{ This.lib }"
|
277
|
+
This.name = lib.capitalize
|
278
|
+
This.object = eval(This.name)
|
279
|
+
version = This.object.send(:version)
|
280
|
+
end
|
281
|
+
This.version = version
|
282
|
+
|
283
|
+
# see if dependencies are export by the module
|
284
|
+
#
|
285
|
+
if This.object.respond_to?(:dependencies)
|
286
|
+
This.dependencies = This.object.dependencies
|
287
|
+
end
|
288
|
+
|
289
|
+
# we need to know the name of the lib an it's version
|
290
|
+
#
|
291
|
+
abort('no lib') unless This.lib
|
292
|
+
abort('no version') unless This.version
|
293
|
+
|
294
|
+
# discover full path to this ruby executable
|
295
|
+
#
|
296
|
+
c = Config::CONFIG
|
297
|
+
bindir = c["bindir"] || c['BINDIR']
|
298
|
+
ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
|
299
|
+
ruby_ext = c['EXEEXT'] || ''
|
300
|
+
ruby = File.join(bindir, (ruby_install_name + ruby_ext))
|
301
|
+
This.ruby = ruby
|
302
|
+
|
303
|
+
# some utils
|
304
|
+
#
|
305
|
+
module Util
|
306
|
+
def indent(s, n = 2)
|
307
|
+
s = unindent(s)
|
308
|
+
ws = ' ' * n
|
309
|
+
s.gsub(%r/^/, ws)
|
310
|
+
end
|
311
|
+
|
312
|
+
def unindent(s)
|
313
|
+
indent = nil
|
314
|
+
s.each_line do |line|
|
315
|
+
next if line =~ %r/^\s*$/
|
316
|
+
indent = line[%r/^\s*/] and break
|
317
|
+
end
|
318
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
319
|
+
end
|
320
|
+
extend self
|
321
|
+
end
|
322
|
+
|
323
|
+
# template support
|
324
|
+
#
|
325
|
+
class Template
|
326
|
+
def initialize(&block)
|
327
|
+
@block = block
|
328
|
+
@template = block.call.to_s
|
329
|
+
end
|
330
|
+
def expand(b=nil)
|
331
|
+
ERB.new(Util.unindent(@template)).result((b||@block).binding)
|
332
|
+
end
|
333
|
+
alias_method 'to_s', 'expand'
|
334
|
+
end
|
335
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
336
|
+
|
337
|
+
# colored console output support
|
338
|
+
#
|
339
|
+
This.ansi = {
|
340
|
+
:clear => "\e[0m",
|
341
|
+
:reset => "\e[0m",
|
342
|
+
:erase_line => "\e[K",
|
343
|
+
:erase_char => "\e[P",
|
344
|
+
:bold => "\e[1m",
|
345
|
+
:dark => "\e[2m",
|
346
|
+
:underline => "\e[4m",
|
347
|
+
:underscore => "\e[4m",
|
348
|
+
:blink => "\e[5m",
|
349
|
+
:reverse => "\e[7m",
|
350
|
+
:concealed => "\e[8m",
|
351
|
+
:black => "\e[30m",
|
352
|
+
:red => "\e[31m",
|
353
|
+
:green => "\e[32m",
|
354
|
+
:yellow => "\e[33m",
|
355
|
+
:blue => "\e[34m",
|
356
|
+
:magenta => "\e[35m",
|
357
|
+
:cyan => "\e[36m",
|
358
|
+
:white => "\e[37m",
|
359
|
+
:on_black => "\e[40m",
|
360
|
+
:on_red => "\e[41m",
|
361
|
+
:on_green => "\e[42m",
|
362
|
+
:on_yellow => "\e[43m",
|
363
|
+
:on_blue => "\e[44m",
|
364
|
+
:on_magenta => "\e[45m",
|
365
|
+
:on_cyan => "\e[46m",
|
366
|
+
:on_white => "\e[47m"
|
367
|
+
}
|
368
|
+
def say(phrase, *args)
|
369
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
370
|
+
options[:color] = args.shift.to_s.to_sym unless args.empty?
|
371
|
+
keys = options.keys
|
372
|
+
keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
|
373
|
+
|
374
|
+
color = options[:color]
|
375
|
+
bold = options.has_key?(:bold)
|
376
|
+
|
377
|
+
parts = [phrase]
|
378
|
+
parts.unshift(This.ansi[color]) if color
|
379
|
+
parts.unshift(This.ansi[:bold]) if bold
|
380
|
+
parts.push(This.ansi[:clear]) if parts.size > 1
|
381
|
+
|
382
|
+
method = options[:method] || :puts
|
383
|
+
|
384
|
+
Kernel.send(method, parts.join)
|
385
|
+
end
|
386
|
+
|
387
|
+
# always run out of the project dir
|
388
|
+
#
|
389
|
+
Dir.chdir(This.dir)
|
390
|
+
}
|
data/doc/classes/Slave.html
CHANGED
@@ -1,45 +1,45 @@
|
|
1
1
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
2
|
<!DOCTYPE html
|
3
3
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"DTD/xhtml1-transitional.dtd">
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
5
|
|
6
6
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
7
|
<head>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
43
|
|
44
44
|
</head>
|
45
45
|
<body>
|
@@ -47,15 +47,18 @@
|
|
47
47
|
|
48
48
|
|
49
49
|
<div id="classHeader">
|
50
|
-
<h1>Slave <sup class="type-note">(Class)</sup></h1>
|
51
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>
|
52
55
|
<tr class="top-aligned-row">
|
53
56
|
<td><strong>In:</strong></td>
|
54
57
|
<td>
|
55
58
|
<a href="../files/lib/slave_rb.html">
|
56
59
|
lib/slave.rb
|
57
60
|
</a>
|
58
|
-
|
61
|
+
<br />
|
59
62
|
</td>
|
60
63
|
</tr>
|
61
64
|
|
@@ -69,30 +72,30 @@
|
|
69
72
|
</div>
|
70
73
|
<!-- banner header -->
|
71
74
|
|
72
|
-
|
75
|
+
<div id="bodyContent">
|
73
76
|
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
<area shape="
|
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" />
|
80
83
|
</map>
|
81
|
-
<img src="../dot/f_1.jpg" usemap="#map" border=0 alt="
|
82
|
-
|
84
|
+
<img src="../dot/f_1.jpg" usemap="#map" border="0" alt="dot/f_1.jpg">
|
85
|
+
</div>
|
83
86
|
|
84
|
-
|
85
|
-
|
87
|
+
<div id="description">
|
88
|
+
<p>
|
86
89
|
the <a href="Slave.html">Slave</a> class encapsulates the work of setting
|
87
90
|
up a drb server in another process running on localhost via unix domain
|
88
|
-
sockets. the slave process is attached to it&#
|
91
|
+
sockets. the slave process is attached to it‘s parent via a <a
|
89
92
|
href="Slave/LifeLine.html">LifeLine</a> which is designed such that the
|
90
|
-
slave cannot out-live it&#
|
93
|
+
slave cannot out-live it‘s parent and become a zombie, even if the
|
91
94
|
parent dies and early death, such as by ‘kill -9’. the concept
|
92
95
|
and purpose of the <a href="Slave.html">Slave</a> class is to be able to
|
93
|
-
setup any server object in another process
|
94
|
-
multi-process, drb/ipc, based design is as easy, or
|
95
|
-
multi-threaded one. eg
|
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
|
96
99
|
</p>
|
97
100
|
<pre>
|
98
101
|
class Server
|
@@ -123,208 +126,205 @@ called only in the child" }
|
|
123
126
|
of the two ‘b’ is preferred.
|
124
127
|
</p>
|
125
128
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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">
|
170
188
|
env config
|
171
189
|
|
172
190
|
</td>
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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">
|
204
222
|
if this is true and you are running from a terminal information is printed
|
205
223
|
on STDERR
|
206
224
|
|
207
225
|
</td>
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
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">
|
223
241
|
attrs
|
224
242
|
|
225
243
|
</td>
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
</tr>
|
272
|
-
<tr class="top-aligned-row context-row">
|
273
|
-
<td class="context-item-name">threadsafe</td>
|
274
|
-
<td class="context-item-value"> [RW] </td>
|
275
|
-
<td class="context-item-desc">
|
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">
|
276
289
|
if this is true all slave objects will be wrapped such that any call to the
|
277
|
-
object is threadsafe. if you do not use
|
278
|
-
objects are threadsafe <em>yourself</em> as
|
279
|
-
acting as a
|
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
|
280
294
|
|
281
295
|
</td>
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
<div id="class-list">
|
293
|
-
<h2 class="section-bar">Classes and Modules</h2>
|
294
|
-
|
295
|
-
Class <a href="Slave/LifeLine.html" class="link">Slave::LifeLine</a><br />
|
296
|
-
Class <a href="Slave/ThreadSafe.html" class="link">Slave::ThreadSafe</a><br />
|
297
|
-
Class <a href="Slave/ThreadSafeHash.html" class="link">Slave::ThreadSafeHash</a><br />
|
298
|
-
|
299
|
-
</div>
|
300
|
-
|
301
|
-
</div>
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
<!-- if includes -->
|
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
306
|
|
307
307
|
|
308
|
-
|
309
|
-
|
310
|
-
|
308
|
+
<!-- if method_list -->
|
309
|
+
<div id="methods">
|
310
|
+
<h3 class="section-bar">Public Class methods</h3>
|
311
311
|
|
312
|
-
|
313
|
-
|
312
|
+
<div id="method-M000002" class="method-detail">
|
313
|
+
<a name="M000002"></a>
|
314
314
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
get a default value
|
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
324
|
</p>
|
325
|
-
|
326
|
-
|
327
|
-
|
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
328
|
<pre>
|
329
329
|
<span class="ruby-comment cmt"># File lib/slave.rb, line 77</span>
|
330
330
|
77: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span> <span class="ruby-identifier">key</span>
|
@@ -333,57 +333,57 @@ get a default value
|
|
333
333
|
80: <span class="ruby-comment cmt">#--}}}</span>
|
334
334
|
81: <span class="ruby-keyword kw">end</span>
|
335
335
|
</pre>
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
just fork with out silly warnings
|
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
352
|
</p>
|
353
|
-
|
354
|
-
|
355
|
-
|
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
356
|
<pre>
|
357
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">
|
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
359
|
99: <span class="ruby-comment cmt">#--{{{</span>
|
360
360
|
100: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">$VERBOSE</span>
|
361
361
|
101: <span class="ruby-keyword kw">begin</span>
|
362
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>
|
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
364
|
104: <span class="ruby-keyword kw">ensure</span>
|
365
365
|
105: <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">v</span>
|
366
366
|
106: <span class="ruby-keyword kw">end</span>
|
367
367
|
107: <span class="ruby-comment cmt">#--}}}</span>
|
368
368
|
108: <span class="ruby-keyword kw">end</span>
|
369
369
|
</pre>
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
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
387
|
<pre>
|
388
388
|
<span class="ruby-comment cmt"># File lib/slave.rb, line 83</span>
|
389
389
|
83: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getopts</span> <span class="ruby-identifier">opts</span>
|
@@ -400,27 +400,29 @@ just fork with out silly warnings
|
|
400
400
|
94: <span class="ruby-comment cmt">#--}}}</span>
|
401
401
|
95: <span class="ruby-keyword kw">end</span>
|
402
402
|
</pre>
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
sets up a child process serving any object
|
419
|
-
on unix domain sockets. the child process
|
420
|
-
href="Slave/LifeLine.html">LifeLine</a> established between it and
|
421
|
-
parent, making it impossible for the child to outlive the parent
|
422
|
-
zombie). the object to serve is
|
423
|
-
‘
|
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
|
424
426
|
</p>
|
425
427
|
<pre>
|
426
428
|
Slave.new :object => MyServer.new
|
@@ -432,14 +434,17 @@ or, preferably, using the block form
|
|
432
434
|
Slave.new{ MyServer.new }
|
433
435
|
</pre>
|
434
436
|
<p>
|
435
|
-
when the block form is used the object is
|
436
|
-
itself. this is quite advantageous if the
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
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.
|
443
448
|
</p>
|
444
449
|
<p>
|
445
450
|
opts may contain the following keys, as either strings or symbols
|
@@ -453,178 +458,180 @@ opts may contain the following keys, as either strings or symbols
|
|
453
458
|
dumped : specify that the slave object should *not* be DRbUndumped (default is DRbUndumped)
|
454
459
|
threadsafe : wrap the slave object with ThreadSafe to implement gross thread safety
|
455
460
|
</pre>
|
456
|
-
|
457
|
-
|
458
|
-
|
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">
|
459
464
|
<pre>
|
460
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
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>
|
491
498
|
351: <span class="ruby-comment cmt">#</span>
|
492
|
-
352:
|
493
|
-
353:
|
494
|
-
354:
|
495
|
-
355:
|
496
|
-
356:
|
497
|
-
357:
|
498
|
-
358: <span class="ruby-
|
499
|
-
359:
|
500
|
-
360: <span class="ruby-keyword kw">
|
501
|
-
361: <span class="ruby-
|
502
|
-
362:
|
503
|
-
363: <span class="ruby-keyword kw">
|
504
|
-
364: <span class="ruby-
|
505
|
-
365: <span class="ruby-keyword kw">
|
506
|
-
366:
|
507
|
-
367:
|
508
|
-
368: <span class="ruby-keyword kw">
|
509
|
-
369:
|
510
|
-
370:
|
511
|
-
371: <span class="ruby-keyword kw">
|
512
|
-
372: <span class="ruby-identifier">
|
513
|
-
373: <span class="ruby-keyword kw">
|
514
|
-
374:
|
515
|
-
375:
|
516
|
-
376: <span class="ruby-
|
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>))
|
517
524
|
377:
|
518
|
-
378: <span class="ruby-
|
519
|
-
379:
|
520
|
-
380: <span class="ruby-keyword kw">
|
521
|
-
381:
|
522
|
-
382: <span class="ruby-keyword kw">
|
523
|
-
383:
|
524
|
-
384: <span class="ruby-keyword kw">
|
525
|
-
385:
|
526
|
-
386: <span class="ruby-
|
527
|
-
387:
|
528
|
-
388: <span class="ruby-ivar">@
|
529
|
-
389:
|
530
|
-
390: <span class="ruby-
|
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>)
|
531
538
|
391:
|
532
|
-
392: <span class="ruby-
|
533
|
-
393:
|
534
|
-
394:
|
535
|
-
395:
|
536
|
-
396:
|
537
|
-
397: <span class="ruby-
|
538
|
-
398: <span class="ruby-
|
539
|
-
399: <span class="ruby-
|
540
|
-
400: <span class="ruby-
|
541
|
-
401: <span class="ruby-
|
542
|
-
402: <span class="ruby-
|
543
|
-
403:
|
544
|
-
404: <span class="ruby-keyword kw">
|
545
|
-
405: <span class="ruby-keyword kw">
|
546
|
-
406:
|
547
|
-
407:
|
548
|
-
408: <span class="ruby-keyword kw">
|
549
|
-
409:
|
550
|
-
410:
|
551
|
-
411:
|
552
|
-
412: <span class="ruby-
|
553
|
-
413:
|
554
|
-
414:
|
555
|
-
415: <span class="ruby-
|
556
|
-
416:
|
557
|
-
417:
|
558
|
-
418: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">
|
559
|
-
419:
|
560
|
-
420: <span class="ruby-
|
561
|
-
421:
|
562
|
-
422:
|
563
|
-
423: <span class="ruby-
|
564
|
-
424: <span class="ruby-keyword kw">
|
565
|
-
425: <span class="ruby-identifier">
|
566
|
-
426:
|
567
|
-
427:
|
568
|
-
428:
|
569
|
-
429:
|
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>
|
570
577
|
430: <span class="ruby-comment cmt">#</span>
|
571
|
-
431:
|
572
|
-
432:
|
573
|
-
433:
|
574
|
-
434:
|
575
|
-
435: <span class="ruby-ivar">@lifeline</span>.<span class="ruby-identifier">
|
576
|
-
436:
|
577
|
-
437: <span class="ruby-
|
578
|
-
438: <span class="ruby-identifier">
|
579
|
-
439:
|
580
|
-
440: <span class="ruby-
|
581
|
-
441:
|
582
|
-
442:
|
583
|
-
443:
|
584
|
-
444:
|
585
|
-
445:
|
586
|
-
446: <span class="ruby-keyword kw">
|
587
|
-
447:
|
588
|
-
448:
|
589
|
-
449: <span class="ruby-
|
590
|
-
450:
|
591
|
-
451:
|
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>
|
592
599
|
452: <span class="ruby-comment cmt">#</span>
|
593
|
-
453:
|
594
|
-
454:
|
595
|
-
455: <span class="ruby-
|
596
|
-
456:
|
597
|
-
457:
|
598
|
-
458: <span class="ruby-identifier">
|
599
|
-
459:
|
600
|
-
460:
|
601
|
-
461:
|
602
|
-
462:
|
603
|
-
463: <span class="ruby-
|
604
|
-
464: <span class="ruby-keyword kw">
|
605
|
-
465:
|
606
|
-
466:
|
607
|
-
467:
|
608
|
-
468: <span class="ruby-comment cmt">#--}}}</span>
|
609
|
-
469: <span class="ruby-keyword kw">end</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>
|
610
615
|
</pre>
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
a simple convenience method which returns an <b
|
627
|
-
|
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
|
628
635
|
</p>
|
629
636
|
<pre>
|
630
637
|
object = Slave.object{ processor_intensive_object_built_in_child_process() }
|
@@ -643,375 +650,343 @@ keyword
|
|
643
650
|
|
644
651
|
object = thread.value
|
645
652
|
</pre>
|
646
|
-
|
647
|
-
|
648
|
-
|
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">
|
649
656
|
<pre>
|
650
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
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>
|
665
678
|
</pre>
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
<pre>
|
684
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line 603</span>
|
685
|
-
603: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">object</span> <span class="ruby-identifier">opts</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>
|
686
|
-
604: <span class="ruby-comment cmt">#--{{{</span>
|
687
|
-
605: <span class="ruby-identifier">async</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value str">'async'</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:async</span>)
|
688
|
-
606:
|
689
|
-
607: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'object'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:object</span>] = <span class="ruby-identifier">lambda</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
|
690
|
-
608: <span class="ruby-identifier">opts</span>[<span class="ruby-value str">'dumped'</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:dumped</span>] = <span class="ruby-keyword kw">true</span>
|
691
|
-
609:
|
692
|
-
610: <span class="ruby-identifier">slave</span> = <span class="ruby-constant">Slave</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">opts</span>
|
693
|
-
611:
|
694
|
-
612: <span class="ruby-identifier">value</span> = <span class="ruby-identifier">lambda</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">slave</span><span class="ruby-operator">|</span>
|
695
|
-
613: <span class="ruby-keyword kw">begin</span>
|
696
|
-
614: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">object</span>.<span class="ruby-identifier">call</span>
|
697
|
-
615: <span class="ruby-keyword kw">ensure</span>
|
698
|
-
616: <span class="ruby-identifier">slave</span>.<span class="ruby-identifier">shutdown</span>
|
699
|
-
617: <span class="ruby-keyword kw">end</span>
|
700
|
-
618: <span class="ruby-keyword kw">end</span>
|
701
|
-
619:
|
702
|
-
620: <span class="ruby-identifier">async</span> <span class="ruby-value">? </span><span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{ <span class="ruby-identifier">value</span>[<span class="ruby-identifier">slave</span>] } <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>[<span class="ruby-identifier">slave</span>]
|
703
|
-
621: <span class="ruby-comment cmt">#--}}}</span>
|
704
|
-
622: <span class="ruby-keyword kw">end</span>
|
705
|
-
</pre>
|
706
|
-
</div>
|
707
|
-
</div>
|
708
|
-
</div>
|
709
|
-
|
710
|
-
<div id="method-M000001" class="method-detail">
|
711
|
-
<a name="M000001"></a>
|
712
|
-
|
713
|
-
<div class="method-heading">
|
714
|
-
<a href="#M000001" class="method-signature">
|
715
|
-
<span class="method-name">version</span><span class="method-args">()</span>
|
716
|
-
</a>
|
717
|
-
</div>
|
718
|
-
|
719
|
-
<div class="method-description">
|
720
|
-
<p><a class="source-toggle" href="#"
|
721
|
-
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
722
|
-
<div class="method-source-code" id="M000001-source">
|
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">
|
723
696
|
<pre>
|
724
697
|
<span class="ruby-comment cmt"># File lib/slave.rb, line 44</span>
|
725
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>
|
726
699
|
</pre>
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
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>
|
744
717
|
see docs for <a href="Slave.html#M000002">Slave.default</a>
|
745
718
|
</p>
|
746
|
-
|
747
|
-
|
748
|
-
|
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">
|
749
722
|
<pre>
|
750
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
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>
|
756
729
|
</pre>
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
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>
|
772
745
|
starts a thread to collect the child status and sets up at_exit handler to
|
773
746
|
prevent zombies. the at_exit handler is canceled if the thread is able to
|
774
747
|
collect the status
|
775
748
|
</p>
|
776
|
-
|
777
|
-
|
778
|
-
|
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">
|
779
752
|
<pre>
|
780
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
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>
|
807
780
|
</pre>
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
generate a default name to appear in
|
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
|
824
798
|
</p>
|
825
|
-
|
826
|
-
|
827
|
-
|
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">
|
828
802
|
<pre>
|
829
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
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>
|
835
809
|
</pre>
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
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>
|
851
825
|
see docs for <a href="Slave.html#M000003">Slave.getopts</a>
|
852
826
|
</p>
|
853
|
-
|
854
|
-
|
855
|
-
|
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">
|
856
830
|
<pre>
|
857
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
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>
|
863
837
|
</pre>
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
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>
|
879
853
|
cuts the lifeline and kills the child process - give the key
|
880
854
|
‘quiet’ to ignore errors shutting down, including having
|
881
|
-
already shutdown
|
855
|
+
already <a href="Slave.html#M000009">shutdown</a>
|
882
856
|
</p>
|
883
|
-
|
884
|
-
|
885
|
-
|
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">
|
886
860
|
<pre>
|
887
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
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>
|
898
872
|
</pre>
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
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>
|
914
888
|
true
|
915
889
|
</p>
|
916
|
-
|
917
|
-
|
918
|
-
|
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">
|
919
893
|
<pre>
|
920
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
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>
|
926
900
|
</pre>
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
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>
|
942
916
|
debugging output - ENV[‘SLAVE_DEBUG’]=1 to enable
|
943
917
|
</p>
|
944
|
-
|
945
|
-
|
946
|
-
|
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">
|
947
921
|
<pre>
|
948
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
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>
|
957
931
|
</pre>
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
wait for slave to finish. if the keyword
|
974
|
-
is given a thread is returned to do the
|
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
|
975
950
|
</p>
|
976
951
|
<pre>
|
977
952
|
thread = slave.wait(:non_block=>true){|value| "background <#{ value }>"}
|
978
953
|
</pre>
|
979
|
-
|
980
|
-
|
981
|
-
|
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">
|
982
957
|
<pre>
|
983
|
-
<span class="ruby-comment cmt"># File lib/slave.rb, line
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
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>
|
991
966
|
</pre>
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
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>
|
1005
980
|
Alias for <a href="Slave.html#M000007">wait</a>
|
1006
981
|
</p>
|
1007
|
-
|
1008
|
-
|
982
|
+
</div>
|
983
|
+
</div>
|
1009
984
|
|
1010
985
|
|
1011
|
-
|
986
|
+
</div>
|
1012
987
|
|
1013
988
|
|
1014
|
-
|
989
|
+
</div>
|
1015
990
|
|
1016
991
|
|
1017
992
|
<div id="validator-badges">
|