Module: AMQ::Client::Async::Adapter

### Home Classes Methods

### In Files

- lib/amq/client/async/adapter.rb

### Namespace

- MODULE AMQ::Client::Async::Adapter::ClassMethods

### Methods

- ::included
- #after_connection_interruption
- #after_recovery
- #auth_mechanism_adapter
- #auto_recover
- #auto_recovering?
- #auto_recovery?
- #before_recovery
- #clear_frames_on
- #close_connection
- #content_complete?
- #disconnect
- #encode_credentials
- #establish_connection
- #frameset_complete?
- #get_next_frame
- #handle_close
- #handle_close_ok
- #handle_connection_interruption
- #handle_open_ok
- #handle_start
- #handle_tune
- #handshake
- #heartbeat_interval
- #heartbeats_enabled?
- #negotiate_heartbeat_value
- #on_connection_interruption
- #on_error
- #on_possible_authentication_failure
- #on_recovery
- #on_skipped_heartbeats
- #on_tcp_connection_failure
- #on_tcp_connection_loss
- #open
- #receive_frame
- #receive_frameset
- #reconnecting?
- #reset_state!
- #run_after_recovery_callbacks
- #run_before_recovery_callbacks
- #run_skipped_heartbeats_callbacks
- #send_frame
- #send_frameset
- #send_heartbeat
- #send_preamble
- #send_raw
- #start_automatic_recovery
- #tcp_connection_failed
- #tcp_connection_lost
- #vhost

### Included Modules

- AMQ::Client::Openable
- AMQ::Client::Async::Callbacks

### 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::Adapter

Base adapter class. Specific implementations (for example, EventMachine-based, Cool.io-based or sockets-based) subclass it and must implement Adapter API methods:

- send_raw(data)

- estabilish_connection(settings)

- close_connection

@abstract

### Public Class Methods

included(host) click to toggle source

    # File lib/amq/client/async/adapter.rb, line 23
    def self.included(host)
      host.extend ClassMethods
      host.extend ProtocolMethodHandlers

      host.class_eval do

        #
        # API
        #

        attr_accessor :logger
        attr_accessor :settings

        # @return [Array<#call>]
        attr_reader :callbacks

        # The locale defines the language in which the server will send reply texts.
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.2)
        attr_accessor :locale

        # Client capabilities
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.2.1)
        attr_accessor :client_properties

        # Server properties
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.1.3)
        attr_reader :server_properties

        # Server capabilities
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.1.3)
        attr_reader :server_capabilities

        # Locales server supports
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.1.3)
        attr_reader :server_locales

        # Authentication mechanism used.
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.2)
        attr_reader :mechanism

        # Authentication mechanisms broker supports.
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.2)
        attr_reader :server_authentication_mechanisms

        # Channels within this connection.
        #
        # @see http://bit.ly/amqp091spec AMQP 0.9.1 specification (Section 2.2.5)
        attr_reader :channels

        # Maximum channel number that the server permits this connection to use.
        # Usable channel numbers are in the range 1..channel_max.
        # Zero indicates no specified limit.
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Sections 1.4.2.5.1 and 1.4.2.6.1)
        attr_accessor :channel_max

        # Maximum frame size that the server permits this connection to use.
        #
        # @see http://bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Sections 1.4.2.5.2 and 1.4.2.6.2)
        attr_accessor :frame_max

        attr_reader :known_hosts

        # @api plugin
        # @see #disconnect
        # @note Adapters must implement this method but it is NOT supposed to be used directly.
        #       AMQ protocol defines two-step process of closing connection (send Connection.Close
        #       to the peer and wait for Connection.Close-Ok), implemented by {Adapter#disconnect}
        def close_connection
          raise NotImplementedError
        end unless defined?(:close_connection) # since it is a module, this method may already be defined
      end
    end

### Public Instance Methods

after_connection_interruption(&block) click to toggle source
Alias for: on_connection_interruption
after_recovery(&block) click to toggle source
Alias for: on_recovery
auth_mechanism_adapter() click to toggle source

Retrieves an AuthMechanismAdapter that will encode credentials for this Adapter.

@api plugin

    # File lib/amq/client/async/adapter.rb, line 521
    def auth_mechanism_adapter
      @auth_mechanism_adapter ||= AuthMechanismAdapter.for_adapter(self)
    end

auto_recover() click to toggle source

Performs recovery of channels that are in the automatic recovery mode. Does not run recovery callbacks.

