slave 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/samples/d.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'slave'
2
+ #
3
+ # at_exit hanlders are handled correctly in both child and parent
4
+ #
5
+ at_exit{ p 'parent' }
6
+ slave = Slave.new{ at_exit{ p 'child' }; 'the server is this string' }
7
+ #
8
+ # this will print 'child', then 'parent'
9
+ #
data/samples/e.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'slave'
2
+ #
3
+ # slaves never outlive their parent. if the parent exits, even under kill -9,
4
+ # the child will die.
5
+ #
6
+ slave = Slave.new{ at_exit{ p 'child' }; 'the server is this string' }
7
+
8
+ Process.kill brutal=9, the_parent_pid=Process.pid
9
+ #
10
+ # even though parent dies a nasty death the child will still print 'child'
11
+ #
data/slave-1.0.0.gem ADDED
File without changes
data/test.old/slave.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'test/unit'
2
+
3
+ %w(lib ../lib . ..).each{|d| $:.unshift d}
4
+ require 'slave'
5
+
6
+ STDOUT.sync = true
7
+ STDERR.sync = true
8
+
9
+ class SlaveTest < Test::Unit::TestCase
10
+ #--{{{
11
+ def setup
12
+ end
13
+
14
+ def teardown
15
+ end
16
+
17
+ def test_00
18
+ s = Slave.new Array.new
19
+ end
20
+ #--}}}
21
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: slave
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-09-23 00:00:00.000000 -06:00
6
+ version: 1.0.0
7
+ date: 2006-10-13 00:00:00.000000 -06:00
8
8
  summary: slave
9
9
  require_paths:
10
10
  - lib
@@ -30,17 +30,19 @@ authors:
30
30
  - Ara T. Howard
31
31
  files:
32
32
  - install.rb
33
- - sample
33
+ - test.old
34
34
  - lib
35
35
  - README
36
36
  - rdoc.cmd
37
+ - slave-1.0.0.gem
37
38
  - doc
38
39
  - gemspec.rb
39
- - sample/a.rb
40
- - sample/b.rb
41
- - sample/c.rb
40
+ - samples
41
+ - README.tmpl
42
+ - gen_readme.rb
43
+ - test.old/slave.rb
42
44
  - lib/slave.rb
43
- - lib/slave-0.2.0.rb
45
+ - lib/slave-1.0.0.rb
44
46
  - doc/index.html
45
47
  - doc/files
46
48
  - doc/fr_class_index.html
@@ -62,7 +64,17 @@ files:
62
64
  - doc/dot/f_0.jpg
63
65
  - doc/classes/Slave
64
66
  - doc/classes/Slave.html
67
+ - doc/classes/(@object = Object.new).html
68
+ - doc/classes/@object.html
69
+ - doc/classes/object.html
70
+ - doc/classes/(o = Object.new).html
71
+ - doc/classes/o.html
65
72
  - doc/classes/Slave/Heartbeat.html
73
+ - samples/a.rb
74
+ - samples/b.rb
75
+ - samples/c.rb
76
+ - samples/d.rb
77
+ - samples/e.rb
66
78
  test_files: []
67
79
  rdoc_options: []
68
80
  extra_rdoc_files: []
data/sample/b.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'slave'
2
-
3
- #
4
- # you can wait for a slave to finish if required
5
- #
6
- slave = Slave.new{ p $$; sleep 2; exit 42 }
7
-
8
- p slave.wait
data/sample/c.rb DELETED
@@ -1,109 +0,0 @@
1
- $:.unshift 'lib'
2
- $:.unshift '../lib'
3
-
4
- require 'yaml'
5
- require 'slave'
6
-
7
- class Incrementer
8
- attr :decrementer, true
9
- def increment n
10
- n + 1
11
- end
12
- def decrement n
13
- @decrementer.decrement n
14
- end
15
- end
16
-
17
- class Decrementer
18
- attr :incrementer, true
19
- def increment n
20
- @incrementer.increment n
21
- end
22
- def decrement n
23
- n - 1
24
- end
25
- end
26
-
27
-
28
- #
29
- #
30
- # here we set up a triangle of communicating processes
31
- #
32
- # incrementer------decrementer
33
- # \ /
34
- # \ /
35
- # \ /
36
- # \ /
37
- # \ /
38
- # parent
39
- #
40
- #
41
-
42
- incrementer_slave = Slave::new Incrementer::new
43
- incrementer = incrementer_slave.object
44
-
45
- puts '---'
46
- puts 'incrementer :'
47
- puts " sockect : #{ incrementer_slave.socket.inspect }"
48
- puts " uri : #{ incrementer_slave.uri.inspect }"
49
- puts " pid : #{ incrementer_slave.pid.inspect }"
50
- puts
51
-
52
- decrementer_slave = Slave::new Decrementer::new
53
- decrementer = decrementer_slave.object
54
-
55
- puts '---'
56
- puts 'decrementer :'
57
- puts " sockect : #{ decrementer_slave.socket.inspect }"
58
- puts " uri : #{ decrementer_slave.uri.inspect }"
59
- puts " pid : #{ decrementer_slave.pid.inspect }"
60
- puts
61
-
62
- #
63
- # connect incrementer and decrementer
64
- #
65
-
66
- incrementer.decrementer = decrementer
67
- decrementer.incrementer = incrementer
68
-
69
- #
70
- # now we can call methods on each drb object, and they can also call methods on
71
- # each other
72
- #
73
-
74
- n = 0
75
-
76
- #n = incrementer.increment n
77
- #p n #=> 1
78
- y "incrementer.increment(#{ n })" => (n = incrementer.increment(n))
79
-
80
- #n = decrementer.decrement n
81
- #p n #=> 0
82
- y "decrementer.decrement(#{ n })" => (n = decrementer.decrement(n))
83
-
84
- #n = decrementer.increment n
85
- #p n #=> 1
86
- y "decrementer.increment(#{ n })" => (n = decrementer.increment(n))
87
-
88
- #n = incrementer.decrement n
89
- #p n #=> 0
90
- y "incrementer.decrement(#{ n })" => (n = incrementer.decrement(n))
91
-
92
- #
93
- # we can explicitly shutdown certain slaves
94
- #
95
-
96
- incrementer_slave.shutdown
97
- #n = decrementer.decrement 43
98
- #p n #=> 42
99
- n = 43
100
- y "decrementer.decrement(#{ n })" => (n = decrementer.decrement(n))
101
-
102
- #
103
- # Slaves cannot live beyond their parent so we simply exit and all living slaves
104
- # will eventually die. how long it takes to die is determined by the
105
- # pulse_rate - the next time the Heartbeat trys to ping the parent the Slave
106
- # will die.
107
- #
108
-
109
- exit