sensu-em 2.0.0-java

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.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +12 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +33 -0
  6. data/GNU +281 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +60 -0
  9. data/README.md +109 -0
  10. data/Rakefile +20 -0
  11. data/docs/DocumentationGuidesIndex.md +27 -0
  12. data/docs/GettingStarted.md +521 -0
  13. data/docs/old/ChangeLog +211 -0
  14. data/docs/old/DEFERRABLES +246 -0
  15. data/docs/old/EPOLL +141 -0
  16. data/docs/old/INSTALL +13 -0
  17. data/docs/old/KEYBOARD +42 -0
  18. data/docs/old/LEGAL +25 -0
  19. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  20. data/docs/old/PURE_RUBY +75 -0
  21. data/docs/old/RELEASE_NOTES +94 -0
  22. data/docs/old/SMTP +4 -0
  23. data/docs/old/SPAWNED_PROCESSES +148 -0
  24. data/docs/old/TODO +8 -0
  25. data/eventmachine.gemspec +38 -0
  26. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  27. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  28. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  29. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  30. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  31. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  32. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  33. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  34. data/examples/old/ex_channel.rb +43 -0
  35. data/examples/old/ex_queue.rb +2 -0
  36. data/examples/old/ex_tick_loop_array.rb +15 -0
  37. data/examples/old/ex_tick_loop_counter.rb +32 -0
  38. data/examples/old/helper.rb +2 -0
  39. data/ext/binder.cpp +124 -0
  40. data/ext/binder.h +46 -0
  41. data/ext/cmain.cpp +887 -0
  42. data/ext/ed.cpp +1988 -0
  43. data/ext/ed.h +422 -0
  44. data/ext/em.cpp +2352 -0
  45. data/ext/em.h +253 -0
  46. data/ext/eventmachine.h +128 -0
  47. data/ext/extconf.rb +179 -0
  48. data/ext/fastfilereader/extconf.rb +103 -0
  49. data/ext/fastfilereader/mapper.cpp +214 -0
  50. data/ext/fastfilereader/mapper.h +59 -0
  51. data/ext/fastfilereader/rubymain.cpp +127 -0
  52. data/ext/kb.cpp +79 -0
  53. data/ext/page.cpp +107 -0
  54. data/ext/page.h +51 -0
  55. data/ext/pipe.cpp +347 -0
  56. data/ext/project.h +161 -0
  57. data/ext/rubymain.cpp +1318 -0
  58. data/ext/ssl.cpp +468 -0
  59. data/ext/ssl.h +94 -0
  60. data/java/.classpath +6 -0
  61. data/java/.gitignore +1 -0
  62. data/java/.project +17 -0
  63. data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
  64. data/java/src/com/rubyeventmachine/EmReactor.java +529 -0
  65. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  66. data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
  67. data/java/src/com/rubyeventmachine/EventCode.java +26 -0
  68. data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
  69. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +180 -0
  70. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
  71. data/java/src/com/rubyeventmachine/SslBox.java +310 -0
  72. data/lib/em/buftok.rb +110 -0
  73. data/lib/em/callback.rb +58 -0
  74. data/lib/em/channel.rb +64 -0
  75. data/lib/em/completion.rb +304 -0
  76. data/lib/em/connection.rb +712 -0
  77. data/lib/em/deferrable/pool.rb +2 -0
  78. data/lib/em/deferrable.rb +210 -0
  79. data/lib/em/file_watch.rb +73 -0
  80. data/lib/em/future.rb +61 -0
  81. data/lib/em/iterator.rb +231 -0
  82. data/lib/em/messages.rb +66 -0
  83. data/lib/em/pool.rb +151 -0
  84. data/lib/em/process_watch.rb +45 -0
  85. data/lib/em/processes.rb +123 -0
  86. data/lib/em/protocols/header_and_content.rb +138 -0
  87. data/lib/em/protocols/httpclient.rb +279 -0
  88. data/lib/em/protocols/httpclient2.rb +600 -0
  89. data/lib/em/protocols/line_and_text.rb +125 -0
  90. data/lib/em/protocols/line_protocol.rb +29 -0
  91. data/lib/em/protocols/linetext2.rb +161 -0
  92. data/lib/em/protocols/memcache.rb +331 -0
  93. data/lib/em/protocols/object_protocol.rb +46 -0
  94. data/lib/em/protocols/postgres3.rb +246 -0
  95. data/lib/em/protocols/saslauth.rb +175 -0
  96. data/lib/em/protocols/smtpclient.rb +365 -0
  97. data/lib/em/protocols/smtpserver.rb +643 -0
  98. data/lib/em/protocols/socks4.rb +66 -0
  99. data/lib/em/protocols/stomp.rb +205 -0
  100. data/lib/em/protocols/tcptest.rb +54 -0
  101. data/lib/em/protocols.rb +37 -0
  102. data/lib/em/pure_ruby.rb +1017 -0
  103. data/lib/em/queue.rb +71 -0
  104. data/lib/em/resolver.rb +209 -0
  105. data/lib/em/spawnable.rb +84 -0
  106. data/lib/em/streamer.rb +118 -0
  107. data/lib/em/threaded_resource.rb +90 -0
  108. data/lib/em/tick_loop.rb +85 -0
  109. data/lib/em/timers.rb +61 -0
  110. data/lib/em/version.rb +3 -0
  111. data/lib/eventmachine.rb +1553 -0
  112. data/lib/jeventmachine.rb +321 -0
  113. data/lib/rubyeventmachine.jar +0 -0
  114. data/rakelib/cpp.rake_example +77 -0
  115. data/rakelib/package.rake +98 -0
  116. data/rakelib/test.rake +8 -0
  117. data/tests/client.crt +31 -0
  118. data/tests/client.key +51 -0
  119. data/tests/em_test_helper.rb +64 -0
  120. data/tests/server.crt +36 -0
  121. data/tests/server.key +51 -0
  122. data/tests/test_attach.rb +150 -0
  123. data/tests/test_basic.rb +294 -0
  124. data/tests/test_channel.rb +62 -0
  125. data/tests/test_completion.rb +177 -0
  126. data/tests/test_connection_count.rb +53 -0
  127. data/tests/test_defer.rb +18 -0
  128. data/tests/test_deferrable.rb +35 -0
  129. data/tests/test_epoll.rb +145 -0
  130. data/tests/test_error_handler.rb +38 -0
  131. data/tests/test_exc.rb +28 -0
  132. data/tests/test_file_watch.rb +65 -0
  133. data/tests/test_futures.rb +170 -0
  134. data/tests/test_get_sock_opt.rb +37 -0
  135. data/tests/test_handler_check.rb +35 -0
  136. data/tests/test_hc.rb +155 -0
  137. data/tests/test_httpclient.rb +190 -0
  138. data/tests/test_httpclient2.rb +133 -0
  139. data/tests/test_idle_connection.rb +25 -0
  140. data/tests/test_inactivity_timeout.rb +54 -0
  141. data/tests/test_iterator.rb +97 -0
  142. data/tests/test_kb.rb +34 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +138 -0
  145. data/tests/test_ltp2.rb +288 -0
  146. data/tests/test_next_tick.rb +104 -0
  147. data/tests/test_object_protocol.rb +36 -0
  148. data/tests/test_pause.rb +102 -0
  149. data/tests/test_pending_connect_timeout.rb +52 -0
  150. data/tests/test_pool.rb +194 -0
  151. data/tests/test_process_watch.rb +48 -0
  152. data/tests/test_processes.rb +128 -0
  153. data/tests/test_proxy_connection.rb +180 -0
  154. data/tests/test_pure.rb +88 -0
  155. data/tests/test_queue.rb +50 -0
  156. data/tests/test_resolver.rb +55 -0
  157. data/tests/test_running.rb +14 -0
  158. data/tests/test_sasl.rb +47 -0
  159. data/tests/test_send_file.rb +217 -0
  160. data/tests/test_servers.rb +33 -0
  161. data/tests/test_set_sock_opt.rb +37 -0
  162. data/tests/test_shutdown_hooks.rb +23 -0
  163. data/tests/test_smtpclient.rb +55 -0
  164. data/tests/test_smtpserver.rb +57 -0
  165. data/tests/test_spawn.rb +293 -0
  166. data/tests/test_ssl_args.rb +78 -0
  167. data/tests/test_ssl_echo_data.rb +60 -0
  168. data/tests/test_ssl_methods.rb +56 -0
  169. data/tests/test_ssl_verify.rb +82 -0
  170. data/tests/test_stomp.rb +37 -0
  171. data/tests/test_system.rb +42 -0
  172. data/tests/test_threaded_resource.rb +53 -0
  173. data/tests/test_tick_loop.rb +59 -0
  174. data/tests/test_timers.rb +123 -0
  175. data/tests/test_ud.rb +8 -0
  176. data/tests/test_unbind_reason.rb +48 -0
  177. metadata +297 -0
