lib/amq/client/adapter.rb in amq-client-0.7.0.alpha31 vs lib/amq/client/adapter.rb in amq-client-0.7.0.alpha32

- old
+ new

@@ -25,25 +25,20 @@ host.extend ProtocolMethodHandlers host.class_eval do # - # Behaviors - # - - include Entity - - - - # # API # attr_accessor :logger attr_accessor :settings - attr_accessor :connection + # @return [Array<#call>] + attr_reader :callbacks + + # The locale defines the language in which the server will send reply texts. # # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.2) attr_accessor :locale @@ -170,12 +165,14 @@ # # Behaviors # - include AMQ::Client::Openable + include Openable + include Callbacks + extend RegisterEntityMixin register_entity :channel, AMQ::Client::Channel @@ -365,10 +362,27 @@ end end # send_heartbeat + + # @group Error handling + + # Defines a callback that will be executed when channel is closed after + # channel-level exception. Only one callback can be added (the one added last + # replaces previous added ones). + # + # @api public + def on_error(&block) + self.redefine_callback(:error, &block) + end + + # @endgroup + + + + # Handles connection.start. # # @api plugin # @see http://bit.ly/htCzCX AMQP 0.9.1 protocol documentation (Section 1.4.2.1.) def handle_start(connection_start) @@ -418,11 +432,10 @@ def handle_close(conn_close) self.handle_connection_interruption closed! # TODO: use proper exception class, provide protocol class (we know conn_close.class_id and conn_close.method_id) as well! - error = RuntimeError.new(conn_close.reply_text) - self.error(error) + self.exec_callback_yielding_self(:error, conn_close) end # Handles Connection.Close-Ok. #