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 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
Closes the socket.
@api private
# File lib/amq/client/async/adapters/coolio.rb, line 267 267: def close_connection 268: @socket.close 269: end
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
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
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
# File lib/amq/client/async/adapters/coolio.rb, line 278 278: def handle_skipped_hearbeats 279: # TODO 280: end
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
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
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
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
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
@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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.