Sha256: de16bb1034d2d6a3315dbb924ec41578f9e8682a4643b16a81df282052e84206

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

module MessageDriver
  module Adapters
    class Base
      include Logging

      attr_accessor :contexts

      def initialize(configuration)
        raise "Must be implemented in subclass"
      end

      def new_context
        @contexts ||= []
        ctx = build_context
        contexts << ctx
        ctx
      end

      def build_context
        raise "Must be implemented in subclass"
      end

      def stop
        contexts.each { |ctx| ctx.invalidate } if contexts
      end
    end

    class ContextBase
      include Logging

      attr_reader :adapter
      attr_accessor :valid

      def initialize(adapter)
        @adapter = adapter
        @valid = true
      end

      def publish(destination, body, headers={}, properties={})
        raise "Must be implemented in subclass"
      end

      def pop_message(destination, options={})
        raise "Must be implemented in subclass"
      end

      def subscribe(destination, options={}, &consumer)
        raise "#subscribe is not supported by #{adapter.class}"
      end

      def create_destination(name, dest_options={}, message_props={})
        raise "Must be implemented in subclass"
      end

      def valid?
        @valid
      end

      def invalidate
        @valid = false
      end

      def supports_transactions?
        false
      end

      def supports_client_acks?
        false
      end

      def supports_subscriptions?
        false
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
message-driver-0.2.1 lib/message_driver/adapters/base.rb
message-driver-0.2.0 lib/message_driver/adapters/base.rb
message-driver-0.2.0.rc2 lib/message_driver/adapters/base.rb
message-driver-0.2.0.rc1 lib/message_driver/adapters/base.rb