@see Channel#auto_recover @see Queue#auto_recover @see Exchange#auto_recover @api plugin

    # File lib/amq/client/async/adapter.rb, line 428
    def auto_recover
      @channels.select { |channel_id, ch| ch.auto_recovering? }.each { |n, ch| ch.auto_recover }
    end

auto_recovering?() click to toggle source

@return [Boolean] whether connection is in the automatic recovery mode @api public

    # File lib/amq/client/async/adapter.rb, line 415
    def auto_recovering?
      !!@auto_recovery
    end

Also aliased as: auto_recovery?
auto_recovery?() click to toggle source
Alias for: auto_recovering?
before_recovery(&block) click to toggle source

Defines a callback that will be executed after TCP connection has recovered after a network failure but before AMQP connection is re-opened. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amq/client/async/adapter.rb, line 384
    def before_recovery(&block)
      self.redefine_callback(:before_recovery, &block)
    end

clear_frames_on(channel_id) click to toggle source

Clears frames that were received but not processed on given channel. Needs to be called when the channel is closed. @private

    # File lib/amq/client/async/adapter.rb, line 571
    def clear_frames_on(channel_id)
      raise ArgumentError, "channel id cannot be nil!" if channel_id.nil?

      @frames[channel_id].clear
    end

close_connection() click to toggle source

@api plugin @see disconnect @note Adapters must implement this method but it is NOT supposed to be used directly.

    AMQ protocol defines two-step process of closing connection (send Connection.Close
    to the peer and wait for Connection.Close-Ok), implemented by {Adapter#disconnect}

    # File lib/amq/client/async/adapter.rb, line 102
    def close_connection
      raise NotImplementedError
    end

disconnect(reply_code = 200, reply_text = "Goodbye", class_id = 0, method_id = 0, &block) click to toggle source

Properly close connection with AMQ broker, as described in section 2.2.4 of the {bit.ly/amqp091spec AMQP 0.9.1 specification}.

@api plugin @see close_connection

    # File lib/amq/client/async/adapter.rb, line 212
    def disconnect(reply_code = 200, reply_text = "Goodbye", class_id = 0, method_id = 0, &block)
      @intentionally_closing_connection = true
      self.on_disconnection do
        @frames.clear
        block.call if block
      end

      # ruby-amqp/amqp#66, MK.
      if self.open?
        closing!
        self.send_frame(Protocol::Connection::Close.encode(reply_code, reply_text, class_id, method_id))
      elsif self.closing?
        # no-op
      else
        self.disconnection_successful
      end
    end

encode_credentials(username, password) click to toggle source

@api plugin @see tools.ietf.org/rfc/rfc2595.txt RFC 2595

    # File lib/amq/client/async/adapter.rb, line 513
    def encode_credentials(username, password)
      auth_mechanism_adapter.encode_credentials(username, password)
    end

establish_connection(settings) click to toggle source

Establish socket connection to the server.

@api plugin

    # File lib/amq/client/async/adapter.rb, line 203
    def establish_connection(settings)
      raise NotImplementedError
    end

handle_close(conn_close) click to toggle source

Handles connection.close. When broker detects a connection level exception, this method is called.

@api plugin @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.5.2.9)

    # File lib/amq/client/async/adapter.rb, line 650
    def handle_close(conn_close)
      closed!
      self.exec_callback_yielding_self(:error, conn_close)
    end

handle_close_ok(close_ok) click to toggle source

Handles Connection.Close-Ok.

@api plugin @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.10)

    # File lib/amq/client/async/adapter.rb, line 660
    def handle_close_ok(close_ok)
      closed!
      self.disconnection_successful
    end

handle_connection_interruption() click to toggle source

@private @api plugin

    # File lib/amq/client/async/adapter.rb, line 370
    def handle_connection_interruption
      self.cancel_heartbeat_sender

      @channels.each { |n, c| c.handle_connection_interruption }
      self.exec_callback_yielding_self(:after_connection_interruption)
    end

handle_open_ok(open_ok) click to toggle source

Handles Connection.Open-Ok.

@api plugin @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.8.)

    # File lib/amq/client/async/adapter.rb, line 638
    def handle_open_ok(open_ok)
      @known_hosts = open_ok.known_hosts.dup.freeze

      opened!
      self.connection_successful if self.respond_to?(:connection_successful)
    end

handle_start(connection_start) click to toggle source

Handles connection.start.

