totty-amqp 0.6.7.1.totty

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/README +143 -0
  2. data/Rakefile +20 -0
  3. data/amqp.todo +32 -0
  4. data/doc/EXAMPLE_01_PINGPONG +2 -0
  5. data/doc/EXAMPLE_02_CLOCK +2 -0
  6. data/doc/EXAMPLE_03_STOCKS +2 -0
  7. data/doc/EXAMPLE_04_MULTICLOCK +2 -0
  8. data/doc/EXAMPLE_05_ACK +2 -0
  9. data/doc/EXAMPLE_05_POP +2 -0
  10. data/doc/EXAMPLE_06_HASHTABLE +2 -0
  11. data/examples/amqp/simple.rb +79 -0
  12. data/examples/mq/ack.rb +45 -0
  13. data/examples/mq/clock.rb +56 -0
  14. data/examples/mq/hashtable.rb +52 -0
  15. data/examples/mq/internal.rb +49 -0
  16. data/examples/mq/logger.rb +88 -0
  17. data/examples/mq/multiclock.rb +49 -0
  18. data/examples/mq/pingpong.rb +45 -0
  19. data/examples/mq/pop.rb +43 -0
  20. data/examples/mq/primes-simple.rb +19 -0
  21. data/examples/mq/primes.rb +99 -0
  22. data/examples/mq/stocks.rb +58 -0
  23. data/lib/amqp/buffer.rb +395 -0
  24. data/lib/amqp/client.rb +210 -0
  25. data/lib/amqp/frame.rb +124 -0
  26. data/lib/amqp/protocol.rb +212 -0
  27. data/lib/amqp/server.rb +99 -0
  28. data/lib/amqp/spec.rb +832 -0
  29. data/lib/amqp/version.rb +3 -0
  30. data/lib/amqp.rb +152 -0
  31. data/lib/ext/blankslate.rb +7 -0
  32. data/lib/ext/em.rb +8 -0
  33. data/lib/ext/emfork.rb +69 -0
  34. data/lib/mq/exchange.rb +314 -0
  35. data/lib/mq/header.rb +33 -0
  36. data/lib/mq/logger.rb +89 -0
  37. data/lib/mq/queue.rb +455 -0
  38. data/lib/mq/rpc.rb +100 -0
  39. data/lib/mq.rb +877 -0
  40. data/old/README +30 -0
  41. data/old/Rakefile +12 -0
  42. data/old/amqp-0.8.json +606 -0
  43. data/old/amqp_spec.rb +796 -0
  44. data/old/amqpc.rb +695 -0
  45. data/old/codegen.rb +148 -0
  46. data/protocol/amqp-0.8.json +617 -0
  47. data/protocol/amqp-0.8.xml +3908 -0
  48. data/protocol/codegen.rb +173 -0
  49. data/protocol/doc.txt +281 -0
  50. data/research/api.rb +88 -0
  51. data/research/primes-forked.rb +63 -0
  52. data/research/primes-processes.rb +135 -0
  53. data/research/primes-threaded.rb +49 -0
  54. data/totty-amqp.gemspec +87 -0
  55. metadata +142 -0
