Parent

Included Modules

Class/Module Index [+]

Quicksearch

AMQ::Client::Async::CoolioClient

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

Attributes

callbacks[RW]

Hash with available callbacks

socket[RW]

Cool.io socket for multiplexing et al.

@private

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 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
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 273
def self.tcp_connection_failure_exception_class
  AMQ::Client::TCPConnectionFailed
end

Public Instance Methods

close_connection() click to toggle source

Closes the socket.

@api private

# File lib/amq/client/async/adapters/coolio.rb, line 266
def close_connection
  @socket.close
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 180
def connection_successful
  @authenticating = false
  opened!

  exec_callback_yielding_self(:connect)
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 191
def disconnection_successful
  exec_callback_yielding_self(:disconnect)
  close_connection
  closed!
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 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
handle_skipped_hearbeats() click to toggle source
# File lib/amq/client/async/adapters/coolio.rb, line 277
def handle_skipped_hearbeats
  # TODO
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 166
def on_closed(&block)
  define_callback :disconnect, &block
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 158
def on_open(&block)
  define_callback :connect, &block
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 172
def on_tcp_connection_failure(&block)
  define_callback :tcp_connection_failure, &block
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 256
def receive_data(chunk)
  @chunk_buffer << chunk
  while frame = get_next_frame
    receive_frame(AMQ::Client::Framing::String::Frame.decode(frame))
  end
end
register_connection_callback(&block) click to toggle source

Registers on_open callback @see on_open @api private

# File lib/amq/client/async/adapters/coolio.rb, line 132
def register_connection_callback(&block)
  self.on_open(&block)
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 245
def send_raw(data)
  socket.send_raw data
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 202
def socket_connected
  post_init
end
socket_disconnected() click to toggle source

Called after socket is closed

@api private

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

Protected Instance Methods

post_init() click to toggle source

@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
reset() click to toggle source

@api private

# File lib/amq/client/async/adapters/coolio.rb, line 307
def reset
  @chunk_buffer = ""
  @frames       = Array.new
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.