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
data/History.txt
ADDED
data/License.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Steven Parkes
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
History.txt
|
|
2
|
+
License.txt
|
|
3
|
+
Manifest.txt
|
|
4
|
+
README.txt
|
|
5
|
+
Rakefile
|
|
6
|
+
config/hoe.rb
|
|
7
|
+
config/requirements.rb
|
|
8
|
+
examples/README.txt
|
|
9
|
+
examples/auction.rb
|
|
10
|
+
examples/bank/bank.rb
|
|
11
|
+
examples/bank/bank_test.rb
|
|
12
|
+
examples/exception.rb
|
|
13
|
+
examples/fib/conservative.rb
|
|
14
|
+
examples/fib/future.rb
|
|
15
|
+
examples/fib/original.rb
|
|
16
|
+
examples/fib/threads.rb
|
|
17
|
+
examples/im/distributed/chat.rb
|
|
18
|
+
examples/im/distributed/chat/client.rb
|
|
19
|
+
examples/im/distributed/chat/screen.rb
|
|
20
|
+
examples/im/distributed/chat/screen/fox.rb
|
|
21
|
+
examples/im/distributed/chat/server.rb
|
|
22
|
+
examples/im/distributed/client.rb
|
|
23
|
+
examples/im/distributed/run.rb
|
|
24
|
+
examples/im/distributed/server.rb
|
|
25
|
+
examples/im/single/chat.rb
|
|
26
|
+
examples/im/single/chat/client.rb
|
|
27
|
+
examples/im/single/chat/screen.rb
|
|
28
|
+
examples/im/single/chat/screen/fox.rb
|
|
29
|
+
examples/im/single/chat/screen/wxs.rb
|
|
30
|
+
examples/im/single/chat/server.rb
|
|
31
|
+
examples/im/single/fox.rb
|
|
32
|
+
examples/im/single/wxchat.rb
|
|
33
|
+
examples/pingpong/actor.rb
|
|
34
|
+
examples/pingpong/actor_rec.rb
|
|
35
|
+
examples/pingpong/pingpong.txt
|
|
36
|
+
examples/pingpong/scala.rb
|
|
37
|
+
examples/pingpong/serial.rb
|
|
38
|
+
examples/pretty.txt
|
|
39
|
+
examples/telephone/.irbrc
|
|
40
|
+
examples/telephone/3esl.txt
|
|
41
|
+
examples/telephone/fifth/kid.rb
|
|
42
|
+
examples/telephone/fifth/run.rb
|
|
43
|
+
examples/telephone/first/kid.rb
|
|
44
|
+
examples/telephone/first/run.rb
|
|
45
|
+
examples/telephone/fourth/kid.rb
|
|
46
|
+
examples/telephone/fourth/run.rb
|
|
47
|
+
examples/telephone/mangler.rb
|
|
48
|
+
examples/telephone/second/kid.rb
|
|
49
|
+
examples/telephone/second/run.rb
|
|
50
|
+
examples/telephone/seventh/kid.rb
|
|
51
|
+
examples/telephone/seventh/run.rb
|
|
52
|
+
examples/telephone/seventh/test.rb
|
|
53
|
+
examples/telephone/seventh/test2.rb
|
|
54
|
+
examples/telephone/sixth/kid.rb
|
|
55
|
+
examples/telephone/sixth/run.rb
|
|
56
|
+
examples/telephone/third/kid.rb
|
|
57
|
+
examples/telephone/third/run.rb
|
|
58
|
+
lib/dramatis.rb
|
|
59
|
+
lib/dramatis/actor.rb
|
|
60
|
+
lib/dramatis/actor/interface.rb
|
|
61
|
+
lib/dramatis/actor/name.rb
|
|
62
|
+
lib/dramatis/actor/name/interface.rb
|
|
63
|
+
lib/dramatis/deadlock.rb
|
|
64
|
+
lib/dramatis/error.rb
|
|
65
|
+
lib/dramatis/error/uncaught.rb
|
|
66
|
+
lib/dramatis/future.rb
|
|
67
|
+
lib/dramatis/future/interface.rb
|
|
68
|
+
lib/dramatis/runtime.rb
|
|
69
|
+
lib/dramatis/runtime/actor.rb
|
|
70
|
+
lib/dramatis/runtime/actor/main.rb
|
|
71
|
+
lib/dramatis/runtime/gate.rb
|
|
72
|
+
lib/dramatis/runtime/scheduler.rb
|
|
73
|
+
lib/dramatis/runtime/task.rb
|
|
74
|
+
lib/dramatis/runtime/thread_pool.rb
|
|
75
|
+
lib/dramatis/runtime/timer.rb
|
|
76
|
+
lib/dramatis/shoes.rb
|
|
77
|
+
lib/dramatis/shoes/runtime.rb
|
|
78
|
+
lib/dramatis/version.rb
|
|
79
|
+
log/debug.log
|
|
80
|
+
script/destroy
|
|
81
|
+
script/generate
|
|
82
|
+
script/txt2html
|
|
83
|
+
setup.rb
|
|
84
|
+
spec/dramatis/actor/become_spec.rb
|
|
85
|
+
spec/dramatis/actor/future_spec.rb
|
|
86
|
+
spec/dramatis/actor/name_spec.rb
|
|
87
|
+
spec/dramatis/actor/task_spec.rb
|
|
88
|
+
spec/dramatis/actor_spec.rb
|
|
89
|
+
spec/dramatis/dramatis_spec.rb
|
|
90
|
+
spec/dramatis/exc_spec.rb
|
|
91
|
+
spec/dramatis/runtime/gate_spec.rb
|
|
92
|
+
spec/dramatis/runtime/thread_pool.rb
|
|
93
|
+
spec/dramatis/shoes_spec.rb
|
|
94
|
+
spec/dramatis/simple_spec.rb
|
|
95
|
+
spec/exp_spec.rb
|
|
96
|
+
spec/simple2_spec.rb
|
|
97
|
+
spec/simple_spec.rb
|
|
98
|
+
spec/spec.opts
|
|
99
|
+
spec/spec_helper.rb
|
|
100
|
+
spec/thread_spec.rb
|
|
101
|
+
tasks/deployment.rake
|
|
102
|
+
tasks/environment.rake
|
|
103
|
+
tasks/rspec.rake
|
|
104
|
+
tasks/website.rake
|
|
105
|
+
test/jruby_lm.rb
|
|
106
|
+
test/test.rb
|
|
107
|
+
test/test10.rb
|
|
108
|
+
test/test11.rb
|
|
109
|
+
test/test12.rb
|
|
110
|
+
test/test13.rb
|
|
111
|
+
test/test2.rb
|
|
112
|
+
test/test3.rb
|
|
113
|
+
test/test4.rb
|
|
114
|
+
test/test5.rb
|
|
115
|
+
test/test6.rb
|
|
116
|
+
test/test7.rb
|
|
117
|
+
test/test8.rb
|
|
118
|
+
test/test9.rb
|
|
119
|
+
test/test_exc.rb
|
data/README.txt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
= dramatis
|
|
2
|
+
|
|
3
|
+
* http://dramatis.mischance.net
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
An actor library for dynamic languages like Ruby and Python.
|
|
8
|
+
|
|
9
|
+
== FEATURES/PROBLEMS:
|
|
10
|
+
|
|
11
|
+
dramatis provides a library for writing concurrent programs using the actor programming model.
|
|
12
|
+
|
|
13
|
+
This is an early version, the first release with packaging (a gem for ruby, setuptools for python).
|
|
14
|
+
|
|
15
|
+
It's available on github to download and does come with documentation, a tutorial, and several examples, all of which (mostly) work, so it's stable enough to being to play with.
|
|
16
|
+
|
|
17
|
+
repository::
|
|
18
|
+
git://github.com/dramatis/dramatis.git
|
|
19
|
+
Mailing list::
|
|
20
|
+
dramatis@googlegroups.com /
|
|
21
|
+
http://groups.google.com/group/dramatis
|
|
22
|
+
IRC:: #dramatis @ freenode
|
|
23
|
+
Website/Wiki/tracker:: http://dramatis.mischance.net
|
|
24
|
+
|
|
25
|
+
== SYNOPSIS:
|
|
26
|
+
== REQUIREMENTS:
|
|
27
|
+
|
|
28
|
+
All the specs run on Ruby 1.8.6, 1.9, and JRuby 1.1 on Linux and OS X.
|
|
29
|
+
All the tests rus on Python 2.5 on Linux.
|
|
30
|
+
|
|
31
|
+
At least one small example runs on rubinius but the whole spec suite has not been attempted.
|
|
32
|
+
|
|
33
|
+
== INSTALL:
|
|
34
|
+
== LICENSE:
|
|
35
|
+
|
|
36
|
+
(The MIT License)
|
|
37
|
+
|
|
38
|
+
Copyright (c) 2008 Steven Parkes
|
|
39
|
+
|
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
41
|
+
a copy of this software and associated documentation files (the
|
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
46
|
+
the following conditions:
|
|
47
|
+
|
|
48
|
+
The above copyright notice and this permission notice shall be
|
|
49
|
+
included in all copies or substantial portions of the Software.
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'dramatis/version'
|
|
2
|
+
|
|
3
|
+
AUTHOR = 'Steven Parkes' # can also be an array of Authors
|
|
4
|
+
EMAIL = "smparkes@smparkes.net"
|
|
5
|
+
DESCRIPTION = "an Actor library for Ruby and Python"
|
|
6
|
+
GEM_NAME = 'dramatis' # what ppl will type to install your gem
|
|
7
|
+
RUBYFORGE_PROJECT = 'dramatis' # The unix name for your project
|
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
10
|
+
|
|
11
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
|
12
|
+
@config = nil
|
|
13
|
+
RUBYFORGE_USERNAME = "unknown"
|
|
14
|
+
def rubyforge_username
|
|
15
|
+
unless @config
|
|
16
|
+
begin
|
|
17
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
|
18
|
+
rescue
|
|
19
|
+
puts <<-EOS
|
|
20
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
|
21
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
22
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
|
23
|
+
EOS
|
|
24
|
+
exit
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
REV = nil
|
|
32
|
+
# UNCOMMENT IF REQUIRED:
|
|
33
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
|
34
|
+
VERS = Dramatis::VERSION::STRING + (REV ? ".#{REV}" : "")
|
|
35
|
+
RDOC_OPTS = ['--quiet', '--title', 'dramatis documentation',
|
|
36
|
+
"--opname", "index.html",
|
|
37
|
+
"--line-numbers",
|
|
38
|
+
"--main", "README",
|
|
39
|
+
"--inline-source"]
|
|
40
|
+
|
|
41
|
+
class Hoe
|
|
42
|
+
def extra_deps
|
|
43
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
|
44
|
+
@extra_deps
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Generate all the Rake tasks
|
|
49
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
|
50
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
51
|
+
p.developer(AUTHOR, EMAIL)
|
|
52
|
+
p.description = DESCRIPTION
|
|
53
|
+
p.summary = DESCRIPTION
|
|
54
|
+
p.url = HOMEPATH
|
|
55
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
|
56
|
+
p.test_globs = ["test/**/test_*.rb"]
|
|
57
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
|
58
|
+
|
|
59
|
+
# == Optional
|
|
60
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
|
61
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
|
62
|
+
|
|
63
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
|
68
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
|
69
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
|
70
|
+
hoe.rsync_args = '-av --delete --ignore-errors'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
include FileUtils
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
|
6
|
+
begin
|
|
7
|
+
require req_gem
|
|
8
|
+
rescue LoadError
|
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
|
11
|
+
exit
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
|
16
|
+
|
|
17
|
+
require 'dramatis'
|
data/examples/README.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
pingpong: working and complete
|
|
2
|
+
|
|
3
|
+
auction: working but doesn't have the timeout, end of auction stuff
|
|
4
|
+
|
|
5
|
+
bank: incomplete
|
|
6
|
+
|
|
7
|
+
telephone: versions first through sixth are complete and working
|
|
8
|
+
seventh is incomplete/not-working
|
|
9
|
+
|
|
10
|
+
im: single/fox: working
|
|
11
|
+
single/wx: working but incomplete
|
|
12
|
+
distributed: very incomplete
|
|
13
|
+
|
|
14
|
+
fib: a fib computation after Doug Lea's Fork/Join framework The goal
|
|
15
|
+
of this is to show speedup on jruby, which has real
|
|
16
|
+
concurrency. Right now, this is flakey. First, it doesn't bound
|
|
17
|
+
concurrency (Doug's whole point) which gets out of control in the
|
|
18
|
+
original version. The conservative version does weird things for
|
|
19
|
+
me on linux. But so does the pure thread version (though the
|
|
20
|
+
dramatis version is weirder than the thread version).
|
data/examples/auction.rb
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# cf. Scala by Example, Chapter 3
|
|
4
|
+
|
|
5
|
+
$:.push File.join( File.dirname(__FILE__), "..", "lib" )
|
|
6
|
+
|
|
7
|
+
require 'dramatis/actor'
|
|
8
|
+
|
|
9
|
+
class Auction
|
|
10
|
+
include Dramatis::Actor
|
|
11
|
+
def initialize seller, min_bid, closing
|
|
12
|
+
@seller = seller
|
|
13
|
+
@min_bid = min_bid
|
|
14
|
+
@closing = closing
|
|
15
|
+
|
|
16
|
+
@time_to_shutdown = 3000
|
|
17
|
+
@bid_increment = 10
|
|
18
|
+
@max_bid = @min_bid - @bid_increment
|
|
19
|
+
@max_bidder = nil
|
|
20
|
+
|
|
21
|
+
actor.timeout @closing - Time::now, :timeout
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def inquire
|
|
25
|
+
[ @max_bid, @closing ]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def offer bid, bidder
|
|
29
|
+
if bid >= @max_bid + @bid_increment
|
|
30
|
+
if @max_bid >= @min_bid
|
|
31
|
+
release( @max_bidder ).beaten_offer bid
|
|
32
|
+
end
|
|
33
|
+
@max_bid = bid
|
|
34
|
+
@max_bidder = bidder
|
|
35
|
+
:best_offer
|
|
36
|
+
else
|
|
37
|
+
[ :beaten_offer, @max_bid ]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def timeout
|
|
42
|
+
actor.timeout( @time_to_shtudown ) { exit }
|
|
43
|
+
actor.become Over.new
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
MIN_BID = 100
|
|
48
|
+
CLOSING = Time::now + 4
|
|
49
|
+
|
|
50
|
+
seller = Dramatis::Actor.new Object.new
|
|
51
|
+
auction = Auction.new seller, MIN_BID, CLOSING
|
|
52
|
+
|
|
53
|
+
class Client
|
|
54
|
+
include Dramatis::Actor
|
|
55
|
+
def initialize id, increment, top, auction
|
|
56
|
+
@id = id
|
|
57
|
+
@increment = increment
|
|
58
|
+
@top = top
|
|
59
|
+
@auction = auction
|
|
60
|
+
@current = 0
|
|
61
|
+
log "started"
|
|
62
|
+
@max = auction.inquire[0]
|
|
63
|
+
log "status #{@max}"
|
|
64
|
+
bid
|
|
65
|
+
end
|
|
66
|
+
def bid
|
|
67
|
+
if @max > @top
|
|
68
|
+
log("too high for me")
|
|
69
|
+
elsif ( @current < @max )
|
|
70
|
+
@current = @max + @increment
|
|
71
|
+
sleep( ( 1 + rand( 1000 ) )/1000.0 )
|
|
72
|
+
answer, max_bid = @auction.offer @current, actor.name
|
|
73
|
+
case answer
|
|
74
|
+
when :best_offer; log("best offer: #{@current}")
|
|
75
|
+
when :beaten_offer; beaten_offer max_bid
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
def beaten_offer max_bid
|
|
80
|
+
log("beaten offer: #{max_bid}")
|
|
81
|
+
@max = max_bid
|
|
82
|
+
release( actor.name ).bid
|
|
83
|
+
end
|
|
84
|
+
def log string
|
|
85
|
+
puts "client #{@id}: #{string}"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
Client.new 1, 20, 200, auction
|
|
90
|
+
Client.new 2, 10, 300, auction
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.push File.join( File.dirname(__FILE__), "..", "lib" )
|
|
4
|
+
|
|
5
|
+
require 'dramatis/actor'
|
|
6
|
+
|
|
7
|
+
$serial = false
|
|
8
|
+
|
|
9
|
+
if ARGV[0] == "serial"
|
|
10
|
+
$serial = true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Foo
|
|
14
|
+
if !$serial
|
|
15
|
+
include Dramatis::Actor
|
|
16
|
+
end
|
|
17
|
+
def foo that
|
|
18
|
+
return that.bar -3
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Bar
|
|
23
|
+
if !$serial
|
|
24
|
+
include Dramatis::Actor
|
|
25
|
+
end
|
|
26
|
+
def bar value
|
|
27
|
+
fooobar
|
|
28
|
+
end
|
|
29
|
+
def foobar
|
|
30
|
+
"foobar"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Foo.new
|
|
35
|
+
begin
|
|
36
|
+
Foo.new.foo Bar.new
|
|
37
|
+
rescue NameError => ne
|
|
38
|
+
puts "hey, I got a #{ne}"
|
|
39
|
+
puts "it happened here: " + ne.backtrace.join("\n")
|
|
40
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# cf. http://gee.cs.oswego.edu/dl/papers/fj.pdf
|
|
4
|
+
|
|
5
|
+
# This variant doesn't produce as many threads and thus stresses
|
|
6
|
+
# the thread system less.
|
|
7
|
+
|
|
8
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "lib" )
|
|
9
|
+
|
|
10
|
+
require 'dramatis/actor'
|
|
11
|
+
|
|
12
|
+
class Fib
|
|
13
|
+
include Dramatis::Actor
|
|
14
|
+
attr_accessor :value
|
|
15
|
+
def initialize n, level = THREAD_LEVELS
|
|
16
|
+
actor.refuse :value
|
|
17
|
+
release( actor.name ).calc n, level
|
|
18
|
+
end
|
|
19
|
+
def calc n, level
|
|
20
|
+
@value = if level == 0
|
|
21
|
+
now = Time.now
|
|
22
|
+
puts "#{Thread.current} start"
|
|
23
|
+
v = sequential( n )
|
|
24
|
+
puts "#{Thread.current} sequential(#{n}) #{Time.now-now}"
|
|
25
|
+
v
|
|
26
|
+
else
|
|
27
|
+
left = Fib.new( n - 1, level - 1 )
|
|
28
|
+
right = Fib.new( n - 2, level - 1 )
|
|
29
|
+
left.value + right.value
|
|
30
|
+
end
|
|
31
|
+
actor.accept :value
|
|
32
|
+
end
|
|
33
|
+
def sequential n
|
|
34
|
+
if n <= 1
|
|
35
|
+
n
|
|
36
|
+
else
|
|
37
|
+
sequential(n-1) + sequential(n-2)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
n = begin ARGV.shift.to_i; rescue; end
|
|
43
|
+
n and n > 0 or n = 36
|
|
44
|
+
|
|
45
|
+
threads = begin ARGV.shift.to_i; rescue; end
|
|
46
|
+
threads and threads > 1 or threads = 1
|
|
47
|
+
|
|
48
|
+
THREAD_LEVELS = ( Math.log(threads)/Math.log(2) ).ceil
|
|
49
|
+
|
|
50
|
+
puts "fib(#{n}) = #{Fib.new(n).value}"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# cf. http://gee.cs.oswego.edu/dl/papers/fj.pdf
|
|
4
|
+
|
|
5
|
+
$:.push File.join( File.dirname(__FILE__), "..", "..", "lib" )
|
|
6
|
+
|
|
7
|
+
require 'dramatis/actor'
|
|
8
|
+
|
|
9
|
+
class Fib
|
|
10
|
+
include Dramatis::Actor
|
|
11
|
+
THRESHOLD = 13
|
|
12
|
+
attr_accessor :value
|
|
13
|
+
def initialize n
|
|
14
|
+
@value = if n <= THRESHOLD
|
|
15
|
+
sequential( n )
|
|
16
|
+
else
|
|
17
|
+
left = Fib.new( n - 1 )
|
|
18
|
+
right = Fib.new( n - 2 )
|
|
19
|
+
left.value + right.value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
def sequential n
|
|
23
|
+
if n <= 1
|
|
24
|
+
n
|
|
25
|
+
else
|
|
26
|
+
sequential(n-1) + sequential(n-2)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
n = 28
|
|
32
|
+
|
|
33
|
+
puts "fib(#{n}) = #{Fib.new(n).value}"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# cf. http://gee.cs.oswego.edu/dl/papers/fj.pdf
|
|
4
|
+
|
|
5
|
+
# This variant doesn't produce as many threads and thus stresses
|
|
6
|
+
# the thread system less.
|
|
7
|
+
|
|
8
|
+
class Fib
|
|
9
|
+
attr_accessor :value
|
|
10
|
+
def initialize n, level = THREAD_LEVELS
|
|
11
|
+
calc n, level
|
|
12
|
+
end
|
|
13
|
+
def calc n, level
|
|
14
|
+
@value = if level == 0
|
|
15
|
+
now = Time.now
|
|
16
|
+
puts "#{Thread.current} start"
|
|
17
|
+
v = sequential( n )
|
|
18
|
+
puts "#{Thread.current} sequential(#{n}) #{Time.now-now}"
|
|
19
|
+
v
|
|
20
|
+
else
|
|
21
|
+
if true
|
|
22
|
+
left = nil
|
|
23
|
+
left_thread = Thread.new { left = Fib.new( n - 1, level - 1 ) }
|
|
24
|
+
right = nil
|
|
25
|
+
right_thread = Thread.new { right = Fib.new( n - 2, level - 1 ) }
|
|
26
|
+
left_thread.join
|
|
27
|
+
right_thread.join
|
|
28
|
+
left.value + right.value
|
|
29
|
+
else
|
|
30
|
+
sequential( n-1 ) + sequential( n-2 )
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
def sequential n
|
|
35
|
+
if n <= 1
|
|
36
|
+
n
|
|
37
|
+
else
|
|
38
|
+
sequential(n-1) + sequential(n-2)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
n = begin ARGV.shift.to_i; rescue; end
|
|
44
|
+
n and n > 0 or n = 36
|
|
45
|
+
|
|
46
|
+
threads = begin ARGV.shift.to_i; rescue; end
|
|
47
|
+
threads and threads > 1 or threads = 1
|
|
48
|
+
|
|
49
|
+
THREAD_LEVELS = ( Math.log(threads)/Math.log(2) ).ceil
|
|
50
|
+
|
|
51
|
+
puts "fib(#{n}) = #{Fib.new(n).value}"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Chat; end
|
|
2
|
+
|
|
3
|
+
require 'dramatis/actor'
|
|
4
|
+
|
|
5
|
+
class Chat::Client
|
|
6
|
+
|
|
7
|
+
include Dramatis::Actor
|
|
8
|
+
|
|
9
|
+
def initialize screen, server, password, group, user
|
|
10
|
+
|
|
11
|
+
@user = user
|
|
12
|
+
|
|
13
|
+
@window = screen.new actor.name, :title => user, :prompt => "#{@user} > "
|
|
14
|
+
|
|
15
|
+
@window << "connecting to server ... "
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
@server = server.connect password
|
|
19
|
+
rescue Exception => e
|
|
20
|
+
@window << "\nfailed to connect to server: #{e}\n"
|
|
21
|
+
return
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
@window << "connected to server #{@server}\n"
|
|
25
|
+
|
|
26
|
+
@window << "logging in ... "
|
|
27
|
+
|
|
28
|
+
begin
|
|
29
|
+
@group = @server.login group, user, actor.name
|
|
30
|
+
@window << "done\n"
|
|
31
|
+
rescue Exception => e
|
|
32
|
+
@window << "\nlogin failed: #{e}\n"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def << opts
|
|
38
|
+
@window << "#{opts[:user]}@#{opts[:client]} #{opts[:string]}\n"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def >> string
|
|
42
|
+
@group << { :user => @user, :client => self, :string => string }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def close
|
|
46
|
+
@group.logout actor.name
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|