@api plugin @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.1.)

    # File lib/amq/client/async/adapter.rb, line 598
    def handle_start(connection_start)
      @server_properties                = connection_start.server_properties
      @server_capabilities              = @server_properties["capabilities"]

      @server_authentication_mechanisms = (connection_start.mechanisms || "").split(" ")
      @server_locales                   = Array(connection_start.locales)

      username = @settings[:user] || @settings[:username]
      password = @settings[:pass] || @settings[:password]

      # It's not clear whether we should transition to :opening state here
      # or in #open but in case authentication fails, it would be strange to have
      # @status undefined. So lets do this. MK.
      opening!

      self.send_frame(Protocol::Connection::StartOk.encode(@client_properties, mechanism, self.encode_credentials(username, password), @locale))
    end

handle_tune(connection_tune) click to toggle source

Handles Connection.Tune-Ok.

@api plugin @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.6)

    # File lib/amq/client/async/adapter.rb, line 621
    def handle_tune(connection_tune)
      @channel_max        = connection_tune.channel_max.freeze
      @frame_max          = connection_tune.frame_max.freeze

      client_heartbeat    = @settings[:heartbeat] || @settings[:heartbeat_interval] || 0

      @heartbeat_interval = negotiate_heartbeat_value(client_heartbeat, connection_tune.heartbeat)

      self.send_frame(Protocol::Connection::TuneOk.encode(@channel_max, [settings[:frame_max], @frame_max].min, @heartbeat_interval))
      self.initialize_heartbeat_sender if heartbeats_enabled?
    end

handshake() click to toggle source

Sends connection preamble to the broker. @api plugin

    # File lib/amq/client/async/adapter.rb, line 490
    def handshake
      @authenticating = true
      self.send_preamble
    end

heartbeat_interval() click to toggle source

Returns heartbeat interval this client uses, in seconds. This value may or may not be used depending on broker capabilities. Zero means the server does not want a heartbeat.

@return [Fixnum] Heartbeat interval this client uses, in seconds. @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.6)

    # File lib/amq/client/async/adapter.rb, line 276
    def heartbeat_interval
      @heartbeat_interval
    end

heartbeats_enabled?() click to toggle source

Returns true if heartbeats are enabled (heartbeat interval is greater than 0) @return [Boolean]

    # File lib/amq/client/async/adapter.rb, line 282
    def heartbeats_enabled?
      @heartbeat_interval && (@heartbeat_interval > 0)
    end

on_connection_interruption(&block) click to toggle source

Defines a callback that will be executed after TCP connection is interrupted (typically because of a network failure). Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amq/client/async/adapter.rb, line 362
    def on_connection_interruption(&block)
      self.redefine_callback(:after_connection_interruption, &block)
    end

Also aliased as: after_connection_interruption
on_error(&block) click to toggle source

Defines a callback that will be executed when connection is closed after connection-level exception. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amq/client/async/adapter.rb, line 353
    def on_error(&block)
      self.redefine_callback(:error, &block)
    end

on_possible_authentication_failure(&block) click to toggle source

Defines a callback that will be run when TCP connection is closed before authentication finishes. Usually this means authentication failure. You can define only one callback.

@api public

    # File lib/amq/client/async/adapter.rb, line 343
    def on_possible_authentication_failure(&block)
      @on_possible_authentication_failure = block
    end

on_recovery(&block) click to toggle source

Defines a callback that will be executed after AMQP connection has recovered after a network failure.. Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amq/client/async/adapter.rb, line 400
    def on_recovery(&block)
      self.redefine_callback(:after_recovery, &block)
    end

Also aliased as: after_recovery
on_skipped_heartbeats(&block) click to toggle source

Defines a callback that will be executed after time since last broker heartbeat is greater than or equal to the heartbeat interval (skipped heartbeat is detected). Only one callback can be defined (the one defined last replaces previously added ones).

@api public

    # File lib/amq/client/async/adapter.rb, line 461
    def on_skipped_heartbeats(&block)
      self.redefine_callback(:skipped_heartbeats, &block)
    end

on_tcp_connection_failure(&block) click to toggle source

Defines a callback that will be run when initial TCP connection fails. You can define only one callback.

@api public

    # File lib/amq/client/async/adapter.rb, line 327
    def on_tcp_connection_failure(&block)
      @on_tcp_connection_failure = block
    end

on_tcp_connection_loss(&block) click to toggle source

Defines a callback that will be run when TCP connection to AMQP broker is lost (interrupted). You can define only one callback.

@api public

    # File lib/amq/client/async/adapter.rb, line 335
    def on_tcp_connection_loss(&block)
      @on_tcp_connection_loss = block
    end

