Object
CoolioClient is a drop-in replacement for EventMachineClient, if you prefer cool.io style.
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 141 def initialize # Be careful with default values for #ruby hashes: h = Hash.new(Array.new); h[:key] ||= 1 # won't assign anything to :key. MK. @callbacks = Hash.new self.logger = self.class.logger # channel => collected frames. MK. @frames = Hash.new { Array.new } @channels = Hash.new @mechanism = "PLAIN" end
Closes the socket.
@api private
# File lib/amq/client/async/adapters/coolio.rb, line 266 def close_connection @socket.close end
Called by AMQ::Client::Connection after we receive connection.open-ok.
@api private
# File lib/amq/client/async/adapters/coolio.rb, line 180 def connection_successful @authenticating = false opened! exec_callback_yielding_self(:connect) end
Called by AMQ::Client::Connection after we receive connection.close-ok.
@api private
# File lib/amq/client/async/adapters/coolio.rb, line 191 def disconnection_successful exec_callback_yielding_self(:disconnect) close_connection closed! end
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 106 def establish_connection(settings) @settings = Settings.configure(settings) socket = Socket.connect(self, @settings[:host], @settings[:port]) socket.attach(Cool.io::Loop.default) self.socket = socket @on_tcp_connection_failure = @settings[:on_tcp_connection_failure] || Proc.new { |settings| raise self.class.tcp_connection_failure_exception_class.new(settings) } @on_possible_authentication_failure = @settings[:on_possible_authentication_failure] || Proc.new { |settings| raise self.class.authentication_failure_exception_class.new(settings) } @locale = @settings.fetch(:locale, "en_GB") @client_properties = Settings.client_properties.merge(@settings.fetch(:client_properties, Hash.new)) @auto_recovery = (!!@settings[:auto_recovery]) socket end
# File lib/amq/client/async/adapters/coolio.rb, line 277 def handle_skipped_hearbeats # TODO end
Sets a callback for disconnection (as in client-side disconnection)
@api public
# File lib/amq/client/async/adapters/coolio.rb, line 166 def on_closed(&block) define_callback :disconnect, &block end
Sets a callback for successful connection (after we receive open-ok)
@api public
# File lib/amq/client/async/adapters/coolio.rb, line 158 def on_open(&block) define_callback :connect, &block end
Sets a callback for tcp connection failure (as in can't make initial connection)
# File lib/amq/client/async/adapters/coolio.rb, line 172 def on_tcp_connection_failure(&block) define_callback :tcp_connection_failure, &block end
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 256 def receive_data(chunk) @chunk_buffer << chunk while frame = get_next_frame receive_frame(AMQ::Client::Framing::String::Frame.decode(frame)) end end
Sends raw data through the socket
@param [String] binary data @api private
# File lib/amq/client/async/adapters/coolio.rb, line 245 def send_raw(data) socket.send_raw data end
@api private
# File lib/amq/client/async/adapters/coolio.rb, line 285 def post_init if @had_successfully_connected_before @recovered = true self.exec_callback_yielding_self(:before_recovery, @settings) self.register_connection_callback do self.auto_recover self.exec_callback_yielding_self(:after_recovery, @settings) end end # now we can set it. MK. @had_successfully_connected_before = true @reconnecting = false @handling_skipped_hearbeats = false self.reset self.handshake end
Generated with the Darkfish Rdoc Generator 2.