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
data/old/codegen.rb ADDED
@@ -0,0 +1,148 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+
4
+ s = JSON.parse(File.read('amqp-0.8.json'))
5
+
6
+ # require 'pp'
7
+ # pp(s)
8
+ # exit
9
+
10
+ require 'erb'
11
+
12
+ puts ERB.new(%q[
13
+ module AMQP
14
+ HEADER = <%= s['name'].dump %>.freeze
15
+ VERSION_MAJOR = <%= s['major-version'] %>
16
+ VERSION_MINOR = <%= s['minor-version'] %>
17
+ PORT = <%= s['port'] %>
18
+
19
+ class Frame
20
+ TYPES = [
21
+ nil,
22
+ <%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
23
+ :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
24
+ <%- end -%>
25
+ ]
26
+ FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
27
+ end
28
+
29
+ RESPONSES = {
30
+ <%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
31
+ <%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
32
+ <%- end -%>
33
+ }
34
+
35
+ FIELDS = [
36
+ <%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
37
+ :<%= d.first -%>,
38
+ <%- end -%>
39
+ ]
40
+
41
+ module Protocol
42
+ class Class
43
+ class << self
44
+ FIELDS.each do |f|
45
+ class_eval %[
46
+ def #{f} name
47
+ properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
48
+ attr_accessor name
49
+ end
50
+ ]
51
+ end
52
+
53
+ def properties() @properties ||= [] end
54
+
55
+ def id() self::ID end
56
+ def name() self::NAME end
57
+ end
58
+
59
+ class Method
60
+ class << self
61
+ FIELDS.each do |f|
62
+ class_eval %[
63
+ def #{f} name
64
+ arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
65
+ attr_accessor name
66
+ end
67
+ ]
68
+ end
69
+
70
+ def arguments() @arguments ||= [] end
71
+
72
+ def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
73
+ def id() self::ID end
74
+ def name() self::NAME end
75
+ end
76
+
77
+ def == b
78
+ self.class.arguments.inject(true) do |eql, (type, name)|
79
+ eql and __send__("#{name}") == b.__send__("#{name}")
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.methods() @methods ||= {} end
85
+
86
+ def self.Method(id, name)
87
+ @_base_methods ||= {}
88
+ @_base_methods[id] ||= ::Class.new(Method) do
89
+ class_eval %[
90
+ def self.inherited klass
91
+ klass.const_set(:ID, #{id})
92
+ klass.const_set(:NAME, :#{name.to_s})
93
+ klass.parent.methods[#{id}] = klass
94
+ klass.parent.methods[klass::NAME] = klass
95
+ end
96
+ ]
97
+ end
98
+ end
99
+ end
100
+
101
+ def self.classes() @classes ||= {} end
102
+
103
+ def self.Class(id, name)
104
+ @_base_classes ||= {}
105
+ @_base_classes[id] ||= ::Class.new(Class) do
106
+ class_eval %[
107
+ def self.inherited klass
108
+ klass.const_set(:ID, #{id})
109
+ klass.const_set(:NAME, :#{name.to_s})
110
+ Protocol.classes[#{id}] = klass
111
+ Protocol.classes[klass::NAME] = klass
112
+ end
113
+ ]
114
+ end
115
+ end
116
+
117
+ <%- s['classes'].each do |c| -%>
118
+ class <%= c['name'].capitalize.ljust(12) %> < Class(<%= c['id'] %>, :<%= c['name'] %>); end
119
+ <%- end -%>
120
+
121
+ <%- s['classes'].each do |c| -%>
122
+ class <%= c['name'].capitalize %>
123
+ <%- c['properties'].each do |p| -%>
124
+ <%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
125
+ <%- end if c['properties'] -%>
126
+
127
+ <%- c['methods'].each do |m| -%>
128
+ class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method(<%= m['id'] %>, :<%= m['name'].tr('- ','_') %>); end
129
+ <%- end -%>
130
+
131
+ <%- c['methods'].each do |m| -%>
132
+ class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
133
+ <%- m['arguments'].each do |a| -%>
134
+ <%- if a['domain'] -%>
135
+ <%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
136
+ <%- else -%>
137
+ <%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
138
+ <%- end -%>
139
+ <%- end if m['arguments'] -%>
140
+ end
141
+
142
+ <%- end -%>
143
+ end
144
+
145
+ <%- end -%>
146
+ end
147
+ end
148
+ ].gsub!(/^ /,''), nil, '>-%').result(binding)