sensu-em 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +12 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +33 -0
- data/GNU +281 -0
- data/Gemfile +2 -0
- data/LICENSE +60 -0
- data/README.md +109 -0
- data/Rakefile +20 -0
- data/docs/DocumentationGuidesIndex.md +27 -0
- data/docs/GettingStarted.md +521 -0
- data/docs/old/ChangeLog +211 -0
- data/docs/old/DEFERRABLES +246 -0
- data/docs/old/EPOLL +141 -0
- data/docs/old/INSTALL +13 -0
- data/docs/old/KEYBOARD +42 -0
- data/docs/old/LEGAL +25 -0
- data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
- data/docs/old/PURE_RUBY +75 -0
- data/docs/old/RELEASE_NOTES +94 -0
- data/docs/old/SMTP +4 -0
- data/docs/old/SPAWNED_PROCESSES +148 -0
- data/docs/old/TODO +8 -0
- data/eventmachine.gemspec +38 -0
- data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
- data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
- data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
- data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
- data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
- data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
- data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
- data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
- data/examples/old/ex_channel.rb +43 -0
- data/examples/old/ex_queue.rb +2 -0
- data/examples/old/ex_tick_loop_array.rb +15 -0
- data/examples/old/ex_tick_loop_counter.rb +32 -0
- data/examples/old/helper.rb +2 -0
- data/ext/binder.cpp +124 -0
- data/ext/binder.h +46 -0
- data/ext/cmain.cpp +887 -0
- data/ext/ed.cpp +1988 -0
- data/ext/ed.h +422 -0
- data/ext/em.cpp +2352 -0
- data/ext/em.h +253 -0
- data/ext/eventmachine.h +128 -0
- data/ext/extconf.rb +179 -0
- data/ext/fastfilereader/extconf.rb +103 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/kb.cpp +79 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +347 -0
- data/ext/project.h +161 -0
- data/ext/rubymain.cpp +1318 -0
- data/ext/ssl.cpp +468 -0
- data/ext/ssl.h +94 -0
- data/java/.classpath +6 -0
- data/java/.gitignore +1 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +529 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
- data/java/src/com/rubyeventmachine/EventCode.java +26 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +180 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
- data/java/src/com/rubyeventmachine/SslBox.java +310 -0
- data/lib/em/buftok.rb +110 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +64 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +712 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +231 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/pool.rb +151 -0
- data/lib/em/process_watch.rb +45 -0
- data/lib/em/processes.rb +123 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +279 -0
- data/lib/em/protocols/httpclient2.rb +600 -0
- data/lib/em/protocols/line_and_text.rb +125 -0
- data/lib/em/protocols/line_protocol.rb +29 -0
- data/lib/em/protocols/linetext2.rb +161 -0
- data/lib/em/protocols/memcache.rb +331 -0
- data/lib/em/protocols/object_protocol.rb +46 -0
- data/lib/em/protocols/postgres3.rb +246 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +365 -0
- data/lib/em/protocols/smtpserver.rb +643 -0
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/protocols/stomp.rb +205 -0
- data/lib/em/protocols/tcptest.rb +54 -0
- data/lib/em/protocols.rb +37 -0
- data/lib/em/pure_ruby.rb +1017 -0
- data/lib/em/queue.rb +71 -0
- data/lib/em/resolver.rb +209 -0
- data/lib/em/spawnable.rb +84 -0
- data/lib/em/streamer.rb +118 -0
- data/lib/em/threaded_resource.rb +90 -0
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +61 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1553 -0
- data/lib/jeventmachine.rb +321 -0
- data/lib/rubyeventmachine.jar +0 -0
- data/rakelib/cpp.rake_example +77 -0
- data/rakelib/package.rake +98 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/server.crt +36 -0
- data/tests/server.key +51 -0
- data/tests/test_attach.rb +150 -0
- data/tests/test_basic.rb +294 -0
- data/tests/test_channel.rb +62 -0
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +53 -0
- data/tests/test_defer.rb +18 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +145 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +65 -0
- data/tests/test_futures.rb +170 -0
- data/tests/test_get_sock_opt.rb +37 -0
- data/tests/test_handler_check.rb +35 -0
- data/tests/test_hc.rb +155 -0
- data/tests/test_httpclient.rb +190 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_idle_connection.rb +25 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_iterator.rb +97 -0
- data/tests/test_kb.rb +34 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +288 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +102 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +194 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +128 -0
- data/tests/test_proxy_connection.rb +180 -0
- data/tests/test_pure.rb +88 -0
- data/tests/test_queue.rb +50 -0
- data/tests/test_resolver.rb +55 -0
- data/tests/test_running.rb +14 -0
- data/tests/test_sasl.rb +47 -0
- data/tests/test_send_file.rb +217 -0
- data/tests/test_servers.rb +33 -0
- data/tests/test_set_sock_opt.rb +37 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +55 -0
- data/tests/test_smtpserver.rb +57 -0
- data/tests/test_spawn.rb +293 -0
- data/tests/test_ssl_args.rb +78 -0
- data/tests/test_ssl_echo_data.rb +60 -0
- data/tests/test_ssl_methods.rb +56 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_stomp.rb +37 -0
- data/tests/test_system.rb +42 -0
- data/tests/test_threaded_resource.rb +53 -0
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +123 -0
- data/tests/test_ud.rb +8 -0
- data/tests/test_unbind_reason.rb +48 -0
- metadata +297 -0
@@ -0,0 +1,205 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 15 November 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
|
+
module EventMachine
|
28
|
+
module Protocols
|
29
|
+
|
30
|
+
# Implements Stomp (http://docs.codehaus.org/display/STOMP/Protocol).
|
31
|
+
#
|
32
|
+
# == Usage example
|
33
|
+
#
|
34
|
+
# module StompClient
|
35
|
+
# include EM::Protocols::Stomp
|
36
|
+
#
|
37
|
+
# def connection_completed
|
38
|
+
# connect :login => 'guest', :passcode => 'guest'
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# def receive_msg msg
|
42
|
+
# if msg.command == "CONNECTED"
|
43
|
+
# subscribe '/some/topic'
|
44
|
+
# else
|
45
|
+
# p ['got a message', msg]
|
46
|
+
# puts msg.body
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# EM.run{
|
52
|
+
# EM.connect 'localhost', 61613, StompClient
|
53
|
+
# }
|
54
|
+
#
|
55
|
+
module Stomp
|
56
|
+
include LineText2
|
57
|
+
|
58
|
+
class Message
|
59
|
+
# The command associated with the message, usually 'CONNECTED' or 'MESSAGE'
|
60
|
+
attr_accessor :command
|
61
|
+
# Hash containing headers such as destination and message-id
|
62
|
+
attr_accessor :header
|
63
|
+
alias :headers :header
|
64
|
+
# Body of the message
|
65
|
+
attr_accessor :body
|
66
|
+
|
67
|
+
# @private
|
68
|
+
def initialize
|
69
|
+
@header = {}
|
70
|
+
@state = :precommand
|
71
|
+
@content_length = nil
|
72
|
+
end
|
73
|
+
# @private
|
74
|
+
def consume_line line
|
75
|
+
if @state == :precommand
|
76
|
+
unless line =~ /\A\s*\Z/
|
77
|
+
@command = line
|
78
|
+
@state = :headers
|
79
|
+
end
|
80
|
+
elsif @state == :headers
|
81
|
+
if line == ""
|
82
|
+
if @content_length
|
83
|
+
yield( [:sized_text, @content_length+1] )
|
84
|
+
else
|
85
|
+
@state = :body
|
86
|
+
yield( [:unsized_text] )
|
87
|
+
end
|
88
|
+
elsif line =~ /\A([^:]+):(.+)\Z/
|
89
|
+
k = $1.dup.strip
|
90
|
+
v = $2.dup.strip
|
91
|
+
@header[k] = v
|
92
|
+
if k == "content-length"
|
93
|
+
@content_length = v.to_i
|
94
|
+
end
|
95
|
+
else
|
96
|
+
# This is a protocol error. How to signal it?
|
97
|
+
end
|
98
|
+
elsif @state == :body
|
99
|
+
@body = line
|
100
|
+
yield( [:dispatch] )
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# @private
|
106
|
+
def send_frame verb, headers={}, body=""
|
107
|
+
body = body.to_s
|
108
|
+
ary = [verb, "\n"]
|
109
|
+
body_bytesize = body.bytesize if body.respond_to? :bytesize
|
110
|
+
body_bytesize ||= body.size
|
111
|
+
headers.each {|k,v| ary << "#{k}:#{v}\n" }
|
112
|
+
ary << "content-length: #{body_bytesize}\n"
|
113
|
+
ary << "content-type: text/plain; charset=UTF-8\n" unless headers.has_key? 'content-type'
|
114
|
+
ary << "\n"
|
115
|
+
ary << body
|
116
|
+
ary << "\0"
|
117
|
+
send_data ary.join
|
118
|
+
end
|
119
|
+
|
120
|
+
# @private
|
121
|
+
def receive_line line
|
122
|
+
@stomp_initialized || init_message_reader
|
123
|
+
@stomp_message.consume_line(line) {|outcome|
|
124
|
+
if outcome.first == :sized_text
|
125
|
+
set_text_mode outcome[1]
|
126
|
+
elsif outcome.first == :unsized_text
|
127
|
+
set_delimiter "\0"
|
128
|
+
elsif outcome.first == :dispatch
|
129
|
+
receive_msg(@stomp_message) if respond_to?(:receive_msg)
|
130
|
+
init_message_reader
|
131
|
+
end
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
# @private
|
136
|
+
def receive_binary_data data
|
137
|
+
@stomp_message.body = data[0..-2]
|
138
|
+
receive_msg(@stomp_message) if respond_to?(:receive_msg)
|
139
|
+
init_message_reader
|
140
|
+
end
|
141
|
+
|
142
|
+
# @private
|
143
|
+
def init_message_reader
|
144
|
+
@stomp_initialized = true
|
145
|
+
set_delimiter "\n"
|
146
|
+
set_line_mode
|
147
|
+
@stomp_message = Message.new
|
148
|
+
end
|
149
|
+
|
150
|
+
# Invoked with an incoming Stomp::Message received from the STOMP server
|
151
|
+
def receive_msg msg
|
152
|
+
# stub, overwrite this in your handler
|
153
|
+
end
|
154
|
+
|
155
|
+
# CONNECT command, for authentication
|
156
|
+
#
|
157
|
+
# connect :login => 'guest', :passcode => 'guest'
|
158
|
+
#
|
159
|
+
def connect parms={}
|
160
|
+
send_frame "CONNECT", parms
|
161
|
+
end
|
162
|
+
|
163
|
+
# SEND command, for publishing messages to a topic
|
164
|
+
#
|
165
|
+
# send '/topic/name', 'some message here'
|
166
|
+
#
|
167
|
+
def send destination, body, parms={}
|
168
|
+
send_frame "SEND", parms.merge( :destination=>destination ), body.to_s
|
169
|
+
end
|
170
|
+
|
171
|
+
# SUBSCRIBE command, for subscribing to topics
|
172
|
+
#
|
173
|
+
# subscribe '/topic/name', false
|
174
|
+
#
|
175
|
+
def subscribe dest, ack=false
|
176
|
+
send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")}
|
177
|
+
end
|
178
|
+
|
179
|
+
# ACK command, for acknowledging receipt of messages
|
180
|
+
#
|
181
|
+
# module StompClient
|
182
|
+
# include EM::P::Stomp
|
183
|
+
#
|
184
|
+
# def connection_completed
|
185
|
+
# connect :login => 'guest', :passcode => 'guest'
|
186
|
+
# # subscribe with ack mode
|
187
|
+
# subscribe '/some/topic', true
|
188
|
+
# end
|
189
|
+
#
|
190
|
+
# def receive_msg msg
|
191
|
+
# if msg.command == "MESSAGE"
|
192
|
+
# ack msg.headers['message-id']
|
193
|
+
# puts msg.body
|
194
|
+
# end
|
195
|
+
# end
|
196
|
+
# end
|
197
|
+
#
|
198
|
+
def ack msgid
|
199
|
+
send_frame "ACK", 'message-id'=> msgid
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
@@ -0,0 +1,54 @@
|
|
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
|
+
module EventMachine
|
28
|
+
module Protocols
|
29
|
+
|
30
|
+
# @private
|
31
|
+
class TcpConnectTester < Connection
|
32
|
+
include EventMachine::Deferrable
|
33
|
+
|
34
|
+
def self.test( host, port )
|
35
|
+
EventMachine.connect( host, port, self )
|
36
|
+
end
|
37
|
+
|
38
|
+
def post_init
|
39
|
+
@start_time = Time.now
|
40
|
+
end
|
41
|
+
|
42
|
+
def connection_completed
|
43
|
+
@completed = true
|
44
|
+
set_deferred_status :succeeded, (Time.now - @start_time)
|
45
|
+
close_connection
|
46
|
+
end
|
47
|
+
|
48
|
+
def unbind
|
49
|
+
set_deferred_status :failed, (Time.now - @start_time) unless @completed
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/em/protocols.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module EventMachine
|
2
|
+
# This module contains various protocol implementations, including:
|
3
|
+
# - HttpClient and HttpClient2
|
4
|
+
# - Stomp
|
5
|
+
# - Memcache
|
6
|
+
# - SmtpClient and SmtpServer
|
7
|
+
# - SASLauth and SASLauthclient
|
8
|
+
# - LineProtocol, LineAndTextProtocol and LineText2
|
9
|
+
# - HeaderAndContentProtocol
|
10
|
+
# - Postgres3
|
11
|
+
# - ObjectProtocol
|
12
|
+
#
|
13
|
+
# The protocol implementations live in separate files in the protocols/ subdirectory,
|
14
|
+
# but are auto-loaded when they are first referenced in your application.
|
15
|
+
#
|
16
|
+
# EventMachine::Protocols is also aliased to EM::P for easier usage.
|
17
|
+
#
|
18
|
+
module Protocols
|
19
|
+
# TODO : various autotools are completely useless with the lack of naming
|
20
|
+
# convention, we need to correct that!
|
21
|
+
autoload :TcpConnectTester, 'em/protocols/tcptest'
|
22
|
+
autoload :HttpClient, 'em/protocols/httpclient'
|
23
|
+
autoload :HttpClient2, 'em/protocols/httpclient2'
|
24
|
+
autoload :LineAndTextProtocol, 'em/protocols/line_and_text'
|
25
|
+
autoload :HeaderAndContentProtocol, 'em/protocols/header_and_content'
|
26
|
+
autoload :LineText2, 'em/protocols/linetext2'
|
27
|
+
autoload :Stomp, 'em/protocols/stomp'
|
28
|
+
autoload :SmtpClient, 'em/protocols/smtpclient'
|
29
|
+
autoload :SmtpServer, 'em/protocols/smtpserver'
|
30
|
+
autoload :SASLauth, 'em/protocols/saslauth'
|
31
|
+
autoload :Memcache, 'em/protocols/memcache'
|
32
|
+
autoload :Postgres3, 'em/protocols/postgres3'
|
33
|
+
autoload :ObjectProtocol, 'em/protocols/object_protocol'
|
34
|
+
autoload :Socks4, 'em/protocols/socks4'
|
35
|
+
autoload :LineProtocol, 'em/protocols/line_protocol'
|
36
|
+
end
|
37
|
+
end
|