open(vhost = "/") click to toggle source

Sends connection.open to the server.

@api plugin @see bit.ly/amqp091reference AMQP 0.9.1 protocol reference (Section 1.4.2.7)

    # File lib/amq/client/async/adapter.rb, line 500
    def open(vhost = "/")
      self.send_frame(Protocol::Connection::Open.encode(vhost))
    end

receive_frame(frame) click to toggle source

Processes a single frame.

@param [AMQ::Protocol::Frame] frame @api plugin

    # File lib/amq/client/async/adapter.rb, line 530
    def receive_frame(frame)
      @frames[frame.channel] ||= Array.new
      @frames[frame.channel] << frame

      if frameset_complete?(@frames[frame.channel])
        receive_frameset(@frames[frame.channel])
        # for channel.close, frame.channel will be nil. MK.
        clear_frames_on(frame.channel) if @frames[frame.channel]
      end
    end

receive_frameset(frames) click to toggle source

Processes a frameset by finding and invoking a suitable handler. Heartbeat frames are treated in a special way: they simply update @last_server_heartbeat value.

@param [Array<AMQ::Protocol::Frame>] frames @api plugin

    # File lib/amq/client/async/adapter.rb, line 547
    def receive_frameset(frames)
      if self.heartbeats_enabled?
        # treat incoming traffic as heartbeats.
        # this operation is pretty expensive under heavy traffic but heartbeats can be disabled
        # (and are also disabled by default). MK.
        @last_server_heartbeat = Time.now
      end
      frame = frames.first

      if AMQ::Protocol::HeartbeatFrame === frame
        # no-op
      else
        if callable = AMQ::Client::HandlersRegistry.find(frame.method_class)
          f = frames.shift
          callable.call(self, f, frames)
        else
          raise MissingHandlerError.new(frames.first)
        end
      end
    end

reconnecting?() click to toggle source

@return [Boolean]

    # File lib/amq/client/async/adapter.rb, line 318
    def reconnecting?
      @reconnecting
    end

reset_state!() click to toggle source

Resets connection state.

@api plugin

    # File lib/amq/client/async/adapter.rb, line 507
    def reset_state!
      # no-op by default
    end

run_after_recovery_callbacks() click to toggle source

@private

    # File lib/amq/client/async/adapter.rb, line 406
    def run_after_recovery_callbacks
      self.exec_callback_yielding_self(:after_recovery, @settings)

      @channels.each { |n, ch| ch.run_after_recovery_callbacks }
    end

run_before_recovery_callbacks() click to toggle source

@private

    # File lib/amq/client/async/adapter.rb, line 389
    def run_before_recovery_callbacks
      self.exec_callback_yielding_self(:before_recovery, @settings)

      @channels.each { |n, ch| ch.run_before_recovery_callbacks }
    end

run_skipped_heartbeats_callbacks() click to toggle source

@private

    # File lib/amq/client/async/adapter.rb, line 466
    def run_skipped_heartbeats_callbacks
      self.exec_callback_yielding_self(:skipped_heartbeats, @settings)
    end

send_frame(frame) click to toggle source

Sends frame to the peer, checking that connection is open.

@raise [ConnectionClosedError]

    # File lib/amq/client/async/adapter.rb, line 245
    def send_frame(frame)
      if closed?
        raise ConnectionClosedError.new(frame)
      else
        self.send_raw(frame.encode)
      end
    end

send_frameset(frames, channel) click to toggle source

Sends multiple frames, one by one. For thread safety this method takes a channel object and synchronizes on it.

@api public

    # File lib/amq/client/async/adapter.rb, line 257
    def send_frameset(frames, channel)
      # some (many) developers end up sharing channels between threads and when multiple
      # threads publish on the same channel aggressively, at some point frames will be
      # delivered out of order and broker will raise 505 UNEXPECTED_FRAME exception.
      # If we synchronize on the channel, however, this is both thread safe and pretty fine-grained
      # locking. Note that "single frame" methods do not need this kind of synchronization. MK.
      channel.synchronize do
        frames.each { |frame| self.send_frame(frame) }
      end
    end

send_heartbeat() click to toggle source

Sends a heartbeat frame if connection is open. @api plugin

    # File lib/amq/client/async/adapter.rb, line 579
    def send_heartbeat
      if tcp_connection_established? && !@handling_skipped_hearbeats && @last_server_heartbeat
        if @last_server_heartbeat < (Time.now - (self.heartbeat_interval * 2)) && !reconnecting?
          logger.error "[amqp] Detected missing server heartbeats"
          self.handle_skipped_hearbeats
        end
        send_frame(Protocol::HeartbeatFrame)
      end
    end

