Parent

Included Modules

Class Index [+]

Quicksearch

AMQ::Client::Async::CoolioClient

CoolioClient is a drop-in replacement for EventMachineClient, if you prefer cool.io style.

Attributes

socket[RW]

Cool.io socket for multiplexing et al.

@private

callbacks[RW]

Hash with available callbacks

Public Class Methods

new() click to toggle source

Performs basic initialization. Do not use this method directly, use CoolioClient.connect instead

@see AMQ::Client::Adapter::ClassMethods#connect @api private

     # File lib/amq/client/async/adapters/coolio.rb, line 142
142:         def initialize
143:           # Be careful with default values for #ruby hashes: h = Hash.new(Array.new); h[:key] ||= 1
144:           # won't assign anything to :key. MK.
145:           @callbacks    = Hash.new
146: 
147:           self.logger   = self.class.logger
148: 
149:           # channel => collected frames. MK.
150:           @frames            = Hash.new { Array.new }
151:           @channels          = Hash.new
152: 
153:           @mechanism         = "PLAIN"
154:         end
tcp_connection_failure_exception_class() click to toggle source

Returns class used for tcp connection failures.

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 274
274:         def self.tcp_connection_failure_exception_class
275:           AMQ::Client::TCPConnectionFailed
276:         end

Public Instance Methods

close_connection() click to toggle source

Closes the socket.

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 267
267:         def close_connection
268:           @socket.close
269:         end
connection_successful() click to toggle source

Called by AMQ::Client::Connection after we receive connection.open-ok.

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 181
181:         def connection_successful
182:           @authenticating = false
183:           opened!
184: 
185:           exec_callback_yielding_self(:connect)
186:         end
disconnection_successful() click to toggle source

Called by AMQ::Client::Connection after we receive connection.close-ok.

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 192
192:         def disconnection_successful
193:           exec_callback_yielding_self(:disconnect)
194:           close_connection
195:           closed!
196:         end
establish_connection(settings) click to toggle source

Creates a socket and attaches it to cool.io default loop.

Called from CoolioClient.connect

@see AMQ::Client::Adapter::ClassMethods#connect @param [Hash] connection settings @api private

     # File lib/amq/client/async/adapters/coolio.rb, line 107
107:         def establish_connection(settings)
108:           @settings     = Settings.configure(settings)
109: 
110:           socket = Socket.connect(self, @settings[:host], @settings[:port])
111:           socket.attach(Cool.io::Loop.default)
112:           self.socket = socket
113: 
114: 
115:           @on_tcp_connection_failure          = @settings[:on_tcp_connection_failure] || Proc.new { |settings|
116:             raise self.class.tcp_connection_failure_exception_class.new(settings)
117:           }
118:           @on_possible_authentication_failure = @settings[:on_possible_authentication_failure] || Proc.new { |settings|
119:             raise self.class.authentication_failure_exception_class.new(settings)
120:           }
121: 
122:           @locale            = @settings.fetch(:locale, "en_GB")
123:           @client_properties = Settings.client_properties.merge(@settings.fetch(:client_properties, Hash.new))
124: 
125:           @auto_recovery     = (!!@settings[:auto_recovery])
126: 
127:           socket
128:         end
handle_skipped_hearbeats() click to toggle source
     # File lib/amq/client/async/adapters/coolio.rb, line 278
278:         def handle_skipped_hearbeats
279:           # TODO
280:         end
on_closed(&block) click to toggle source

Sets a callback for disconnection (as in client-side disconnection)

@api public

     # File lib/amq/client/async/adapters/coolio.rb, line 167
167:         def on_closed(&block)
168:           define_callback :disconnect, &block
169:         end
Also aliased as: on_disconnection
on_connection(&block) click to toggle source
Alias for: on_open
on_disconnection(&block) click to toggle source
Alias for: on_closed
on_open(&block) click to toggle source

Sets a callback for successful connection (after we receive open-ok)

@api public

     # File lib/amq/client/async/adapters/coolio.rb, line 159
159:         def on_open(&block)
160:           define_callback :connect, &block
161:         end
Also aliased as: on_connection
on_tcp_connection_failure(&block) click to toggle source

Sets a callback for tcp connection failure (as in can’t make initial connection)

     # File lib/amq/client/async/adapters/coolio.rb, line 173
173:         def on_tcp_connection_failure(&block)
174:           define_callback :tcp_connection_failure, &block
175:         end
receive_data(chunk) click to toggle source

The story about the buffering is kinda similar to EventMachine, you keep receiving more than one frame in a single packet.

@param [String] chunk with binary data received. It could be one frame,

  more than one frame or less than one frame.

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 257
257:         def receive_data(chunk)
258:           @chunk_buffer << chunk
259:           while frame = get_next_frame
260:             receive_frame(AMQ::Client::Framing::String::Frame.decode(frame))
261:           end
262:         end
register_connection_callback(&block) click to toggle source

Registers on_open callback @see # @api private

     # File lib/amq/client/async/adapters/coolio.rb, line 133
133:         def register_connection_callback(&block)
134:           self.on_open(&block)
135:         end
send_raw(data) click to toggle source

Sends raw data through the socket

@param [String] binary data @api private

     # File lib/amq/client/async/adapters/coolio.rb, line 246
246:         def send_raw(data)
247:           socket.send_raw data
248:         end
socket_connected() click to toggle source

Called when socket is connected but before handshake is done

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 203
203:         def socket_connected
204:           post_init
205:         end
socket_disconnected() click to toggle source

Called after socket is closed

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 210
210:         def socket_disconnected
211:         end

Protected Instance Methods

post_init() click to toggle source

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 286
286:         def post_init
287:           if @had_successfully_connected_before
288:             @recovered = true
289: 
290:             self.exec_callback_yielding_self(:before_recovery, @settings)
291: 
292:             self.register_connection_callback do
293:               self.auto_recover
294:               self.exec_callback_yielding_self(:after_recovery, @settings)
295:             end
296:           end
297: 
298:           # now we can set it. MK.
299:           @had_successfully_connected_before = true
300:           @reconnecting                      = false
301:           @handling_skipped_hearbeats        = false
302: 
303:           self.reset
304:           self.handshake
305:         end
reset() click to toggle source

@api private

     # File lib/amq/client/async/adapters/coolio.rb, line 308
308:         def reset
309:           @chunk_buffer = ""
310:           @frames       = Array.new
311:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.