Class: AMQ::Client::Async::CoolioClient

### Home Classes Methods

### In Files

- lib/amq/client/async/adapters/coolio.rb

### Parent

Object

### Namespace

- CLASS AMQ::Client::Async::CoolioClient::Socket

### Methods

- ::new
- ::tcp_connection_failure_exception_class
- #close_connection
- #connection_successful
- #disconnection_successful
- #establish_connection
- #handle_skipped_hearbeats
- #initialize_heartbeat_sender
- #on_closed
- #on_connection
- #on_disconnection
- #on_open
- #on_tcp_connection_failure
- #post_init
- #receive_data
- #register_connection_callback
- #reset
- #send_raw
- #socket_connected
- #socket_disconnected

### Included Modules

- AMQ::Client::Async::Adapter

### Class/Module Index

Quicksearch

- AMQ
- AMQ::Client
- AMQ::Client::Async
- AMQ::Client::Async::Adapter
- AMQ::Client::Async::Adapter::ClassMethods
- AMQ::Client::Async::AuthMechanismAdapter
- AMQ::Client::Async::AuthMechanismAdapter::External
- AMQ::Client::Async::AuthMechanismAdapter::Plain
- AMQ::Client::Async::Callbacks
- AMQ::Client::Async::Channel
- AMQ::Client::Async::Consumer
- AMQ::Client::Async::CoolioClient
- AMQ::Client::Async::CoolioClient::Socket
- AMQ::Client::Async::Entity
- AMQ::Client::Async::EventMachineClient
- AMQ::Client::Async::Exchange
- AMQ::Client::Async::Extensions
- AMQ::Client::Async::Extensions::RabbitMQ
- AMQ::Client::Async::Extensions::RabbitMQ::Basic
- AMQ::Client::Async::Extensions::RabbitMQ::Basic::ChannelMixin
- AMQ::Client::Async::Extensions::RabbitMQ::Basic::ConsumerMixin
- AMQ::Client::Async::Extensions::RabbitMQ::Basic::QueueMixin
- AMQ::Client::Async::Extensions::RabbitMQ::Confirm
- AMQ::Client::Async::Extensions::RabbitMQ::Confirm::ChannelMixin
- AMQ::Client::Async::ProtocolMethodHandlers
- AMQ::Client::Async::Queue
- AMQ::Client::Async::RegisterEntityMixin
- AMQ::Client::BadLengthError
- AMQ::Client::ConnectionClosedError
- AMQ::Client::ConsumerTagGenerator
- AMQ::Client::Framing
- AMQ::Client::Framing::IO
- AMQ::Client::Framing::IO::Frame
- AMQ::Client::Framing::String
- AMQ::Client::Framing::String::Frame
- AMQ::Client::HandlersRegistry
- AMQ::Client::InconsistentDataError
- AMQ::Client::Logging
- AMQ::Client::Logging::IncompatibleLoggerError
- AMQ::Client::MissingHandlerError
- AMQ::Client::NoFinalOctetError
- AMQ::Client::Openable
- AMQ::Client::Openable::ImproperStatusError
- AMQ::Client::PossibleAuthenticationFailureError
- AMQ::Client::ServerNamedEntity
- AMQ::Client::Settings
- AMQ::Client::TCPConnectionFailed
- AMQ::Client::UnknownExchangeTypeError
- AMQ::Protocol
- AMQ::Protocol::GetResponse

No matching classes.

# 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 281
    def handle_skipped_hearbeats
      # TODO
    end

initialize_heartbeat_sender() click to toggle source

    # File lib/amq/client/async/adapters/coolio.rb, line 277
    def initialize_heartbeat_sender
      # 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 289
    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 311
    def reset
      @chunk_buffer = ""
      @frames       = Array.new
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.