send_preamble() click to toggle source

Sends AMQ protocol header (also known as preamble).

@note This must be implemented by all AMQP clients. @api plugin @see bit.ly/amqp091spec AMQP 0.9.1 specification (Section 2.2)

    # File lib/amq/client/async/adapter.rb, line 238
    def send_preamble
      self.send_raw(AMQ::Protocol::PREAMBLE)
    end

send_raw(data) click to toggle source

Sends opaque data to AMQ broker over active connection.

@note This must be implemented by all AMQP clients. @api plugin

    # File lib/amq/client/async/adapter.rb, line 484
    def send_raw(data)
      raise NotImplementedError
    end

start_automatic_recovery() click to toggle source

Performs recovery of channels that are in the automatic recovery mode. "before recovery" callbacks are run immediately, "after recovery" callbacks are run after AMQP connection is re-established and auto recovery is performed (using auto_recover).

Use this method if you want to run automatic recovery process after handling a connection-level exception, for example, 320 CONNECTION_FORCED (used by RabbitMQ when it is shut down gracefully).

@see Channel#auto_recover @see Queue#auto_recover @see Exchange#auto_recover @api plugin

    # File lib/amq/client/async/adapter.rb, line 444
    def start_automatic_recovery
      self.run_before_recovery_callbacks
      self.register_connection_callback do
        # always run automatic recovery, because it is per-channel
        # and connection has to start it. Channels that did not opt-in for
        # autorecovery won't be selected. MK.
        self.auto_recover
        self.run_after_recovery_callbacks
      end
    end

tcp_connection_failed() click to toggle source

Called when initial TCP connection fails. @api public

    # File lib/amq/client/async/adapter.rb, line 302
    def tcp_connection_failed
      @recovered = false

      @on_tcp_connection_failure.call(@settings) if @on_tcp_connection_failure
    end

tcp_connection_lost() click to toggle source

Called when previously established TCP connection fails. @api public

    # File lib/amq/client/async/adapter.rb, line 310
    def tcp_connection_lost
      @recovered = false

      @on_tcp_connection_loss.call(self, @settings) if @on_tcp_connection_loss
      self.handle_connection_interruption
    end

vhost() click to toggle source

vhost this connection uses. Default is "/", a historically estabilished convention of RabbitMQ and amqp gem.

@return [String] vhost this connection uses @api public

    # File lib/amq/client/async/adapter.rb, line 292
    def vhost
      @settings.fetch(:vhost, "/")
    end

### Protected Instance Methods

content_complete?(frames) click to toggle source

Determines, whether given frame array contains full content body

    # File lib/amq/client/async/adapter.rb, line 705
    def content_complete?(frames)
      return false if frames.empty?
      header = frames[0]
      raise "Not a content header frame first: #{header.inspect}" unless header.kind_of?(AMQ::Protocol::HeaderFrame)
      header.body_size == frames[1..-1].inject(0) {|sum, frame| sum + frame.payload.size }
    end

frameset_complete?(frames) click to toggle source

Determines, whether the received frameset is ready to be further processed

    # File lib/amq/client/async/adapter.rb, line 698
    def frameset_complete?(frames)
      return false if frames.empty?
      first_frame = frames[0]
      first_frame.final? || (first_frame.method_class.has_content? && content_complete?(frames[1..-1]))
    end

get_next_frame() click to toggle source

Returns next frame from buffer whenever possible

@api private

    # File lib/amq/client/async/adapter.rb, line 680
    def get_next_frame
      return nil unless @chunk_buffer.size > 7 # otherwise, cannot read the length
      # octet + short
      offset = 3 # 1 + 2
      # length
      payload_length = @chunk_buffer[offset, 4].unpack(AMQ::Protocol::PACK_UINT32).first
      # 4 bytes for long payload length, 1 byte final octet
      frame_length = offset + payload_length + 5
      if frame_length <= @chunk_buffer.size
        @chunk_buffer.slice!(0, frame_length)
      else
        nil
      end
    end

negotiate_heartbeat_value(client_value, server_value) click to toggle source

    # File lib/amq/client/async/adapter.rb, line 669
    def negotiate_heartbeat_value(client_value, server_value)
      if client_value == 0 || server_value == 0
        [client_value, server_value].max
      else
        [client_value, server_value].min
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.