sidekick-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +52 -0
  6. data/VERSION +1 -0
  7. data/lib/ext/README +1 -0
  8. data/lib/ext/bunny-0.6.0/LICENSE +20 -0
  9. data/lib/ext/bunny-0.6.0/README.rdoc +66 -0
  10. data/lib/ext/bunny-0.6.0/Rakefile +24 -0
  11. data/lib/ext/bunny-0.6.0/bunny.gemspec +65 -0
  12. data/lib/ext/bunny-0.6.0/examples/simple_08.rb +30 -0
  13. data/lib/ext/bunny-0.6.0/examples/simple_09.rb +30 -0
  14. data/lib/ext/bunny-0.6.0/examples/simple_ack_08.rb +33 -0
  15. data/lib/ext/bunny-0.6.0/examples/simple_ack_09.rb +33 -0
  16. data/lib/ext/bunny-0.6.0/examples/simple_consumer_08.rb +53 -0
  17. data/lib/ext/bunny-0.6.0/examples/simple_consumer_09.rb +53 -0
  18. data/lib/ext/bunny-0.6.0/examples/simple_fanout_08.rb +39 -0
  19. data/lib/ext/bunny-0.6.0/examples/simple_fanout_09.rb +39 -0
  20. data/lib/ext/bunny-0.6.0/examples/simple_headers_08.rb +40 -0
  21. data/lib/ext/bunny-0.6.0/examples/simple_headers_09.rb +40 -0
  22. data/lib/ext/bunny-0.6.0/examples/simple_publisher_08.rb +27 -0
  23. data/lib/ext/bunny-0.6.0/examples/simple_publisher_09.rb +27 -0
  24. data/lib/ext/bunny-0.6.0/examples/simple_topic_08.rb +59 -0
  25. data/lib/ext/bunny-0.6.0/examples/simple_topic_09.rb +59 -0
  26. data/lib/ext/bunny-0.6.0/lib/bunny/channel08.rb +39 -0
  27. data/lib/ext/bunny-0.6.0/lib/bunny/channel09.rb +39 -0
  28. data/lib/ext/bunny-0.6.0/lib/bunny/client08.rb +494 -0
  29. data/lib/ext/bunny-0.6.0/lib/bunny/client09.rb +460 -0
  30. data/lib/ext/bunny-0.6.0/lib/bunny/exchange08.rb +175 -0
  31. data/lib/ext/bunny-0.6.0/lib/bunny/exchange09.rb +177 -0
  32. data/lib/ext/bunny-0.6.0/lib/bunny/queue08.rb +389 -0
  33. data/lib/ext/bunny-0.6.0/lib/bunny/queue09.rb +395 -0
  34. data/lib/ext/bunny-0.6.0/lib/bunny/subscription08.rb +85 -0
  35. data/lib/ext/bunny-0.6.0/lib/bunny/subscription09.rb +85 -0
  36. data/lib/ext/bunny-0.6.0/lib/bunny.rb +87 -0
  37. data/lib/ext/bunny-0.6.0/lib/qrack/channel.rb +18 -0
  38. data/lib/ext/bunny-0.6.0/lib/qrack/client.rb +204 -0
  39. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol08.rb +132 -0
  40. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/protocol09.rb +133 -0
  41. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec08.rb +823 -0
  42. data/lib/ext/bunny-0.6.0/lib/qrack/protocol/spec09.rb +521 -0
  43. data/lib/ext/bunny-0.6.0/lib/qrack/qrack08.rb +23 -0
  44. data/lib/ext/bunny-0.6.0/lib/qrack/qrack09.rb +23 -0
  45. data/lib/ext/bunny-0.6.0/lib/qrack/queue.rb +53 -0
  46. data/lib/ext/bunny-0.6.0/lib/qrack/subscription.rb +102 -0
  47. data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer08.rb +276 -0
  48. data/lib/ext/bunny-0.6.0/lib/qrack/transport/buffer09.rb +276 -0
  49. data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb +112 -0
  50. data/lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb +94 -0
  51. data/lib/ext/bunny-0.6.0/spec/spec_08/bunny_spec.rb +65 -0
  52. data/lib/ext/bunny-0.6.0/spec/spec_08/connection_spec.rb +12 -0
  53. data/lib/ext/bunny-0.6.0/spec/spec_08/exchange_spec.rb +162 -0
  54. data/lib/ext/bunny-0.6.0/spec/spec_08/queue_spec.rb +206 -0
  55. data/lib/ext/bunny-0.6.0/spec/spec_09/bunny_spec.rb +65 -0
  56. data/lib/ext/bunny-0.6.0/spec/spec_09/connection_spec.rb +12 -0
  57. data/lib/ext/bunny-0.6.0/spec/spec_09/exchange_spec.rb +162 -0
  58. data/lib/ext/bunny-0.6.0/spec/spec_09/queue_spec.rb +205 -0
  59. data/lib/ext/eventmachine-0.12.10/.gitignore +14 -0
  60. data/lib/ext/eventmachine-0.12.10/README +82 -0
  61. data/lib/ext/eventmachine-0.12.10/Rakefile +374 -0
  62. data/lib/ext/eventmachine-0.12.10/docs/COPYING +60 -0
  63. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +211 -0
  64. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +133 -0
  65. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +141 -0
  66. data/lib/ext/eventmachine-0.12.10/docs/GNU +281 -0
  67. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +13 -0
  68. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +38 -0
  69. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +25 -0
  70. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  71. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +75 -0
  72. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +94 -0
  73. data/lib/ext/eventmachine-0.12.10/docs/SMTP +2 -0
  74. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +89 -0
  75. data/lib/ext/eventmachine-0.12.10/docs/TODO +8 -0
  76. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +40 -0
  77. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +43 -0
  78. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +2 -0
  79. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +2 -0
  80. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +125 -0
  81. data/lib/ext/eventmachine-0.12.10/ext/binder.h +46 -0
  82. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +827 -0
  83. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +202 -0
  84. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +1893 -0
  85. data/lib/ext/eventmachine-0.12.10/ext/ed.h +424 -0
  86. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +2282 -0
  87. data/lib/ext/eventmachine-0.12.10/ext/em.h +232 -0
  88. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +300 -0
  89. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +94 -0
  90. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +26 -0
  91. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +25 -0
  92. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +122 -0
  93. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +96 -0
  94. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +148 -0
  95. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +83 -0
  96. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +214 -0
  97. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +59 -0
  98. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +127 -0
  99. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +94 -0
  100. data/lib/ext/eventmachine-0.12.10/ext/files.h +65 -0
  101. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +81 -0
  102. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +107 -0
  103. data/lib/ext/eventmachine-0.12.10/ext/page.h +51 -0
  104. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +349 -0
  105. data/lib/ext/eventmachine-0.12.10/ext/project.h +151 -0
  106. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +1166 -0
  107. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +89 -0
  108. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +32 -0
  109. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +460 -0
  110. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +94 -0
  111. data/lib/ext/eventmachine-0.12.10/java/.classpath +8 -0
  112. data/lib/ext/eventmachine-0.12.10/java/.project +17 -0
  113. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +570 -0
  114. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  115. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  116. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  117. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  118. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +194 -0
  119. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  120. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  121. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  122. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  123. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  124. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  125. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  126. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  127. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  128. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  129. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  130. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +138 -0
  131. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +26 -0
  132. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +57 -0
  133. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +564 -0
  134. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +192 -0
  135. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +54 -0
  136. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +61 -0
  137. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +66 -0
  138. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +44 -0
  139. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +119 -0
  140. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +138 -0
  141. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +263 -0
  142. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +590 -0
  143. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +125 -0
  144. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +161 -0
  145. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +323 -0
  146. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +45 -0
  147. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +247 -0
  148. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +175 -0
  149. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +357 -0
  150. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +547 -0
  151. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +66 -0
  152. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +200 -0
  153. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +53 -0
  154. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +36 -0
  155. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +61 -0
  156. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +85 -0
  157. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +130 -0
  158. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +56 -0
  159. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +3 -0
  160. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +1592 -0
  161. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +32 -0
  162. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +75 -0
  163. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +77 -0
  164. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +87 -0
  165. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +48 -0
  166. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +32 -0
  167. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +257 -0
  168. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +1022 -0
  169. data/lib/ext/eventmachine-0.12.10/setup.rb +1585 -0
  170. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +77 -0
  171. data/lib/ext/eventmachine-0.12.10/tests/client.crt +31 -0
  172. data/lib/ext/eventmachine-0.12.10/tests/client.key +51 -0
  173. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +126 -0
  174. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +284 -0
  175. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +63 -0
  176. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +35 -0
  177. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +47 -0
  178. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +160 -0
  179. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +35 -0
  180. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +82 -0
  181. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +55 -0
  182. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +49 -0
  183. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +198 -0
  184. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +30 -0
  185. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +37 -0
  186. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +218 -0
  187. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +218 -0
  188. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +153 -0
  189. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +50 -0
  190. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +60 -0
  191. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +182 -0
  192. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +317 -0
  193. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +133 -0
  194. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +37 -0
  195. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +70 -0
  196. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +48 -0
  197. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +48 -0
  198. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +128 -0
  199. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +92 -0
  200. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +125 -0
  201. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +44 -0
  202. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +42 -0
  203. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +72 -0
  204. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +242 -0
  205. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +76 -0
  206. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +83 -0
  207. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +85 -0
  208. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +322 -0
  209. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +79 -0
  210. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +50 -0
  211. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +82 -0
  212. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +162 -0
  213. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +36 -0
  214. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +31 -0
  215. data/lib/ext/eventmachine-0.12.10/web/whatis +7 -0
  216. data/lib/ext/misc/README +1 -0
  217. data/lib/ext/misc/indifferent_access.rb +131 -0
  218. data/lib/ext/uuidtools-2.1.1/CHANGELOG +56 -0
  219. data/lib/ext/uuidtools-2.1.1/LICENSE +20 -0
  220. data/lib/ext/uuidtools-2.1.1/README +13 -0
  221. data/lib/ext/uuidtools-2.1.1/Rakefile +48 -0
  222. data/lib/ext/uuidtools-2.1.1/lib/compat/securerandom.rb +202 -0
  223. data/lib/ext/uuidtools-2.1.1/lib/uuidtools/version.rb +35 -0
  224. data/lib/ext/uuidtools-2.1.1/lib/uuidtools.rb +618 -0
  225. data/lib/ext/uuidtools-2.1.1/spec/spec.opts +1 -0
  226. data/lib/ext/uuidtools-2.1.1/spec/spec_helper.rb +7 -0
  227. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/mac_address_spec.rb +15 -0
  228. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/utility_spec.rb +21 -0
  229. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_creation_spec.rb +121 -0
  230. data/lib/ext/uuidtools-2.1.1/spec/uuidtools/uuid_parsing_spec.rb +127 -0
  231. data/lib/ext/uuidtools-2.1.1/tasks/benchmark.rake +38 -0
  232. data/lib/ext/uuidtools-2.1.1/tasks/clobber.rake +2 -0
  233. data/lib/ext/uuidtools-2.1.1/tasks/gem.rake +68 -0
  234. data/lib/ext/uuidtools-2.1.1/tasks/git.rake +40 -0
  235. data/lib/ext/uuidtools-2.1.1/tasks/metrics.rake +22 -0
  236. data/lib/ext/uuidtools-2.1.1/tasks/rdoc.rake +29 -0
  237. data/lib/ext/uuidtools-2.1.1/tasks/rubyforge.rake +89 -0
  238. data/lib/ext/uuidtools-2.1.1/tasks/spec.rake +64 -0
  239. data/lib/ext/uuidtools-2.1.1/website/index.html +95 -0
  240. data/lib/sidekick/client/sidekick_client.rb +46 -0
  241. data/lib/sidekick/shared/sidekick_logger.rb +14 -0
  242. data/lib/sidekick/shared/sidekick_queue_publisher.rb +91 -0
  243. data/lib/sidekick-client.rb +7 -0
  244. data/sidekick-client.gemspec +289 -0
  245. data/test/helper.rb +10 -0
  246. data/test/test_sidekick-client.rb +7 -0
  247. metadata +311 -0
