totty-amqp 0.6.7.1.totty
Sign up to get free protection for your applications and to get access to all the features.
- data/README +143 -0
- data/Rakefile +20 -0
- data/amqp.todo +32 -0
- data/doc/EXAMPLE_01_PINGPONG +2 -0
- data/doc/EXAMPLE_02_CLOCK +2 -0
- data/doc/EXAMPLE_03_STOCKS +2 -0
- data/doc/EXAMPLE_04_MULTICLOCK +2 -0
- data/doc/EXAMPLE_05_ACK +2 -0
- data/doc/EXAMPLE_05_POP +2 -0
- data/doc/EXAMPLE_06_HASHTABLE +2 -0
- data/examples/amqp/simple.rb +79 -0
- data/examples/mq/ack.rb +45 -0
- data/examples/mq/clock.rb +56 -0
- data/examples/mq/hashtable.rb +52 -0
- data/examples/mq/internal.rb +49 -0
- data/examples/mq/logger.rb +88 -0
- data/examples/mq/multiclock.rb +49 -0
- data/examples/mq/pingpong.rb +45 -0
- data/examples/mq/pop.rb +43 -0
- data/examples/mq/primes-simple.rb +19 -0
- data/examples/mq/primes.rb +99 -0
- data/examples/mq/stocks.rb +58 -0
- data/lib/amqp/buffer.rb +395 -0
- data/lib/amqp/client.rb +210 -0
- data/lib/amqp/frame.rb +124 -0
- data/lib/amqp/protocol.rb +212 -0
- data/lib/amqp/server.rb +99 -0
- data/lib/amqp/spec.rb +832 -0
- data/lib/amqp/version.rb +3 -0
- data/lib/amqp.rb +152 -0
- data/lib/ext/blankslate.rb +7 -0
- data/lib/ext/em.rb +8 -0
- data/lib/ext/emfork.rb +69 -0
- data/lib/mq/exchange.rb +314 -0
- data/lib/mq/header.rb +33 -0
- data/lib/mq/logger.rb +89 -0
- data/lib/mq/queue.rb +455 -0
- data/lib/mq/rpc.rb +100 -0
- data/lib/mq.rb +877 -0
- data/old/README +30 -0
- data/old/Rakefile +12 -0
- data/old/amqp-0.8.json +606 -0
- data/old/amqp_spec.rb +796 -0
- data/old/amqpc.rb +695 -0
- data/old/codegen.rb +148 -0
- data/protocol/amqp-0.8.json +617 -0
- data/protocol/amqp-0.8.xml +3908 -0
- data/protocol/codegen.rb +173 -0
- data/protocol/doc.txt +281 -0
- data/research/api.rb +88 -0
- data/research/primes-forked.rb +63 -0
- data/research/primes-processes.rb +135 -0
- data/research/primes-threaded.rb +49 -0
- data/totty-amqp.gemspec +87 -0
- 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)
|