Sha256: 04247973b89165eb874e0455ee68ac507bc7daf89c31be06f70c245a87f7f074

Contents?: true

Size: 1.64 KB

Versions: 33

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8

require "amq/client/openable"
require "amq/client/async/callbacks"

module AMQ
  module Client
    module Async
      module RegisterEntityMixin
        # @example Registering Channel implementation
        #  Adapter.register_entity(:channel, Channel)
        #   # ... so then I can do:
        #  channel = client.channel(1)
        #  # instead of:
        #  channel = Channel.new(client, 1)
        def register_entity(name, klass)
          define_method(name) do |*args, &block|
            klass.new(self, *args, &block)
          end # define_method
        end # register_entity
      end # RegisterEntityMixin

      module ProtocolMethodHandlers
        def handle(klass, &block)
          AMQ::Client::HandlersRegistry.register(klass, &block)
        end

        def handlers
          AMQ::Client::HandlersRegistry.handlers
        end
      end # ProtocolMethodHandlers


      # AMQ entities, as implemented by AMQ::Client, have callbacks and can run them
      # when necessary.
      #
      # @note Exchanges and queues implementation is based on this class.
      #
      # @abstract
      module Entity

        #
        # Behaviors
        #

        include Openable
        include Async::Callbacks

        #
        # API
        #

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


        def initialize(connection)
          @connection = connection
          # 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
        end # initialize
      end # Entity
    end # Async
  end # Client
end # AMQ

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
amq-client-1.0.4 lib/amq/client/async/entity.rb
amq-client-1.0.3 lib/amq/client/async/entity.rb
amq-client-1.1.0.pre1 lib/amq/client/async/entity.rb
amq-client-1.0.2 lib/amq/client/async/entity.rb
amq-client-1.0.1 lib/amq/client/async/entity.rb
amq-client-1.0.0 lib/amq/client/async/entity.rb
amq-client-0.9.12 lib/amq/client/async/entity.rb
amq-client-0.9.11 lib/amq/client/async/entity.rb
amq-client-0.9.10 lib/amq/client/async/entity.rb
amq-client-0.9.9 lib/amq/client/async/entity.rb
amq-client-0.9.8 lib/amq/client/async/entity.rb
amq-client-0.9.7 lib/amq/client/async/entity.rb
amq-client-0.9.6 lib/amq/client/async/entity.rb
amq-client-0.9.5 lib/amq/client/async/entity.rb
amq-client-0.9.4 lib/amq/client/async/entity.rb
amq-client-1.0.0.pre2 lib/amq/client/async/entity.rb
amq-client-0.9.3 lib/amq/client/async/entity.rb
amq-client-1.0.0.pre1 lib/amq/client/async/entity.rb
amq-client-0.9.2 lib/amq/client/async/entity.rb
amq-client-0.9.1 lib/amq/client/async/entity.rb