@@ -0,0 +1,279 @@
1
+ #--
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 16 July 2006
6
+ #
7
+ # See EventMachine and EventMachine::Connection for documentation and
8
+ # usage examples.
9
+ #
10
+ #----------------------------------------------------------------------------
11
+ #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU General Public License
17
+ # as published by the Free Software Foundation; either version 2 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #---------------------------------------------------------------------------
23
+ #
24
+ #
25
+
26
+
27
+
28
+ module EventMachine
29
+ module Protocols
30
+
31
+ # <b>Note:</b> This class is deprecated and will be removed. Please use EM-HTTP-Request instead.
32
+ #
33
+ # @example
34
+ # EventMachine.run {
35
+ # http = EventMachine::Protocols::HttpClient.request(
36
+ # :host => server,
37
+ # :port => 80,
38
+ # :request => "/index.html",
39
+ # :query_string => "parm1=value1&parm2=value2"
40
+ # )
41
+ # http.callback {|response|
42
+ # puts response[:status]
43
+ # puts response[:headers]
44
+ # puts response[:content]
45
+ # }
46
+ # }
47
+ #--
48
+ # TODO:
49
+ # Add streaming so we can support enormous POSTs. Current max is 20meg.
50
+ # Timeout for connections that run too long or hang somewhere in the middle.
51
+ # Persistent connections (HTTP/1.1), may need a associated delegate object.
52
+ # DNS: Some way to cache DNS lookups for hostnames we connect to. Ruby's
53
+ # DNS lookups are unbelievably slow.
54
+ # HEAD requests.
55
+ # Chunked transfer encoding.
56
+ # Convenience methods for requests. get, post, url, etc.
57
+ # SSL.
58
+ # Handle status codes like 304, 100, etc.
59
+ # Refactor this code so that protocol errors all get handled one way (an exception?),
60
+ # instead of sprinkling set_deferred_status :failed calls everywhere.
61
+ class HttpClient < Connection
62
+ include EventMachine::Deferrable
63
+
64
+ MaxPostContentLength = 20 * 1024 * 1024
65
+
66
+ def initialize
67
+ warn "HttpClient is deprecated and will be removed. EM-Http-Request should be used instead."
68
+ end
69
+
70
+ # @param args [Hash] The request arguments
71
+ # @option args [String] :host The host IP/DNS name
72
+ # @option args [Integer] :port The port to connect too
73
+ # @option args [String] :verb The request type [GET | POST | DELETE | PUT]
74
+ # @option args [String] :request The request path
75
+ # @option args [Hash] :basic_auth The basic auth credentials (:username and :password)
76
+ # @option args [String] :content The request content
77
+ # @option args [String] :contenttype The content type (e.g. text/plain)
78
+ # @option args [String] :query_string The query string
79
+ # @option args [String] :host_header The host header to set
80
+ # @option args [String] :cookie Cookies to set
81
+ def self.request( args = {} )
82
+ args[:port] ||= 80
83
+ EventMachine.connect( args[:host], args[:port], self ) {|c|
84
+ # According to the docs, we will get here AFTER post_init is called.
85
+ c.instance_eval {@args = args}
86
+ }
87
+ end
88
+
89
+ def post_init
90
+ @start_time = Time.now
91
+ @data = ""
92
+ @read_state = :base
93
+ end
94
+
95
+ # We send the request when we get a connection.
96
+ # AND, we set an instance variable to indicate we passed through here.
97
+ # That allows #unbind to know whether there was a successful connection.
98
+ # NB: This naive technique won't work when we have to support multiple
99
+ # requests on a single connection.
100
+ def connection_completed
101
+ @connected = true
102
+ send_request @args
103
+ end
104
+
105
+ def send_request args
106
+ args[:verb] ||= args[:method] # Support :method as an alternative to :verb.
107
+ args[:verb] ||= :get # IS THIS A GOOD IDEA, to default to GET if nothing was specified?
108
+
109
+ verb = args[:verb].to_s.upcase
110
+ unless ["GET", "POST", "PUT", "DELETE", "HEAD"].include?(verb)
111
+ set_deferred_status :failed, {:status => 0} # TODO, not signalling the error type
112
+ return # NOTE THE EARLY RETURN, we're not sending any data.
113
+ end
114
+
115
+ request = args[:request] || "/"
116
+ unless request[0,1] == "/"
117
+ request = "/" + request
118
+ end
119
+
120
+ qs = args[:query_string] || ""
121
+ if qs.length > 0 and qs[0,1] != '?'
122
+ qs = "?" + qs
123
+ end
124
+
125
+ version = args[:version] || "1.1"
126
+
127
+ # Allow an override for the host header if it's not the connect-string.
128
+ host = args[:host_header] || args[:host] || "_"
129
+ # For now, ALWAYS tuck in the port string, although we may want to omit it if it's the default.
130
+ port = args[:port].to_i != 80 ? ":#{args[:port]}" : ""
131
+
132
+ # POST items.
133
+ postcontenttype = args[:contenttype] || "application/octet-stream"
134
+ postcontent = args[:content] || ""
135
+ raise "oversized content in HTTP POST" if postcontent.length > MaxPostContentLength
136
+
137
+ # ESSENTIAL for the request's line-endings to be CRLF, not LF. Some servers misbehave otherwise.
138
+ # TODO: We ASSUME the caller wants to send a 1.1 request. May not be a good assumption.
139
+ req = [
140
+ "#{verb} #{request}#{qs} HTTP/#{version}",
141
+ "Host: #{host}#{port}",
142
+ "User-agent: Ruby EventMachine",
143
+ ]
144
+
145
+ if verb == "POST" || verb == "PUT"
146
+ req << "Content-type: #{postcontenttype}"
147
+ req << "Content-length: #{postcontent.length}"
148
+ end
149
+
150
+ # TODO, this cookie handler assumes it's getting a single, semicolon-delimited string.
151
+ # Eventually we will want to deal intelligently with arrays and hashes.
152
+ if args[:cookie]
153
+ req << "Cookie: #{args[:cookie]}"
154
+ end
155
+
156
+ # Allow custom HTTP headers, e.g. SOAPAction
157
+ args[:custom_headers].each do |k,v|
158
+ req << "#{k}: #{v}"
159
+ end if args[:custom_headers]
160
+
161
+ # Basic-auth stanza contributed by Matt Murphy.
162
+ if args[:basic_auth]
163
+ basic_auth_string = ["#{args[:basic_auth][:username]}:#{args[:basic_auth][:password]}"].pack('m').strip.gsub(/\n/,'')
164
+ req << "Authorization: Basic #{basic_auth_string}"
165
+ end
166
+
167
+ req << ""
168
+ reqstring = req.map {|l| "#{l}\r\n"}.join
169
+ send_data reqstring
170
+
171
+ if verb == "POST" || verb == "PUT"
172
+ send_data postcontent
173
+ end
174
+ end
175
+
176
+
177
+ def receive_data data
178
+ while data and data.length > 0
179
+ case @read_state
180
+ when :base
181
+ # Perform any per-request initialization here and don't consume any data.
182
+ @data = ""
183
+ @headers = []
184
+ @content_length = nil # not zero
185
+ @content = ""
186
+ @status = nil
187
+ @read_state = :header
188
+ @connection_close = nil
189
+ when :header
190
+ ary = data.split( /\r?\n/m, 2 )
191
+ if ary.length == 2
192
+ data = ary.last
193
+ if ary.first == ""
194
+ if (@content_length and @content_length > 0) || @connection_close
195
+ @read_state = :content
196
+ else
197
+ dispatch_response
198
+ @read_state = :base
199
+ end
200
+ else
201
+ @headers << ary.first
202
+ if @headers.length == 1
203
+ parse_response_line
204
+ elsif ary.first =~ /\Acontent-length:\s*/i
205
+ # Only take the FIRST content-length header that appears,
206
+ # which we can distinguish because @content_length is nil.
207
+ # TODO, it's actually a fatal error if there is more than one
208
+ # content-length header, because the caller is presumptively
209
+ # a bad guy. (There is an exploit that depends on multiple
210
+ # content-length headers.)
211
+ @content_length ||= $'.to_i
212
+ elsif ary.first =~ /\Aconnection:\s*close/i
213
+ @connection_close = true
214
+ end
215
+ end
216
+ else
217
+ @data << data
218
+ data = ""
219
+ end
220
+ when :content
221
+ # If there was no content-length header, we have to wait until the connection
222
+ # closes. Everything we get until that point is content.
223
+ # TODO: Must impose a content-size limit, and also must implement chunking.
224
+ # Also, must support either temporary files for large content, or calling
225
+ # a content-consumer block supplied by the user.
226
+ if @content_length
227
+ bytes_needed = @content_length - @content.length
228
+ @content += data[0, bytes_needed]
229
+ data = data[bytes_needed..-1] || ""
230
+ if @content_length == @content.length
231
+ dispatch_response
232
+ @read_state = :base
233
+ end
234
+ else
235
+ @content << data
236
+ data = ""
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+
243
+ # We get called here when we have received an HTTP response line.
244
+ # It's an opportunity to throw an exception or trigger other exceptional
245
+ # handling.
246
+ def parse_response_line
247
+ if @headers.first =~ /\AHTTP\/1\.[01] ([\d]{3})/
248
+ @status = $1.to_i
249
+ else
250
+ set_deferred_status :failed, {
251
+ :status => 0 # crappy way of signifying an unrecognized response. TODO, find a better way to do this.
252
+ }
253
+ close_connection
254
+ end
255
+ end
256
+ private :parse_response_line
257
+
258
+ def dispatch_response
259
+ @read_state = :base
260
+ set_deferred_status :succeeded, {
261
+ :content => @content,
262
+ :headers => @headers,
263
+ :status => @status
264
+ }
265
+ # TODO, we close the connection for now, but this is wrong for persistent clients.
266
+ close_connection
267
+ end
268
+
269
+ def unbind
270
+ if !@connected
271
+ set_deferred_status :failed, {:status => 0} # YECCCCH. Find a better way to signal no-connect/network error.
272
+ elsif (@read_state == :content and @content_length == nil)
273
+ dispatch_response
274
+ end
275
+ end
276
+ end
277
+
278
+ end
279
+ end