dramatis 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/License.txt +20 -0
- data/Manifest.txt +119 -0
- data/README.txt +57 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/examples/README.txt +20 -0
- data/examples/auction.rb +90 -0
- data/examples/bank/bank.rb +7 -0
- data/examples/bank/bank_test.rb +7 -0
- data/examples/exception.rb +40 -0
- data/examples/fib/conservative.rb +50 -0
- data/examples/fib/future.rb +5 -0
- data/examples/fib/original.rb +33 -0
- data/examples/fib/threads.rb +51 -0
- data/examples/im/distributed/chat/client.rb +49 -0
- data/examples/im/distributed/chat/screen/fox.rb +92 -0
- data/examples/im/distributed/chat/screen.rb +11 -0
- data/examples/im/distributed/chat/server.rb +72 -0
- data/examples/im/distributed/chat.rb +5 -0
- data/examples/im/distributed/client.rb +9 -0
- data/examples/im/distributed/run.rb +18 -0
- data/examples/im/distributed/server.rb +11 -0
- data/examples/im/single/chat/client.rb +50 -0
- data/examples/im/single/chat/screen/fox.rb +96 -0
- data/examples/im/single/chat/screen/wxs.rb +63 -0
- data/examples/im/single/chat/screen.rb +11 -0
- data/examples/im/single/chat/server.rb +72 -0
- data/examples/im/single/chat.rb +5 -0
- data/examples/im/single/fox.rb +18 -0
- data/examples/im/single/wxchat.rb +19 -0
- data/examples/pingpong/actor.rb +33 -0
- data/examples/pingpong/actor_rec.rb +34 -0
- data/examples/pingpong/pingpong.txt +315 -0
- data/examples/pingpong/scala.rb +41 -0
- data/examples/pingpong/serial.rb +26 -0
- data/examples/pretty.txt +108 -0
- data/examples/telephone/.irbrc +2 -0
- data/examples/telephone/3esl.txt +21877 -0
- data/examples/telephone/fifth/kid.rb +36 -0
- data/examples/telephone/fifth/run.rb +26 -0
- data/examples/telephone/first/kid.rb +31 -0
- data/examples/telephone/first/run.rb +20 -0
- data/examples/telephone/fourth/kid.rb +31 -0
- data/examples/telephone/fourth/run.rb +26 -0
- data/examples/telephone/mangler.rb +53 -0
- data/examples/telephone/second/kid.rb +26 -0
- data/examples/telephone/second/run.rb +20 -0
- data/examples/telephone/seventh/kid.rb +40 -0
- data/examples/telephone/seventh/run.rb +35 -0
- data/examples/telephone/seventh/test.rb +28 -0
- data/examples/telephone/seventh/test2.rb +10 -0
- data/examples/telephone/sixth/kid.rb +39 -0
- data/examples/telephone/sixth/run.rb +26 -0
- data/examples/telephone/third/kid.rb +31 -0
- data/examples/telephone/third/run.rb +21 -0
- data/lib/dramatis/actor/interface.rb +118 -0
- data/lib/dramatis/actor/name/interface.rb +128 -0
- data/lib/dramatis/actor/name.rb +44 -0
- data/lib/dramatis/actor.rb +96 -0
- data/lib/dramatis/deadlock.rb +123 -0
- data/lib/dramatis/error/uncaught.rb +19 -0
- data/lib/dramatis/error.rb +125 -0
- data/lib/dramatis/future/interface.rb +45 -0
- data/lib/dramatis/future.rb +32 -0
- data/lib/dramatis/runtime/actor/main.rb +3 -0
- data/lib/dramatis/runtime/actor.rb +294 -0
- data/lib/dramatis/runtime/gate.rb +244 -0
- data/lib/dramatis/runtime/scheduler.rb +374 -0
- data/lib/dramatis/runtime/task.rb +390 -0
- data/lib/dramatis/runtime/thread_pool.rb +149 -0
- data/lib/dramatis/runtime/timer.rb +5 -0
- data/lib/dramatis/runtime.rb +129 -0
- data/lib/dramatis/shoes/runtime.rb +7 -0
- data/lib/dramatis/shoes.rb +14 -0
- data/lib/dramatis/version.rb +8 -0
- data/lib/dramatis.rb +73 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/dramatis/actor/become_spec.rb +17 -0
- data/spec/dramatis/actor/future_spec.rb +189 -0
- data/spec/dramatis/actor/name_spec.rb +141 -0
- data/spec/dramatis/actor/task_spec.rb +75 -0
- data/spec/dramatis/actor_spec.rb +492 -0
- data/spec/dramatis/dramatis_spec.rb +23 -0
- data/spec/dramatis/exc_spec.rb +78 -0
- data/spec/dramatis/runtime/gate_spec.rb +57 -0
- data/spec/dramatis/runtime/thread_pool.rb +30 -0
- data/spec/dramatis/shoes_spec.rb +11 -0
- data/spec/dramatis/simple_spec.rb +32 -0
- data/spec/exp_spec.rb +21 -0
- data/spec/simple2_spec.rb +36 -0
- data/spec/simple_spec.rb +30 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/thread_spec.rb +13 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/test/jruby_lm.rb +13 -0
- data/test/test.rb +19 -0
- data/test/test10.rb +43 -0
- data/test/test11.rb +45 -0
- data/test/test12.rb +60 -0
- data/test/test13.rb +71 -0
- data/test/test2.rb +12 -0
- data/test/test3.rb +10 -0
- data/test/test4.rb +29 -0
- data/test/test5.rb +8 -0
- data/test/test6.rb +32 -0
- data/test/test7.rb +48 -0
- data/test/test8.rb +133 -0
- data/test/test9.rb +105 -0
- data/test/test_exc.rb +22 -0
- metadata +180 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
require 'dramatis/actor/name'
|
|
3
|
+
|
|
4
|
+
require 'mangler'
|
|
5
|
+
|
|
6
|
+
class Kid
|
|
7
|
+
|
|
8
|
+
include Dramatis::Actor
|
|
9
|
+
|
|
10
|
+
def initialize name, next_kid = nil
|
|
11
|
+
@name = name
|
|
12
|
+
@next = next_kid
|
|
13
|
+
@heard = "I ain't heard nuthin"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
@name
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def whisper what
|
|
21
|
+
@heard = mangle what
|
|
22
|
+
# puts "#{self} heard #{@heard}"
|
|
23
|
+
if @next
|
|
24
|
+
release( @next ).whisper @heard
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def ask
|
|
29
|
+
@heard
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def mangle what
|
|
33
|
+
Mangler.mangle what
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
4
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
5
|
+
|
|
6
|
+
require 'kid'
|
|
7
|
+
|
|
8
|
+
tom = Kid.new "Tom"
|
|
9
|
+
becky = Kid.new "Becky", tom
|
|
10
|
+
dick = Kid.new "Dick", becky
|
|
11
|
+
jane = Kid.new "Jane", dick
|
|
12
|
+
harry = Kid.new "Harry", jane
|
|
13
|
+
sally = Kid.new "Sally", harry
|
|
14
|
+
|
|
15
|
+
phrases = [ "his mom locked her keys in the car, " +
|
|
16
|
+
"so he should get a ride home with Hector",
|
|
17
|
+
"Mac King is a comedy magic genius" ]
|
|
18
|
+
|
|
19
|
+
phrases.each do |phrase|
|
|
20
|
+
puts "Teacher: #{phrase}"
|
|
21
|
+
sally.whisper phrase
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
phrases.length.times do
|
|
25
|
+
puts "Teacher heard: '#{tom.ask}'"
|
|
26
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
|
|
3
|
+
require 'mangler'
|
|
4
|
+
|
|
5
|
+
class Kid
|
|
6
|
+
|
|
7
|
+
include Dramatis::Actor
|
|
8
|
+
|
|
9
|
+
def initialize name, next_kid = nil
|
|
10
|
+
@name = name
|
|
11
|
+
@next = next_kid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
@name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def whisper what
|
|
19
|
+
what = mangle what
|
|
20
|
+
if @next
|
|
21
|
+
@next.whisper what
|
|
22
|
+
else
|
|
23
|
+
puts "#{@name}: #{what}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def mangle what
|
|
28
|
+
Mangler.mangle what
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
4
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
5
|
+
|
|
6
|
+
require 'kid'
|
|
7
|
+
|
|
8
|
+
tom = Kid.new "Tom"
|
|
9
|
+
becky = Kid.new "Becky", tom
|
|
10
|
+
dick = Kid.new "Dick", becky
|
|
11
|
+
jane = Kid.new "Jane", dick
|
|
12
|
+
harry = Kid.new "Harry", jane
|
|
13
|
+
sally = Kid.new "Sally", harry
|
|
14
|
+
|
|
15
|
+
phrase = "his mom locked her keys in the car, " +
|
|
16
|
+
"so he should get a ride home with Hector"
|
|
17
|
+
|
|
18
|
+
puts "Teacher: #{phrase}"
|
|
19
|
+
sally.whisper phrase
|
|
20
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
|
|
3
|
+
require 'mangler'
|
|
4
|
+
|
|
5
|
+
class Kid
|
|
6
|
+
|
|
7
|
+
include Dramatis::Actor
|
|
8
|
+
|
|
9
|
+
def initialize name, next_kid = nil
|
|
10
|
+
@name = name
|
|
11
|
+
@next = next_kid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
@name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def whisper what
|
|
19
|
+
@heard = mangle what
|
|
20
|
+
@next and @next.whisper @heard
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def ask
|
|
24
|
+
@heard
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def mangle what
|
|
28
|
+
Mangler.mangle what
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
4
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
5
|
+
|
|
6
|
+
require 'kid'
|
|
7
|
+
|
|
8
|
+
tom = Kid.new "Tom"
|
|
9
|
+
becky = Kid.new "Becky", tom
|
|
10
|
+
dick = Kid.new "Dick", becky
|
|
11
|
+
jane = Kid.new "Jane", dick
|
|
12
|
+
harry = Kid.new "Harry", jane
|
|
13
|
+
sally = Kid.new "Sally", harry
|
|
14
|
+
|
|
15
|
+
phrases = [ "his mom locked her keys in the car, " +
|
|
16
|
+
"so he should get a ride home with Hector",
|
|
17
|
+
"Mac King is a comedy magic genius" ]
|
|
18
|
+
|
|
19
|
+
phrases.each do |phrase|
|
|
20
|
+
puts "Teacher: #{phrase}"
|
|
21
|
+
sally.whisper phrase
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
phrases.length.times do
|
|
25
|
+
puts "Teacher heard: #{tom.ask}"
|
|
26
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'pp'
|
|
2
|
+
|
|
3
|
+
class Mangler
|
|
4
|
+
|
|
5
|
+
def self.mangle_word what
|
|
6
|
+
patterns = [ what, what+"." ]
|
|
7
|
+
index = 0
|
|
8
|
+
(what.length).times do
|
|
9
|
+
|
|
10
|
+
# delete a character
|
|
11
|
+
if what.length > 3
|
|
12
|
+
mod = what.clone
|
|
13
|
+
mod[index] = ""
|
|
14
|
+
patterns << mod
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# insert a character
|
|
18
|
+
mod = what.clone
|
|
19
|
+
mod[index,0] = "."
|
|
20
|
+
patterns << mod
|
|
21
|
+
|
|
22
|
+
#change a character (biased towards making words longer)
|
|
23
|
+
if what.length > 3
|
|
24
|
+
mod = what.clone
|
|
25
|
+
mod[index] = "."
|
|
26
|
+
patterns << mod
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
index += 1
|
|
30
|
+
end
|
|
31
|
+
patterns = "^((" + patterns.join( ")|(" ) + "))$"
|
|
32
|
+
# pp patterns
|
|
33
|
+
matches = words.grep Regexp.new( patterns, Regexp::IGNORECASE )
|
|
34
|
+
# pp matches
|
|
35
|
+
matches[rand( matches.length )]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.mangle words
|
|
39
|
+
words.split.map { |word| mangle_word word }.join(" ")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def self.words
|
|
45
|
+
@words ||=
|
|
46
|
+
begin
|
|
47
|
+
lines = IO.readlines File.join( File.dirname(__FILE__), "3esl.txt")
|
|
48
|
+
lines.each { |line| line.chomp! }
|
|
49
|
+
lines
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
|
|
3
|
+
require 'mangler'
|
|
4
|
+
|
|
5
|
+
class Kid
|
|
6
|
+
|
|
7
|
+
include Dramatis::Actor
|
|
8
|
+
|
|
9
|
+
def initialize name, next_kid = nil
|
|
10
|
+
@name = name
|
|
11
|
+
@next = next_kid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
@name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def whisper what
|
|
19
|
+
mangle( @next.nil? && @next.whisper( mangle( what ) ) || what )
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def mangle what
|
|
23
|
+
Mangler.mangle what
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
4
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
5
|
+
|
|
6
|
+
require 'kid'
|
|
7
|
+
|
|
8
|
+
tom = Kid.new "Tom"
|
|
9
|
+
becky = Kid.new "Becky", tom
|
|
10
|
+
dick = Kid.new "Dick", becky
|
|
11
|
+
jane = Kid.new "Jane", dick
|
|
12
|
+
harry = Kid.new "Harry", jane
|
|
13
|
+
sally = Kid.new "Sally", harry
|
|
14
|
+
|
|
15
|
+
phrase = "his mom locked her keys in the car, " +
|
|
16
|
+
"so he should get a ride home with Hector"
|
|
17
|
+
|
|
18
|
+
puts "Teacher: #{phrase}"
|
|
19
|
+
heard = sally.whisper phrase
|
|
20
|
+
puts "Teacher heard: #{heard}"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
require 'dramatis/actor/name'
|
|
3
|
+
|
|
4
|
+
require 'mangler'
|
|
5
|
+
|
|
6
|
+
class Kid
|
|
7
|
+
|
|
8
|
+
include Dramatis::Actor
|
|
9
|
+
|
|
10
|
+
def initialize name, next_kid = nil
|
|
11
|
+
@name = name
|
|
12
|
+
@next = next_kid
|
|
13
|
+
@heard = "I ain't heard nuthin"
|
|
14
|
+
actor.refuse :ask
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_s
|
|
18
|
+
@name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def whisper what
|
|
22
|
+
@heard = mangle what
|
|
23
|
+
if @next
|
|
24
|
+
release( @next ).whisper @heard
|
|
25
|
+
end
|
|
26
|
+
actor.accept :ask
|
|
27
|
+
actor.refuse :whisper
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ask
|
|
31
|
+
actor.refuse :ask
|
|
32
|
+
actor.accept :whisper
|
|
33
|
+
@heard
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def mangle what
|
|
37
|
+
Mangler.mangle what
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# THIS EXAMPLE ISN'T COMPLETE OR WORKING
|
|
4
|
+
|
|
5
|
+
# it deadlocks (don't remember)
|
|
6
|
+
# self for main isn't getting mapped into an actor name correctly
|
|
7
|
+
|
|
8
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
9
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
10
|
+
|
|
11
|
+
require 'kid'
|
|
12
|
+
|
|
13
|
+
tom = Kid.new "Tom", self
|
|
14
|
+
becky = Kid.new "Becky", tom
|
|
15
|
+
dick = Kid.new "Dick", becky
|
|
16
|
+
jane = Kid.new "Jane", dick
|
|
17
|
+
harry = Kid.new "Harry", jane
|
|
18
|
+
sally = Kid.new "Sally", harry
|
|
19
|
+
|
|
20
|
+
phrases = [ "his mom locked her keys in the car, " +
|
|
21
|
+
"so he should get a ride home with Hector",
|
|
22
|
+
"Mac King is a comedy magic genius" ]
|
|
23
|
+
|
|
24
|
+
phrases.each do |phrase|
|
|
25
|
+
puts "Teacher: #{phrase}"
|
|
26
|
+
begin
|
|
27
|
+
sally.whisper phrase
|
|
28
|
+
rescue Dramatis::Deadlock
|
|
29
|
+
warn "woah: got a deadlock: that shouln't happen"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
phrases.length.times do
|
|
34
|
+
puts "Teacher heard: '#{tom.ask}'"
|
|
35
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
smp = 10
|
|
2
|
+
o = Object.new
|
|
3
|
+
block = lambda { p smp; p "hi"; p self }
|
|
4
|
+
p "o", o.class
|
|
5
|
+
o.instance_eval do
|
|
6
|
+
class << self
|
|
7
|
+
@__bif__ = "foo"
|
|
8
|
+
end
|
|
9
|
+
# p @@__bif__ = "bif"
|
|
10
|
+
p self.class_eval { @__bif__ }
|
|
11
|
+
class << self
|
|
12
|
+
p @__bif__
|
|
13
|
+
p "<<", self
|
|
14
|
+
def ____frob____
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
p "o", o.class
|
|
19
|
+
o.class.send :define_method, :bar, &block
|
|
20
|
+
o.instance_eval do
|
|
21
|
+
def foo
|
|
22
|
+
bar
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
o.foo
|
|
27
|
+
o.instance_eval { bar }
|
|
28
|
+
Object.new.instance_eval { bar; p @__bif__ }
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
require 'dramatis/actor/name'
|
|
3
|
+
|
|
4
|
+
require 'mangler'
|
|
5
|
+
|
|
6
|
+
class Kid
|
|
7
|
+
|
|
8
|
+
include Dramatis::Actor
|
|
9
|
+
|
|
10
|
+
def initialize name, next_kid = nil
|
|
11
|
+
@name = name
|
|
12
|
+
@next = next_kid
|
|
13
|
+
@heard = "I ain't heard nuthin"
|
|
14
|
+
actor.refuse :ask
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_s
|
|
18
|
+
@name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def whisper what
|
|
22
|
+
@heard = mangle what
|
|
23
|
+
# puts "#{self} heard #{@heard}"
|
|
24
|
+
if @next
|
|
25
|
+
release( @next ).whisper @heard
|
|
26
|
+
end
|
|
27
|
+
actor.accept :ask
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ask
|
|
31
|
+
actor.refuse :ask
|
|
32
|
+
@heard
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def mangle what
|
|
36
|
+
Mangler.mangle what
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
4
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
5
|
+
|
|
6
|
+
require 'kid'
|
|
7
|
+
|
|
8
|
+
tom = Kid.new "Tom"
|
|
9
|
+
becky = Kid.new "Becky", tom
|
|
10
|
+
dick = Kid.new "Dick", becky
|
|
11
|
+
jane = Kid.new "Jane", dick
|
|
12
|
+
harry = Kid.new "Harry", jane
|
|
13
|
+
sally = Kid.new "Sally", harry
|
|
14
|
+
|
|
15
|
+
phrases = [ "his mom locked her keys in the car, " +
|
|
16
|
+
"so he should get a ride home with Hector",
|
|
17
|
+
"Mac King is a comedy magic genius" ]
|
|
18
|
+
|
|
19
|
+
phrases.each do |phrase|
|
|
20
|
+
puts "Teacher: #{phrase}"
|
|
21
|
+
sally.whisper phrase
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
phrases.length.times do
|
|
25
|
+
puts "Teacher heard: '#{tom.ask}'"
|
|
26
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'dramatis/actor'
|
|
2
|
+
|
|
3
|
+
require 'mangler'
|
|
4
|
+
|
|
5
|
+
class Kid
|
|
6
|
+
|
|
7
|
+
include Dramatis::Actor
|
|
8
|
+
|
|
9
|
+
def initialize name, next_kid = nil
|
|
10
|
+
@name = name
|
|
11
|
+
@next = next_kid
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_s
|
|
15
|
+
@name
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def whisper what
|
|
19
|
+
@heard = mangle what
|
|
20
|
+
@next and @next.whisper @heard
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def ask
|
|
24
|
+
@heard
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def mangle what
|
|
28
|
+
Mangler.mangle what
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "..", "lib" )
|
|
4
|
+
$:.push File.join( File.dirname(__FILE__), ".." )
|
|
5
|
+
|
|
6
|
+
require 'kid'
|
|
7
|
+
|
|
8
|
+
tom = Kid.new "Tom"
|
|
9
|
+
becky = Kid.new "Becky", tom
|
|
10
|
+
dick = Kid.new "Dick", becky
|
|
11
|
+
jane = Kid.new "Jane", dick
|
|
12
|
+
harry = Kid.new "Harry", jane
|
|
13
|
+
sally = Kid.new "Sally", harry
|
|
14
|
+
|
|
15
|
+
phrase = "his mom locked her keys in the car, " +
|
|
16
|
+
"so he should get a ride home with Hector"
|
|
17
|
+
|
|
18
|
+
puts "Teacher: #{phrase}"
|
|
19
|
+
sally.whisper phrase
|
|
20
|
+
heard = tom.ask
|
|
21
|
+
puts "Teacher heard: #{heard}"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
module Dramatis; end
|
|
2
|
+
module Dramatis::Actor; end
|
|
3
|
+
|
|
4
|
+
# A Dramatis::Actor::Interface object provides actors that have mixed
|
|
5
|
+
# in Dramatis::Actor with access to their actor name and other actor
|
|
6
|
+
# operations. An instance of Dramatis::Actor::Interface is typically accessed through
|
|
7
|
+
# Dramatis::Actor.actor.
|
|
8
|
+
|
|
9
|
+
# Many of the interface method affect the <em>gate behavior</em> of
|
|
10
|
+
# the actor, that is, whether tasks queued for the actor are allowed
|
|
11
|
+
# to execute. With functions refuse, accept, default, and always, an
|
|
12
|
+
# actor can control task scheduling.
|
|
13
|
+
|
|
14
|
+
# Most of these methods accept an array of arguments that are matched
|
|
15
|
+
# against each method by the runtime when determining whether a task
|
|
16
|
+
# can be scheduled.
|
|
17
|
+
|
|
18
|
+
# Each element in the array is tested, via ====, against the method
|
|
19
|
+
# and arguments of the task underconsideration. If all the arguments
|
|
20
|
+
# match, the pattern matches. Extra task parameters are ignored and
|
|
21
|
+
# the match succeeds. If there are more arguments in the pattern than
|
|
22
|
+
# there are associated with the task, the match fails.
|
|
23
|
+
|
|
24
|
+
# Note that the interaction of multiple calls is a bit complex and currently
|
|
25
|
+
# not documented. See the examples and tutorials.
|
|
26
|
+
|
|
27
|
+
# This object should only be accessed from the actor it represents.
|
|
28
|
+
|
|
29
|
+
class Dramatis::Actor::Interface
|
|
30
|
+
|
|
31
|
+
# call-seq:
|
|
32
|
+
# refuse pattern_args -> nil
|
|
33
|
+
#
|
|
34
|
+
# Blocks the actor from running any tasks that match pattern_args. Note that
|
|
35
|
+
# subsequent gate calls may override this behavior.
|
|
36
|
+
|
|
37
|
+
def refuse *args
|
|
38
|
+
@actor.gate.refuse( :object, *args )
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# call-seq:
|
|
42
|
+
# accept pattern_args -> nil
|
|
43
|
+
#
|
|
44
|
+
# Enables the actor to run tasks that match pattern_args. Note that
|
|
45
|
+
# subsequent gate calls may override this behavior.
|
|
46
|
+
|
|
47
|
+
def accept *args
|
|
48
|
+
@actor.gate.accept( :object, *args )
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# call-seq:
|
|
52
|
+
# default pattern_args -> nil
|
|
53
|
+
#
|
|
54
|
+
# Reverts the behavior of the actor to tasks matching pattern_args
|
|
55
|
+
# to the default. It un-does the affect of a call to refuse or
|
|
56
|
+
# accept with the same arguments.
|
|
57
|
+
|
|
58
|
+
def default *args
|
|
59
|
+
@actor.gate.default( [ :object ] + args )
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# call-seq:
|
|
63
|
+
# always( pattern_args, value ) -> nil
|
|
64
|
+
#
|
|
65
|
+
# Causes tasks matching pattern_args to always be accepted if +value+
|
|
66
|
+
# is +true+ or reject if +value+ is +false+. always takes precendence over
|
|
67
|
+
# refuse/accept so a task that matches both a refuse pattern and an
|
|
68
|
+
# always( ..., true ) pattern will be allowed. always also overrides
|
|
69
|
+
# the implict gating in rpc method calls.
|
|
70
|
+
|
|
71
|
+
def always args, value
|
|
72
|
+
@actor.gate.always( ( [ :object ] + Array( args ) ), value )
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Enables call threading for actor method calls made by this
|
|
76
|
+
# actor. When call threading is enabled, method gating is modified
|
|
77
|
+
# such that recursive and co-recursive calls are allowed. Normally
|
|
78
|
+
# blocking calls made by an actor on itself, e.g.,
|
|
79
|
+
# actor.name.some_method
|
|
80
|
+
# would cause a deadlock. When call threading is enabled, recursion, both self-recursion
|
|
81
|
+
# and co-recursion (actor A does an rpc on actor B which does an rpc on actor A), is allowed.
|
|
82
|
+
|
|
83
|
+
def enable_call_threading
|
|
84
|
+
@actor.enable_call_threading
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Returns the actor name for the object.
|
|
88
|
+
|
|
89
|
+
def name
|
|
90
|
+
@actor.name
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Yields the actor to allow other tasks to be executed.
|
|
94
|
+
# Currently, messages are handled FIFO so the yield will
|
|
95
|
+
# return when all the messages received up to the point of the
|
|
96
|
+
# yield are executed. This could be modified if non-FIFO queue
|
|
97
|
+
# processing is added
|
|
98
|
+
|
|
99
|
+
def yield
|
|
100
|
+
@actor.actor_send [ :yield ], :continuation => :rpc,
|
|
101
|
+
:nonblocking => true
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def timeout value, *args #:nodoc: not ready
|
|
105
|
+
@actor.timeout value, *args
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
private
|
|
109
|
+
|
|
110
|
+
def gate
|
|
111
|
+
@actor.gate
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def initialize actor #:nodoc:
|
|
115
|
+
@actor = actor
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|