@@ -0,0 +1,39 @@
1
+ module Bunny
2
+ class Channel < Qrack::Channel
3
+
4
+ def initialize(client)
5
+ super
6
+ end
7
+
8
+ def open
9
+ client.channel = self
10
+ client.send_frame(Qrack::Protocol::Channel::Open.new)
11
+
12
+ method = client.next_method
13
+
14
+ client.check_response(method, Qrack::Protocol::Channel::OpenOk, "Cannot open channel #{number}")
15
+
16
+ @active = true
17
+ :open_ok
18
+ end
19
+
20
+ def close
21
+ client.channel = self
22
+ client.send_frame(
23
+ Qrack::Protocol::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
24
+ )
25
+
26
+ method = client.next_method
27
+
28
+ client.check_response(method, Qrack::Protocol::Channel::CloseOk, "Error closing channel #{number}")
29
+
30
+ @active = false
31
+ :close_ok
32
+ end
33
+
34
+ def open?
35
+ active
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module Bunny
2
+ class Channel09 < Qrack::Channel
3
+
4
+ def initialize(client)
5
+ super
6
+ end
7
+
8
+ def open
9
+ client.channel = self
10
+ client.send_frame(Qrack::Protocol09::Channel::Open.new)
11
+
12
+ method = client.next_method
13
+
14
+ client.check_response(method, Qrack::Protocol09::Channel::OpenOk, "Cannot open channel #{number}")
15
+
16
+ @active = true
17
+ :open_ok
18
+ end
19
+
20
+ def close
21
+ client.channel = self
22
+ client.send_frame(
23
+ Qrack::Protocol09::Channel::Close.new(:reply_code => 200, :reply_text => 'bye', :method_id => 0, :class_id => 0)
24
+ )
25
+
26
+ method = client.next_method
27
+
28
+ client.check_response(method, Qrack::Protocol09::Channel::CloseOk, "Error closing channel #{number}")
29
+
30
+ @active = false
31
+ :close_ok
32
+ end
33
+
34
+ def open?
35
+ active
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,494 @@
1
+ module Bunny
2
+
3
+ =begin rdoc
4
+
5
+ === DESCRIPTION:
6
+
7
+ The Client class provides the major Bunny API methods.
8
+
9
+ =end
10
+
11
+ class Client < Qrack::Client
12
+
13
+ attr_accessor :ticket
14
+
15
+ =begin rdoc
16
+
17
+ === DESCRIPTION:
18
+
19
+ Sets up a Bunny::Client object ready for connection to a broker/server. _Client_._status_ is set to
20
+ <tt>:not_connected</tt>.
21
+
22
+ ==== OPTIONS:
23
+
24
+ * <tt>:host => '_hostname_' (default = 'localhost')</tt>
25
+ * <tt>:port => _portno_ (default = 5672 or 5671 if :ssl set to true)</tt>
26
+ * <tt>:vhost => '_vhostname_' (default = '/')</tt>
27
+ * <tt>:user => '_username_' (default = 'guest')</tt>
28
+ * <tt>:pass => '_password_' (default = 'guest')</tt>
29
+ * <tt>:ssl => true or false (default = false)</tt> - If set to _true_, ssl
30
+ encryption will be used and port will default to 5671.
31
+ * <tt>:verify_ssl => true or false (default = true)</tt> - If ssl is enabled,
32
+ this will cause OpenSSL to validate the server certificate unless this
33
+ parameter is set to _false_.
34
+ * <tt>:logfile => '_logfilepath_' (default = nil)</tt>
35
+ * <tt>:logging => true or false (_default_)</tt> - If set to _true_, session information is sent
36
+ to STDOUT if <tt>:logfile</tt> has not been specified. Otherwise, session information is written to
37
+ <tt>:logfile</tt>.
38
+ * <tt>:insist => true or false (_default_)</tt> - In a configuration with multiple load-sharing
39
+ servers, the server may respond to a Connection::Open method with a Connection::Redirect. The insist
40
+ option, if set to _true_, tells the server that the client is insisting on a connection to the
41
+ specified server.
42
+ * <tt>:frame_max => maximum frame size in bytes (default = 131072)</tt>
43
+ * <tt>:channel_max => maximum number of channels (default = 0 no maximum)</tt>
44
+ * <tt>:heartbeat => number of seconds (default = 0 no heartbeat)</tt>
45
+ * <tt>:connect_timeout => number of seconds before Qrack::ConnectionTimeout is raised (default = 5)</tt>
46
+
47
+ =end
48
+
49
+ def initialize(opts = {})
50
+ super
51
+ @spec = '0-8'
52
+ @port = opts[:port] || (opts[:ssl] ? Qrack::Protocol::SSL_PORT : Qrack::Protocol::PORT)
53
+ @insist = opts[:insist]
54
+ end
55
+
56
+ =begin rdoc
57
+
58
+ === DESCRIPTION:
59
+
60
+ Checks response from AMQP methods and takes appropriate action
61
+
62
+ =end
63
+
64
+ def check_response(received_method, expected_method, err_msg, err_class = Bunny::ProtocolError)
65
+ case
66
+ when received_method.is_a?(Qrack::Protocol::Connection::Close)
67
+ # Clean up the socket
68
+ close_socket
69
+
70
+ raise Bunny::ForcedConnectionCloseError,
71
+ "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
72
+
73
+ when received_method.is_a?(Qrack::Protocol::Channel::Close)
74
+ # Clean up the channel
75
+ channel.active = false
76
+
77
+ raise Bunny::ForcedChannelCloseError,
78
+ "Error Reply Code: #{received_method.reply_code}\nError Reply Text: #{received_method.reply_text}"
79
+
80
+ when !received_method.is_a?(expected_method)
81
+ raise err_class, err_msg
82
+
83
+ else
84
+ :response_ok
85
+ end
86
+ end
87
+
88
+ def close_connection
89
+ # Set client channel to zero
90
+ switch_channel(0)
91
+
92
+ send_frame(
93
+ Qrack::Protocol::Connection::Close.new(:reply_code => 200, :reply_text => 'Goodbye', :class_id => 0, :method_id => 0)
94
+ )
95
+
96
+ method = next_method
97
+
98
+ check_response(method, Qrack::Protocol::Connection::CloseOk, "Error closing connection")
99
+
100
+ end
101
+
102
+ def create_channel
103
+ channels.each do |c|
104
+ return c if (!c.open? and c.number != 0)
105
+ end
106
+ # If no channel to re-use instantiate new one
107
+ Bunny::Channel.new(self)
108
+ end
109
+
110
+ =begin rdoc
111
+
112
+ === DESCRIPTION:
113
+
114
+ Declares an exchange to the broker/server. If the exchange does not exist, a new one is created
115
+ using the arguments passed in. If the exchange already exists, the existing object is returned.
116
+ If an error occurs a _Bunny_::_ProtocolError_ is raised.
117
+
118
+ ==== OPTIONS:
119
+
120
+ * <tt>:type => one of :direct (_default_), :fanout, :topic, :headers</tt>
121
+ * <tt>:passive => true or false</tt> - If set to _true_, the server will not create the exchange.
122
+ The client can use this to check whether an exchange exists without modifying the server state.
123
+ * <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new exchange, the exchange
124
+ will be marked as durable. Durable exchanges remain active when a server restarts. Non-durable
125
+ exchanges (transient exchanges) are purged if/when a server restarts.
126
+ * <tt>:auto_delete => true or false (_default_)</tt> - If set to _true_, the exchange is deleted
127
+ when all queues have finished using it.
128
+ * <tt>:nowait => true or false (_default_)</tt> - Ignored by Bunny, always _false_.
129
+
130
+ ==== RETURNS:
131
+
132
+ Exchange
133
+
134
+ =end
135
+
136
+ def exchange(name, opts = {})
137
+ exchanges[name] || Bunny::Exchange.new(self, name, opts)
138
+ end
139
+
140
+ def init_connection
141
+ write(Qrack::Protocol::HEADER)
142
+ write([1, 1, Qrack::Protocol::VERSION_MAJOR, Qrack::Protocol::VERSION_MINOR].pack('C4'))
143
+
144
+ frame = next_frame
145
+ if frame.nil? or !frame.payload.is_a?(Qrack::Protocol::Connection::Start)
146
+ raise Bunny::ProtocolError, 'Connection initiation failed'
147
+ end
148
+ end
149
+
150
+ def next_frame(opts = {})
151
+ frame = nil
152
+
153
+ case
154
+ when channel.frame_buffer.size > 0
155
+ frame = channel.frame_buffer.shift
156
+ when opts.has_key?(:timeout)
157
+ Timeout::timeout(opts[:timeout], Qrack::ClientTimeout) do
158
+ frame = Qrack::Transport::Frame.parse(buffer)
159
+ end
160
+ else
161
+ frame = Qrack::Transport::Frame.parse(buffer)
162
+ end
163
+
164
+ @logger.info("received") { frame } if @logging
165
+
166
+ raise Bunny::ConnectionError, 'No connection to server' if (frame.nil? and !connecting?)
167
+
168
+ # Monitor server activity and discard heartbeats
169
+ @message_in = true
170
+
171
+ case
172
+ when frame.is_a?(Qrack::Transport::Heartbeat)
173
+ next_frame(opts)
174
+ when frame.nil?
175
+ frame
176
+ when ((frame.channel != channel.number) and (frame.channel != 0))
177
+ channel.frame_buffer << frame
178
+ next_frame(opts)
179
+ else
180
+ frame
181
+ end
182
+
183
+ end
184
+
185
+ def open_connection
186
+ send_frame(
187
+ Qrack::Protocol::Connection::StartOk.new(
188
+ {:platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/celldee/bunny', :version => VERSION},
189
+ 'AMQPLAIN',
190
+ {:LOGIN => @user, :PASSWORD => @pass},
191
+ 'en_US'
192
+ )
193
+ )
194
+
195
+ frame = next_frame
196
+ raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
197
+
198
+ method = frame.payload
199
+
200
+ if method.is_a?(Qrack::Protocol::Connection::Tune)
201
+ send_frame(
202
+ Qrack::Protocol::Connection::TuneOk.new( :channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat)
203
+ )
204
+ end
205
+
206
+ send_frame(
207
+ Qrack::Protocol::Connection::Open.new(:virtual_host => @vhost, :capabilities => '', :insist => @insist)
208
+ )
209
+
210
+ case method = next_method
211
+ when Qrack::Protocol::Connection::OpenOk
212
+ :ok
213
+ when Qrack::Protocol::Connection::Redirect
214
+ raise Bunny::ConnectionError, "Cannot connect to the specified server - host: #{@host}, port: #{@port}" if @insist
215
+
216
+ @host, @port = method.host.split(':')
217
+ close_socket
218
+ else
219
+ raise Bunny::ProtocolError, 'Cannot open connection'
220
+ end
221
+ end
222
+
223
+ =begin rdoc
224
+
225
+ === DESCRIPTION:
226
+
227
+ Requests a specific quality of service. The QoS can be specified for the current channel
228
+ or for all channels on the connection. The particular properties and semantics of a QoS
229
+ method always depend on the content class semantics. Though the QoS method could in principle
230
+ apply to both peers, it is currently meaningful only for the server.
231
+
232
+ ==== Options:
233
+
234
+ * <tt>:prefetch_size => size in no. of octets (default = 0)</tt> - The client can request that
235
+ messages be sent in advance so that when the client finishes processing a message, the following
236
+ message is already held locally, rather than needing to be sent down the channel. Prefetching gives
237
+ a performance improvement. This field specifies the prefetch window size in octets. The server
238
+ will send a message in advance if it is equal to or smaller in size than the available prefetch
239
+ size (and also falls into other prefetch limits). May be set to zero, meaning "no specific limit",
240
+ although other prefetch limits may still apply. The prefetch-size is ignored if the no-ack option
241
+ is set.
242
+ * <tt>:prefetch_count => no. messages (default = 1)</tt> - Specifies a prefetch window in terms
243
+ of whole messages. This field may be used in combination with the prefetch-size field; a message
244
+ will only be sent in advance if both prefetch windows (and those at the channel and connection level)
245
+ allow it. The prefetch-count is ignored if the no-ack option is set.
246
+ * <tt>:global => true or false (_default_)</tt> - By default the QoS settings apply to the current channel only. If set to
247
+ true, they are applied to the entire connection.
248
+
249
+ ==== RETURNS:
250
+
251
+ <tt>:qos_ok</tt> if successful.
252
+
253
+ =end
254
+
255
+ def qos(opts = {})
256
+
257
+ send_frame(
258
+ Qrack::Protocol::Basic::Qos.new({ :prefetch_size => 0, :prefetch_count => 1, :global => false }.merge(opts))
259
+ )
260
+
261
+ method = next_method
262
+
263
+ check_response(method, Qrack::Protocol::Basic::QosOk, "Error specifying Quality of Service")
264
+
265
+ # return confirmation
266
+ :qos_ok
267
+ end
268
+
269
+ =begin rdoc
270
+
271
+ === DESCRIPTION:
272
+
273
+ Declares a queue to the broker/server. If the queue does not exist, a new one is created
274
+ using the arguments passed in. If the queue already exists, a reference to it is created, provided
275
+ that the arguments passed in do not conflict with the existing attributes of the queue. If an error
276
+ occurs a _Bunny_::_ProtocolError_ is raised.
277
+
278
+ ==== OPTIONS:
279
+
280
+ * <tt>:passive => true or false (_default_)</tt> - If set to _true_, the server will not create
281
+ the queue. The client can use this to check whether a queue exists without modifying the server
282
+ state.
283
+ * <tt>:durable => true or false (_default_)</tt> - If set to _true_ when creating a new queue, the
284
+ queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable
285
+ queues (transient queues) are purged if/when a server restarts. Note that durable queues do not
286
+ necessarily hold persistent messages, although it does not make sense to send persistent messages
287
+ to a transient queue.
288
+ * <tt>:exclusive => true or false (_default_)</tt> - If set to _true_, requests an exclusive queue.
289
+ Exclusive queues may only be consumed from by the current connection. Setting the 'exclusive'
290
+ flag always implies 'auto-delete'.
291
+ * <tt>:auto_delete => true or false (_default_)</tt> - If set to _true_, the queue is deleted
292
+ when all consumers have finished using it. Last consumer can be cancelled either explicitly
293
+ or because its channel is closed. If there has never been a consumer on the queue, it is not
294
+ deleted.
295
+ * <tt>:nowait => true or false (_default_)</tt> - Ignored by Bunny, always _false_.
296
+
297
+ ==== RETURNS:
298
+
299
+ Queue
300
+
301
+ =end
302
+
303
+ def queue(name = nil, opts = {})
304
+ if name.is_a?(Hash)
305
+ opts = name
306
+ name = nil
307
+ end
308
+
309
+ # Queue is responsible for placing itself in the list of queues
310
+ queues[name] || Bunny::Queue.new(self, name, opts)
311
+ end
312
+
313
+ =begin rdoc
314
+
315
+ === DESCRIPTION:
316
+
317
+ Asks the broker to redeliver all unacknowledged messages on a specified channel. Zero or
318
+ more messages may be redelivered.
319
+
320
+ ==== Options:
321
+
322
+ * <tt>:requeue => true or false (_default_)</tt> - If set to _false_, the message will be
323
+ redelivered to the original recipient. If set to _true_, the server will attempt to requeue
324
+ the message, potentially then delivering it to an alternative subscriber.
325
+
326
+ =end
327
+
328
+ def recover(opts = {})
329
+
330
+ send_frame(
331
+ Qrack::Protocol::Basic::Recover.new({ :requeue => false }.merge(opts))
332
+ )
333
+
334
+ end
335
+
336
+ def request_access
337
+ send_frame(
338
+ Qrack::Protocol::Access::Request.new(:realm => '/data', :read => true, :write => true, :active => true, :passive => true)
339
+ )
340
+
341
+ method = next_method
342
+
343
+ check_response(method, Qrack::Protocol::Access::RequestOk, "Access denied")
344
+
345
+ self.ticket = method.ticket
346
+ end
347
+
348
+ def send_frame(*args)
349
+ args.each do |data|
350
+ data.ticket = ticket if ticket and data.respond_to?(:ticket=)
351
+ data = data.to_frame(channel.number) unless data.is_a?(Qrack::Transport::Frame)
352
+ data.channel = channel.number
353
+
354
+ @logger.info("send") { data } if @logging
355
+ write(data.to_s)
356
+
357
+ # Monitor client activity for heartbeat purposes
358
+ @message_out = true
359
+ end
360
+
361
+ nil
362
+ end
363
+
364
+ def send_heartbeat
365
+ # Create a new heartbeat frame
366
+ hb = Qrack::Transport::Heartbeat.new('')
367
+ # Channel 0 must be used
368
+ switch_channel(0) if @channel.number > 0
369
+ # Send the heartbeat to server
370
+ send_frame(hb)
371
+ end
372
+
373
+ =begin rdoc
374
+
375
+ === DESCRIPTION:
376
+
377
+ Opens a communication channel and starts a connection. If an error occurs, a
378
+ _Bunny_::_ProtocolError_ is raised. If successful, _Client_._status_ is set to <tt>:connected</tt>.
379
+
380
+ ==== RETURNS:
381
+
382
+ <tt>:connected</tt> if successful.
383
+
384
+ =end
385
+
386
+ def start_session
387
+ @connecting = true
388
+
389
+ loop do
390
+ # Create/get socket
391
+ socket
392
+
393
+ # Initiate connection
394
+ init_connection
395
+
396
+ # Open connection
397
+ break if open_connection == :ok
398
+ end
399
+
400
+ # Open another channel because channel zero is used for specific purposes
401
+ c = create_channel()
402
+ c.open
403
+
404
+ # Get access ticket
405
+ request_access
406
+
407
+ @connecting = false
408
+
409
+ # return status
410
+ @status = :connected
411
+ end
412
+
413
+ alias start start_session
414
+
415
+ =begin rdoc
416
+
417
+ === DESCRIPTION:
418
+ This method commits all messages published and acknowledged in
419
+ the current transaction. A new transaction starts immediately
420
+ after a commit.
421
+
422
+ ==== RETURNS:
423
+
424
+ <tt>:commit_ok</tt> if successful.
425
+
426
+ =end
427
+
428
+ def tx_commit
429
+ send_frame(Qrack::Protocol::Tx::Commit.new())
430
+
431
+ method = next_method
432
+
433
+ check_response(method, Qrack::Protocol::Tx::CommitOk, "Error commiting transaction")
434
+
435
+ # return confirmation
436
+ :commit_ok
437
+ end
438
+
439
+ =begin rdoc
440
+
441
+ === DESCRIPTION:
442
+ This method abandons all messages published and acknowledged in
443
+ the current transaction. A new transaction starts immediately
444
+ after a rollback.
445
+
446
+ ==== RETURNS:
447
+
448
+ <tt>:rollback_ok</tt> if successful.
449
+
450
+ =end
451
+
452
+ def tx_rollback
453
+ send_frame(Qrack::Protocol::Tx::Rollback.new())
454
+
455
+ method = next_method
456
+
457
+ check_response(method, Qrack::Protocol::Tx::RollbackOk, "Error rolling back transaction")
458
+
459
+ # return confirmation
460
+ :rollback_ok
461
+ end
462
+
463
+ =begin rdoc
464
+
465
+ === DESCRIPTION:
466
+ This method sets the channel to use standard transactions. The
467
+ client must use this method at least once on a channel before
468
+ using the Commit or Rollback methods.
469
+
470
+ ==== RETURNS:
471
+
472
+ <tt>:select_ok</tt> if successful.
473
+
474
+ =end
475
+
476
+ def tx_select
477
+ send_frame(Qrack::Protocol::Tx::Select.new())
478
+
479
+ method = next_method
480
+
481
+ check_response(method, Qrack::Protocol::Tx::SelectOk, "Error initiating transactions for current channel")
482
+
483
+ # return confirmation
484
+ :select_ok
485
+ end
486
+
487
+ private
488
+
489
+ def buffer
490
+ @buffer ||= Qrack::Transport::Buffer.new(self)
491
+ end
492
+
493
+ end
494
+ end