@@ -0,0 +1,135 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mq'
3
+
4
+ MAX = 500
5
+
6
+ EM.run{
7
+
8
+ def log *args
9
+ p args
10
+ end
11
+
12
+ # MQ.logging = true
13
+
14
+ if ARGV[0] == 'worker'
15
+
16
+ log "prime checker #{Process.pid}", :started
17
+
18
+ class Fixnum
19
+ def prime?
20
+ ('1' * self) !~ /^1?$|^(11+?)\1+$/
21
+ end
22
+ end
23
+
24
+ MQ.queue('prime checker').subscribe{ |info, num|
25
+ log "prime checker #{Process.pid}", :prime?, num
26
+ if Integer(num).prime?
27
+ MQ.queue(info.reply_to).publish(num, :reply_to => Process.pid)
28
+ EM.stop_event_loop if num == (MAX-1).to_s
29
+ end
30
+ }
31
+
32
+ elsif ARGV[0] == 'controller'
33
+
34
+ MQ.queue('prime collector').subscribe{ |info, prime|
35
+ log 'prime collector', :received, prime, :from, info.reply_to
36
+ (@primes ||= []) << Integer(prime)
37
+ }
38
+
39
+ MAX.times do |i|
40
+ EM.next_tick do
41
+ MQ.queue('prime checker').publish((i+1).to_s, :reply_to => 'prime collector')
42
+ end
43
+ end
44
+
45
+ else # run n workers and 1 controller as an example
46
+
47
+ workers = ARGV[0] ? (Integer(ARGV[0]) rescue 2) : 2
48
+
49
+ ([ :worker ] * workers + [ :controller ]).each do |type|
50
+ log :spawning, "`ruby #{$0} #{type}`"
51
+
52
+ EM.popen("ruby #{$0} #{type}") do |c|
53
+ def c.receive_data data
54
+ puts data
55
+ end
56
+
57
+ def c.unbind
58
+ EM.stop_event_loop
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ }
65
+
66
+ __END__
67
+
68
+ ["prime checker", :started, {:pid=>1958}]
69
+ ["prime checker", :started, {:pid=>1957}]
70
+ ["prime checker", :started, {:pid=>1956}]
71
+ ["prime checker", :prime?, "1", {:pid=>1958}]
72
+ ["prime checker", :prime?, "2", {:pid=>1957}]
73
+ ["prime collector", :received, "2", {:from_pid=>"1957"}]
74
+ ["prime checker", :prime?, "3", {:pid=>1956}]
75
+ ["prime collector", :received, "3", {:from_pid=>"1956"}]
76
+ ["prime checker", :prime?, "4", {:pid=>1958}]
77
+ ["prime checker", :prime?, "5", {:pid=>1957}]
78
+ ["prime collector", :received, "5", {:from_pid=>"1957"}]
79
+ ["prime checker", :prime?, "6", {:pid=>1956}]
80
+ ["prime checker", :prime?, "7", {:pid=>1958}]
81
+ ["prime collector", :received, "7", {:from_pid=>"1958"}]
82
+ ["prime checker", :prime?, "8", {:pid=>1957}]
83
+ ["prime checker", :prime?, "9", {:pid=>1956}]
84
+ ["prime checker", :prime?, "10", {:pid=>1958}]
85
+ ["prime checker", :prime?, "11", {:pid=>1957}]
86
+ ["prime collector", :received, "11", {:from_pid=>"1957"}]
87
+ ["prime checker", :prime?, "12", {:pid=>1956}]
88
+ ["prime checker", :prime?, "13", {:pid=>1958}]
89
+ ["prime collector", :received, "13", {:from_pid=>"1958"}]
90
+ ["prime checker", :prime?, "14", {:pid=>1957}]
91
+ ["prime checker", :prime?, "15", {:pid=>1956}]
92
+ ["prime checker", :prime?, "16", {:pid=>1958}]
93
+ ["prime checker", :prime?, "17", {:pid=>1957}]
94
+ ["prime collector", :received, "17", {:from_pid=>"1957"}]
95
+ ["prime checker", :prime?, "18", {:pid=>1956}]
96
+ ["prime checker", :prime?, "19", {:pid=>1958}]
97
+ ["prime collector", :received, "19", {:from_pid=>"1958"}]
98
+ ["prime checker", :prime?, "20", {:pid=>1957}]
99
+ ["prime checker", :prime?, "21", {:pid=>1956}]
100
+ ["prime checker", :prime?, "22", {:pid=>1958}]
101
+ ["prime checker", :prime?, "23", {:pid=>1957}]
102
+ ["prime collector", :received, "23", {:from_pid=>"1957"}]
103
+ ["prime checker", :prime?, "24", {:pid=>1956}]
104
+ ["prime checker", :prime?, "25", {:pid=>1958}]
105
+ ["prime checker", :prime?, "26", {:pid=>1957}]
106
+ ["prime checker", :prime?, "27", {:pid=>1956}]
107
+ ["prime checker", :prime?, "28", {:pid=>1958}]
108
+ ["prime checker", :prime?, "29", {:pid=>1957}]
109
+ ["prime collector", :received, "29", {:from_pid=>"1957"}]
110
+ ["prime checker", :prime?, "30", {:pid=>1956}]
111
+ ["prime checker", :prime?, "31", {:pid=>1958}]
112
+ ["prime collector", :received, "31", {:from_pid=>"1958"}]
113
+ ["prime checker", :prime?, "32", {:pid=>1957}]
114
+ ["prime checker", :prime?, "33", {:pid=>1956}]
115
+ ["prime checker", :prime?, "34", {:pid=>1958}]
116
+ ["prime checker", :prime?, "35", {:pid=>1957}]
117
+ ["prime checker", :prime?, "36", {:pid=>1956}]
118
+ ["prime checker", :prime?, "37", {:pid=>1958}]
119
+ ["prime collector", :received, "37", {:from_pid=>"1958"}]
120
+ ["prime checker", :prime?, "38", {:pid=>1957}]
121
+ ["prime checker", :prime?, "39", {:pid=>1956}]
122
+ ["prime checker", :prime?, "40", {:pid=>1958}]
123
+ ["prime checker", :prime?, "41", {:pid=>1957}]
124
+ ["prime collector", :received, "41", {:from_pid=>"1957"}]
125
+ ["prime checker", :prime?, "42", {:pid=>1956}]
126
+ ["prime checker", :prime?, "43", {:pid=>1958}]
127
+ ["prime collector", :received, "43", {:from_pid=>"1958"}]
128
+ ["prime checker", :prime?, "44", {:pid=>1957}]
129
+ ["prime checker", :prime?, "45", {:pid=>1956}]
130
+ ["prime checker", :prime?, "46", {:pid=>1958}]
131
+ ["prime checker", :prime?, "47", {:pid=>1957}]
132
+ ["prime collector", :received, "47", {:from_pid=>"1957"}]
133
+ ["prime checker", :prime?, "48", {:pid=>1956}]
134
+ ["prime checker", :prime?, "49", {:pid=>1958}]
135
+ ["prime checker", :prime?, "50", {:pid=>1957}]
@@ -0,0 +1,49 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'mq'
3
+
4
+ MAX = 500
5
+
6
+ def log *args
7
+ p args
8
+ end
9
+
10
+ # MQ.logging = true
11
+
12
+ EM.run{
13
+
14
+ # worker
15
+
16
+ log "prime checker", Process.pid, :started
17
+
18
+ class Fixnum
19
+ def prime?
20
+ ('1' * self) !~ /^1?$|^(11+?)\1+$/
21
+ end
22
+ end
23
+
24
+ MQ.queue('prime checker').subscribe{ |info, num|
25
+ EM.defer(proc{
26
+
27
+ log "prime checker #{Process.pid}-#{Thread.current.object_id}", :prime?, num
28
+ if Integer(num).prime?
29
+ MQ.queue(info.reply_to).publish(num, :reply_to => "#{Process.pid}-#{Thread.current.object_id}")
30
+ EM.stop_event_loop if num == '499'
31
+ end
32
+
33
+ })
34
+ }
35
+
36
+ # controller
37
+
38
+ MQ.queue('prime collector').subscribe{ |info, prime|
39
+ log 'prime collector', :received, prime, :from, info.reply_to
40
+ (@primes ||= []) << Integer(prime)
41
+ }
42
+
43
+ MAX.times do |i|
44
+ EM.next_tick do
45
+ MQ.queue('prime checker').publish((i+1).to_s, :reply_to => 'prime collector')
46
+ end
47
+ end
48
+
49
+ }
@@ -0,0 +1,87 @@
1
+ require File.expand_path('../lib/amqp/version', __FILE__)
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'totty-amqp'
5
+ s.version = AMQP::VERSION
6
+ s.date = '2010-06-24'
7
+ s.summary = 'AMQP client implementation in Ruby/EventMachine'
8
+ s.email = "tokunaga.jp@gmail.com"
9
+ s.homepage = ""
10
+ s.rubyforge_project = ''
11
+ s.description = "An implementation of the AMQP protocol in Ruby/EventMachine for writing clients to the RabbitMQ message broker"
12
+ s.has_rdoc = true
13
+ s.rdoc_options = '--include=examples'
14
+
15
+ # ruby -rpp -e' pp `git ls-files`.split("\n").grep(/^(doc|README)/) '
16
+ s.extra_rdoc_files = [
17
+ "README",
18
+ "doc/EXAMPLE_01_PINGPONG",
19
+ "doc/EXAMPLE_02_CLOCK",
20
+ "doc/EXAMPLE_03_STOCKS",
21
+ "doc/EXAMPLE_04_MULTICLOCK",
22
+ "doc/EXAMPLE_05_ACK",
23
+ "doc/EXAMPLE_05_POP",
24
+ "doc/EXAMPLE_06_HASHTABLE"
25
+ ]
26
+
27
+ s.authors = ["Aman Gupta"]
28
+ s.add_dependency('eventmachine', '>= 0.12.4')
29
+
30
+ # ruby -rpp -e' pp `git ls-files`.split("\n") '
31
+ s.files = [
32
+ "README",
33
+ "Rakefile",
34
+ "totty-amqp.gemspec",
35
+ "amqp.todo",
36
+ "doc/EXAMPLE_01_PINGPONG",
37
+ "doc/EXAMPLE_02_CLOCK",
38
+ "doc/EXAMPLE_03_STOCKS",
39
+ "doc/EXAMPLE_04_MULTICLOCK",
40
+ "doc/EXAMPLE_05_ACK",
41
+ "doc/EXAMPLE_05_POP",
42
+ "doc/EXAMPLE_06_HASHTABLE",
43
+ "examples/amqp/simple.rb",
44
+ "examples/mq/ack.rb",
45
+ "examples/mq/clock.rb",
46
+ "examples/mq/pop.rb",
47
+ "examples/mq/hashtable.rb",
48
+ "examples/mq/internal.rb",
49
+ "examples/mq/logger.rb",
50
+ "examples/mq/multiclock.rb",
51
+ "examples/mq/pingpong.rb",
52
+ "examples/mq/primes-simple.rb",
53
+ "examples/mq/primes.rb",
54
+ "examples/mq/stocks.rb",
55
+ "lib/amqp.rb",
56
+ "lib/amqp/version.rb",
57
+ "lib/amqp/buffer.rb",
58
+ "lib/amqp/client.rb",
59
+ "lib/amqp/frame.rb",
60
+ "lib/amqp/protocol.rb",
61
+ "lib/amqp/server.rb",
62
+ "lib/amqp/spec.rb",
63
+ "lib/ext/blankslate.rb",
64
+ "lib/ext/em.rb",
65
+ "lib/ext/emfork.rb",
66
+ "lib/mq.rb",
67
+ "lib/mq/exchange.rb",
68
+ "lib/mq/header.rb",
69
+ "lib/mq/logger.rb",
70
+ "lib/mq/queue.rb",
71
+ "lib/mq/rpc.rb",
72
+ "old/README",
73
+ "old/Rakefile",
74
+ "old/amqp-0.8.json",
75
+ "old/amqp_spec.rb",
76
+ "old/amqpc.rb",
77
+ "old/codegen.rb",
78
+ "protocol/amqp-0.8.json",
79
+ "protocol/amqp-0.8.xml",
80
+ "protocol/codegen.rb",
81
+ "protocol/doc.txt",
82
+ "research/api.rb",
83
+ "research/primes-forked.rb",
84
+ "research/primes-processes.rb",
85
+ "research/primes-threaded.rb"
86
+ ]
87
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: totty-amqp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 6
8
+ - 7
9
+ - 1
10
+ - totty
11
+ version: 0.6.7.1.totty
12
+ platform: ruby
13
+ authors:
14
+ - Aman Gupta
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-24 00:00:00 +09:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: eventmachine
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ - 12
33
+ - 4
34
+ version: 0.12.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: An implementation of the AMQP protocol in Ruby/EventMachine for writing clients to the RabbitMQ message broker
38
+ email: tokunaga.jp@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README
45
+ - doc/EXAMPLE_01_PINGPONG
46
+ - doc/EXAMPLE_02_CLOCK
47
+ - doc/EXAMPLE_03_STOCKS
48
+ - doc/EXAMPLE_04_MULTICLOCK
49
+ - doc/EXAMPLE_05_ACK
50
+ - doc/EXAMPLE_05_POP
51
+ - doc/EXAMPLE_06_HASHTABLE
52
+ files:
53
+ - README
54
+ - Rakefile
55
+ - totty-amqp.gemspec
56
+ - amqp.todo
57
+ - doc/EXAMPLE_01_PINGPONG
58
+ - doc/EXAMPLE_02_CLOCK
59
+ - doc/EXAMPLE_03_STOCKS
60
+ - doc/EXAMPLE_04_MULTICLOCK
61
+ - doc/EXAMPLE_05_ACK
62
+ - doc/EXAMPLE_05_POP
63
+ - doc/EXAMPLE_06_HASHTABLE
64
+ - examples/amqp/simple.rb
65
+ - examples/mq/ack.rb
66
+ - examples/mq/clock.rb
67
+ - examples/mq/pop.rb
68
+ - examples/mq/hashtable.rb
69
+ - examples/mq/internal.rb
70
+ - examples/mq/logger.rb
71
+ - examples/mq/multiclock.rb
72
+ - examples/mq/pingpong.rb
73
+ - examples/mq/primes-simple.rb
74
+ - examples/mq/primes.rb
75
+ - examples/mq/stocks.rb
76
+ - lib/amqp.rb
77
+ - lib/amqp/version.rb
78
+ - lib/amqp/buffer.rb
79
+ - lib/amqp/client.rb
80
+ - lib/amqp/frame.rb
81
+ - lib/amqp/protocol.rb
82
+ - lib/amqp/server.rb
83
+ - lib/amqp/spec.rb
84
+ - lib/ext/blankslate.rb
85
+ - lib/ext/em.rb
86
+ - lib/ext/emfork.rb
87
+ - lib/mq.rb
88
+ - lib/mq/exchange.rb
89
+ - lib/mq/header.rb
90
+ - lib/mq/logger.rb
91
+ - lib/mq/queue.rb
92
+ - lib/mq/rpc.rb
93
+ - old/README
94
+ - old/Rakefile
95
+ - old/amqp-0.8.json
96
+ - old/amqp_spec.rb
97
+ - old/amqpc.rb
98
+ - old/codegen.rb
99
+ - protocol/amqp-0.8.json
100
+ - protocol/amqp-0.8.xml
101
+ - protocol/codegen.rb
102
+ - protocol/doc.txt
103
+ - research/api.rb
104
+ - research/primes-forked.rb
105
+ - research/primes-processes.rb
106
+ - research/primes-threaded.rb
107
+ has_rdoc: true
108
+ homepage: ""
109
+ licenses: []
110
+
111
+ post_install_message:
112
+ rdoc_options:
113
+ - --include=examples
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">"
128
+ - !ruby/object:Gem::Version
129
+ segments:
130
+ - 1
131
+ - 3
132
+ - 1
133
+ version: 1.3.1
134
+ requirements: []
135
+
136
+ rubyforge_project: ""
137
+ rubygems_version: 1.3.7
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: AMQP client implementation in Ruby/EventMachine
141
+ test_files: []
142
+