Sha256: 09aa200cb8fc3565fca2956db402cd815d6b82edb5b3686803d9aa98dfb84242

Contents?: true

Size: 1.61 KB

Versions: 11

Compression:

Stored size: 1.61 KB

Contents

module ASIR
  class Transport
    # !SLIDE
    # A Transport that delgated to one or more other Transports.
    #
    # Classes that include this must define #_send_message(message, message_payload).
    module Delegation
      # If true, reraise the first Exception that occurred during Transport#send_message.
      attr_accessor :reraise_first_exception

      # Proc to call(transport, message, exc) when a delegated #send_message fails.
      attr_accessor :on_send_message_exception

      # Proc to call(transport, message) when #send_message fails with no recourse.
      attr_accessor :on_failed_message

      # Return the subTransports' result unmodified from #_send_message.
      def _receive_result state
        true
      end

      def needs_message_identifier? message
        @needs_message_identifier ||
          transports.any? { | t | t.needs_message_identifier?(message) }
      end

      def needs_message_timestamp? message
        @needs_message_timestamp ||
          transports.any? { | t | t.needs_message_timestamp?(message) }
      end

      # Subclasses with multiple transports should override this method.
      def transports
        @transports ||= [ transport ]
      end

      # Called from within _send_message rescue.
      def _handle_send_message_exception! transport, state, exc
        _log { [ :send_message, :transport_failed, exc, exc.backtrace ] }
        (state.message[:transport_exceptions] ||= [ ]) << "#{exc.inspect}: #{exc.backtrace.first}"
        @on_send_message_exception.call(self, state, exc) if @on_send_message_exception
        self
      end
    end
    # !SLIDE END
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
asir-1.2.11 lib/asir/transport/delegation.rb
asir-1.2.10 lib/asir/transport/delegation.rb
asir-1.2.9 lib/asir/transport/delegation.rb
asir-1.2.8 lib/asir/transport/delegation.rb
asir-1.2.7 lib/asir/transport/delegation.rb
asir-1.2.6 lib/asir/transport/delegation.rb
asir-1.2.5 lib/asir/transport/delegation.rb
asir-1.2.3 lib/asir/transport/delegation.rb
asir-1.2.2 lib/asir/transport/delegation.rb
asir-1.2.1 lib/asir/transport/delegation.rb
asir-1.2.0 lib/asir/transport/delegation.rb